Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

feat(GraphQLTemplate) option to externalize fetching, Relates #70 #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nodes/src/main/java/io/aexp/nodes/graphql/Fetch.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.List;
import java.util.Map;

final class Fetch {
final class Fetch implements Fetcher {

private final ObjectMapperFactory objectMapperFactory;
private ObjectMapper mapper;
Expand All @@ -41,7 +41,7 @@ final class Fetch {
this.objectMapperFactory = objectMapperFactory;
}

<T> GraphQLResponseEntity<T> send(GraphQLRequestEntity requestEntity, Class<T> responseClass) throws GraphQLException {
public <T> GraphQLResponseEntity<T> send(GraphQLRequestEntity requestEntity, Class<T> responseClass) throws GraphQLException {
mapper = objectMapperFactory.newSerializerMapper();
module = new SimpleModule();

Expand Down
20 changes: 20 additions & 0 deletions nodes/src/main/java/io/aexp/nodes/graphql/Fetcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2018 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.aexp.nodes.graphql;

import io.aexp.nodes.graphql.exceptions.GraphQLException;

public interface Fetcher {
<T> GraphQLResponseEntity<T> send(GraphQLRequestEntity requestEntity, Class<T> responseClass) throws GraphQLException;
}
12 changes: 10 additions & 2 deletions nodes/src/main/java/io/aexp/nodes/graphql/GraphQLTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class GraphQLTemplate {

private Fetch fetch;
private Fetcher fetch;

public enum GraphQLMethod {
QUERY("query"),
Expand All @@ -45,7 +45,15 @@ public GraphQLTemplate() {
* @param objectMapperFactory factory class used for creating ObjectMapper instances
*/
public GraphQLTemplate(final ObjectMapperFactory objectMapperFactory) {
fetch = new Fetch(objectMapperFactory);
this(new Fetch(objectMapperFactory));
}

/**
* Constructs a new GraphQL template instance using the specified ObjectMapper factory.
* @param fetcher custom fetch provider
*/
public GraphQLTemplate(final Fetcher fetcher) {
fetch = fetcher;
}

/**
Expand Down