From 9bc0d442e67248d0899429ae8548340c055ee50f Mon Sep 17 00:00:00 2001 From: fupduck Date: Fri, 2 Aug 2019 19:39:33 +0200 Subject: [PATCH] feat(GraphQLTemplate) option to externalize fetching (#85) --- .../java/io/aexp/nodes/graphql/Fetch.java | 4 ++-- .../java/io/aexp/nodes/graphql/Fetcher.java | 20 +++++++++++++++++++ .../aexp/nodes/graphql/GraphQLTemplate.java | 12 +++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 nodes/src/main/java/io/aexp/nodes/graphql/Fetcher.java diff --git a/nodes/src/main/java/io/aexp/nodes/graphql/Fetch.java b/nodes/src/main/java/io/aexp/nodes/graphql/Fetch.java index b511085..a7a0e63 100644 --- a/nodes/src/main/java/io/aexp/nodes/graphql/Fetch.java +++ b/nodes/src/main/java/io/aexp/nodes/graphql/Fetch.java @@ -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; @@ -50,7 +50,7 @@ final class Fetch { } - GraphQLResponseEntity send(GraphQLRequestEntity requestEntity, Class responseClass) throws GraphQLException { + public GraphQLResponseEntity send(GraphQLRequestEntity requestEntity, Class responseClass) throws GraphQLException { mapper = objectMapperFactory.newSerializerMapper(); module = new SimpleModule(); diff --git a/nodes/src/main/java/io/aexp/nodes/graphql/Fetcher.java b/nodes/src/main/java/io/aexp/nodes/graphql/Fetcher.java new file mode 100644 index 0000000..c6af248 --- /dev/null +++ b/nodes/src/main/java/io/aexp/nodes/graphql/Fetcher.java @@ -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 { + GraphQLResponseEntity send(GraphQLRequestEntity requestEntity, Class responseClass) throws GraphQLException; +} diff --git a/nodes/src/main/java/io/aexp/nodes/graphql/GraphQLTemplate.java b/nodes/src/main/java/io/aexp/nodes/graphql/GraphQLTemplate.java index 6938c11..dce4b40 100644 --- a/nodes/src/main/java/io/aexp/nodes/graphql/GraphQLTemplate.java +++ b/nodes/src/main/java/io/aexp/nodes/graphql/GraphQLTemplate.java @@ -18,7 +18,7 @@ public class GraphQLTemplate { - private Fetch fetch; + private Fetcher fetch; public enum GraphQLMethod { QUERY("query"), @@ -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; } /**