Skip to content

Commit

Permalink
feat(GraphQLTemplate) option to externalize fetching (americanexpress#85
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fupduck authored and chemdrew committed Aug 2, 2019
1 parent 3091930 commit 9bc0d44
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
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 @@ -50,7 +50,7 @@ final class Fetch {

}

<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

0 comments on commit 9bc0d44

Please sign in to comment.