From f1f2cf859a1584e504f9a45bdc11724860ee3ab8 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Tue, 20 Jul 2021 10:45:03 +0800 Subject: [PATCH 1/8] Enable ExecutionInput as part of @GraphQLApi @Query methods --- .../graphql/server/ExecutionContext.java | 16 ++++ .../graphql/server/ExecutionContextImpl.java | 13 +++ .../graphql/server/InvocationHandlerImpl.java | 2 + .../graphql/server/DataFetcherUtils.java | 51 ++++++---- .../graphql/server/SchemaArgument.java | 34 ++++++- .../graphql/server/SchemaFieldDefinition.java | 7 +- .../graphql/server/SchemaGenerator.java | 8 +- .../graphql/server/SchemaArgumentTest.java | 11 +++ .../ExecutionInputQueriesAndMutations.java | 51 ++++++++++ .../graphql/server/ExecutionInputIT.java | 95 +++++++++++++++++++ 10 files changed, 262 insertions(+), 26 deletions(-) create mode 100644 microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/ExecutionInputQueriesAndMutations.java create mode 100644 tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java index 45b986e6f69..0d5c9d798d0 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java @@ -16,6 +16,8 @@ package io.helidon.graphql.server; +import graphql.ExecutionInput; + /** * GraphQL execution context to support partial results. */ @@ -40,4 +42,18 @@ public interface ExecutionContext { * @return true if there was a partial results exception */ boolean hasPartialResultsException(); + + /** + * Add the {@link ExecutionInput}. + * + * @param input {@link ExecutionInput} + */ + void setExecutionInput(ExecutionInput input); + + /** + * Retrieve the {@link ExecutionInput}. + * + * @return the {@link ExecutionInput} + */ + ExecutionInput executionInput(); } diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java index cab5f933274..3f3c9844134 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java @@ -18,8 +18,11 @@ import java.util.concurrent.atomic.AtomicReference; +import graphql.ExecutionInput; + class ExecutionContextImpl implements ExecutionContext { private final AtomicReference currentThrowable = new AtomicReference<>(); + private final AtomicReference currentExecutionInput = new AtomicReference<>(); ExecutionContextImpl() { } @@ -38,4 +41,14 @@ public Throwable partialResultsException() { public boolean hasPartialResultsException() { return currentThrowable.get() != null; } + + @Override + public void setExecutionInput(ExecutionInput input) { + currentExecutionInput.set(input); + } + + @Override + public ExecutionInput executionInput() { + return currentExecutionInput.get(); + } } diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java b/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java index 5674d38d56e..d9e2fafdc9f 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java @@ -92,6 +92,8 @@ private Map doExecute(String query, String operationName, Map errors = result.getErrors(); diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/DataFetcherUtils.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/DataFetcherUtils.java index ee14d1e4ffb..290e6c1b5a9 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/DataFetcherUtils.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/DataFetcherUtils.java @@ -20,6 +20,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.math.BigDecimal; import java.math.BigInteger; import java.text.NumberFormat; @@ -46,6 +47,7 @@ import io.helidon.graphql.server.ExecutionContext; +import graphql.ExecutionInput; import graphql.GraphQLException; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; @@ -120,28 +122,39 @@ static DataFetcher newMethodDataFetcher(Schema schema, Class clazz, Me } } - if (args.length > 0) { + ExecutionContext executionContext; + // check for a single ExecutionInput parameter as args will be zero + Parameter[] parameters = method.getParameters(); + if (parameters.length == 1 && parameters[0].getType().equals(ExecutionInput.class)) { + executionContext = environment.getContext(); + listArgumentValues.add(executionContext.executionInput()); + } else if (args.length > 0) { for (SchemaArgument argument : args) { - // ensure a Map is not used as an input type - Class originalType = argument.originalType(); - if (originalType != null && Map.class.isAssignableFrom(originalType)) { - ensureRuntimeException(LOGGER, MAP_MESSAGE); - } + if (argument.isExecutionInput()) { + executionContext = environment.getContext(); + listArgumentValues.add(executionContext.executionInput()); + } else { + // ensure a Map is not used as an input type + Class originalType = argument.originalType(); + if (originalType != null && Map.class.isAssignableFrom(originalType)) { + ensureRuntimeException(LOGGER, MAP_MESSAGE); + } - if (argument.isArrayReturnType() && argument.arrayLevels() > 1 - && SchemaGeneratorHelper.isPrimitiveArray(argument.originalType())) { - throw new GraphQlConfigurationException("This implementation does not currently support " - + "multi-level primitive arrays as arguments. Please use " - + "List or Collection of Object equivalent. E.g. " - + "In place of method(int [][] value) use " - + " method(List> value)"); - } + if (argument.isArrayReturnType() && argument.arrayLevels() > 1 + && SchemaGeneratorHelper.isPrimitiveArray(argument.originalType())) { + throw new GraphQlConfigurationException("This implementation does not currently support " + + "multi-level primitive arrays as arguments. Please use " + + "List or Collection of Object equivalent. E.g. " + + "In place of method(int [][] value) use " + + " method(List> value)"); + } - listArgumentValues.add(generateArgumentValue(schema, argument.argumentType(), - argument.originalType(), - argument.originalArrayType(), - environment.getArgument(argument.argumentName()), - argument.format())); + listArgumentValues.add(generateArgumentValue(schema, argument.argumentType(), + argument.originalType(), + argument.originalArrayType(), + environment.getArgument(argument.argumentName()), + argument.format())); + } } } diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java index 0f7cb1eafb1..611b4f4e8e5 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java @@ -78,6 +78,11 @@ class SchemaArgument extends AbstractDescriptiveElement implements ElementGenera */ private Class originalArrayType; + /** + * Indicates if the argument type is the {@link graphql.ExecutionInput} and must be ignored in schema generation. + */ + private boolean isExecutionInput; + /** * Construct a {@link SchemaArgument}. * @@ -95,6 +100,7 @@ private SchemaArgument(Builder builder) { this.arrayLevels = builder.arrayLevels; this.isArrayReturnTypeMandatory = builder.isArrayReturnTypeMandatory; this.originalArrayType = builder.originalArrayType; + this.isExecutionInput = builder.isExecutionInput; description(builder.description); } @@ -299,6 +305,15 @@ public void arrayReturnTypeMandatory(boolean arrayReturnTypeMandatory) { isArrayReturnTypeMandatory = arrayReturnTypeMandatory; } + /** + * Indicates if the argument type is the {@link graphql.ExecutionInput} and must be ignored in schema generation. + * + * @return true if the argument type is the {@link graphql.ExecutionInput} + */ + public boolean isExecutionInput() { + return isExecutionInput; + } + /** * Sets the original array type. * @@ -329,6 +344,7 @@ public String toString() { + ", isReturnTypeMandatory=" + isArrayReturnTypeMandatory + ", isArrayReturnType=" + isArrayReturnType + ", originalArrayType=" + originalArrayType + + ", isExecutionInput=" + isExecutionInput + ", arrayLevels=" + arrayLevels + ", format=" + Arrays.toString(format) + ", description='" + description() + '\'' + '}'; @@ -353,13 +369,14 @@ public boolean equals(Object o) { && Arrays.equals(format, schemaArgument.format) && Objects.equals(sourceArgument, schemaArgument.sourceArgument) && Objects.equals(originalArrayType, schemaArgument.originalArrayType) + && Objects.equals(isExecutionInput, schemaArgument.isExecutionInput) && Objects.equals(description(), schemaArgument.description()) && Objects.equals(defaultValue, schemaArgument.defaultValue); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), argumentName, argumentType, sourceArgument, + return Objects.hash(super.hashCode(), argumentName, argumentType, sourceArgument, isExecutionInput, isMandatory, defaultValue, description(), originalType, format, originalArrayType); } @@ -380,6 +397,7 @@ public static class Builder implements io.helidon.common.Builder private int arrayLevels; private boolean isArrayReturnTypeMandatory; private Class originalArrayType; + private boolean isExecutionInput; /** * Set the argument name. @@ -506,7 +524,8 @@ public Builder arrayReturnTypeMandatory(boolean isArrayReturnTypeMandatory) { /** * Set the original array inner type if it is array type. - * @param originalArrayType the original array inner type if it is array type + * + * @param originalArrayType the original array inner type if it is array type * @return updated builder instance */ public Builder originalArrayType(Class originalArrayType) { @@ -514,6 +533,17 @@ public Builder originalArrayType(Class originalArrayType) { return this; } + /** + * Set if the argument type is the {@link graphql.ExecutionInput} and must be ignored in schema generation. + * + * @param isExecutionInput if the argument type is the {@link graphql.ExecutionInput} + * @return updated builder instance + */ + public Builder executionInput(boolean isExecutionInput) { + this.isExecutionInput = isExecutionInput; + return this; + } + /** * Build the instance from this builder. * diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java index 099c3208ad7..6d038c715ea 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java @@ -142,10 +142,15 @@ public String getSchemaAsString() { StringBuilder sb = new StringBuilder(getSchemaElementDescription(format())) .append(name()); - if (listSchemaArguments.size() > 0) { + // determine if there are any arguments that are not ExecutionInput as they should + // not be included as standard types + boolean hasSchemaArguments = listSchemaArguments.stream().anyMatch(a -> !a.isExecutionInput()); + + if (hasSchemaArguments) { sb.append(OPEN_PARENTHESES) .append(NEWLINE) .append(listSchemaArguments.stream() + .filter(a -> !a.isExecutionInput()) .map(SchemaArgument::getSchemaAsString) .collect(Collectors.joining(COMMA_SPACE + NEWLINE))); sb.append(NEWLINE).append(CLOSE_PARENTHESES); diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaGenerator.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaGenerator.java index 015696256df..b1a5409d01d 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaGenerator.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaGenerator.java @@ -44,6 +44,7 @@ import io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.DiscoveredMethod; +import graphql.ExecutionInput; import graphql.schema.DataFetcher; import graphql.schema.DataFetcherFactories; import graphql.schema.GraphQLScalarType; @@ -515,11 +516,9 @@ private void processGraphQLApiAnnotations(SchemaType rootQueryType, Class clazz) throws IntrospectionException, ClassNotFoundException { - for (Map.Entry entry - : retrieveAllAnnotatedBeanMethods(clazz).entrySet()) { + for (Map.Entry entry : retrieveAllAnnotatedBeanMethods(clazz).entrySet()) { DiscoveredMethod discoveredMethod = entry.getValue(); Method method = discoveredMethod.method(); - SchemaFieldDefinition fd = null; // only include discovered methods in the original type where either the source is null @@ -552,7 +551,7 @@ private void processGraphQLApiAnnotations(SchemaType rootQueryType, a.argumentType(typeName); String returnType = a.argumentType(); - if (originalTypeName.equals(returnType) && !ID.equals(returnType)) { + if (originalTypeName.equals(returnType) && !ID.equals(returnType) && !a.isExecutionInput()) { // type name has not changed, so this must be either a Scalar, Enum or a Type // Note: Interfaces are not currently supported as InputTypes in 1.0 of the Specification // if is Scalar or enum then add to unresolved types and they will be dealt with @@ -1244,6 +1243,7 @@ private void processMethodParameters(Method method, DiscoveredMethod discoveredM .defaultValue(argumentDefaultValue) .originalType(paramType) .description(getDescription(parameter.getAnnotation(Description.class))) + .executionInput(paramType.equals(ExecutionInput.class)) .build(); String[] argumentFormat = getFormattingAnnotation(parameter); diff --git a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java index e29820b006a..2d378e6a8c6 100644 --- a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java +++ b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java @@ -120,6 +120,17 @@ public void testSchemaGenerationWithArrays() { assertThat(schemaArgument.getSchemaAsString(), is("name: [String!]")); } + @Test + public void testSchemaArgumentGenerationWithExecutionInput() { + SchemaArgument schemaArgument = SchemaArgument.builder() + .argumentName("test") + .executionInput(true) + .argumentType("String") + .build(); + + assertThat(schemaArgument.isExecutionInput(), is(true)); + } + @Test public void testSchemaGeneration() { SchemaArgument schemaArgument = SchemaArgument.builder() diff --git a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/ExecutionInputQueriesAndMutations.java b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/ExecutionInputQueriesAndMutations.java new file mode 100644 index 00000000000..7b90a8cf460 --- /dev/null +++ b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/ExecutionInputQueriesAndMutations.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * + * 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.helidon.microprofile.graphql.server.test.queries; + +import graphql.ExecutionInput; + +import javax.enterprise.context.ApplicationScoped; + +import org.eclipse.microprofile.graphql.GraphQLApi; +import org.eclipse.microprofile.graphql.Name; +import org.eclipse.microprofile.graphql.Query; + +/** + * Class that holds queries and mutations using {@link graphql.ExecutionInput}. + */ +@GraphQLApi +@ApplicationScoped +public class ExecutionInputQueriesAndMutations { + + public ExecutionInputQueriesAndMutations() { + } + + @Query + public String testExecutionInputNoArgs(ExecutionInput input) { + return input.getQuery(); + } + + @Query + public String testExecutionInputWithArgs(@Name("name") String name, ExecutionInput input) { + return name + input.getQuery(); + } + + @Query + public String testExecutionInputWithArgs2(@Name("name1") String name1, ExecutionInput input, @Name("name2") String name2) { + return name1 + name2 + input.getQuery(); + } +} diff --git a/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java b/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java new file mode 100644 index 00000000000..6fb10e2235f --- /dev/null +++ b/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * + * 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.helidon.microprofile.graphql.server; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static io.helidon.graphql.server.GraphQlConstants.ERRORS; +import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.DATETIME_SCALAR; +import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.DATE_SCALAR; +import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.FORMATTED_DATE_SCALAR; +import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.FORMATTED_TIME_SCALAR; +import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.TIME_SCALAR; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +import io.helidon.graphql.server.InvocationHandler; +import io.helidon.microprofile.graphql.server.test.db.TestDB; +import io.helidon.microprofile.graphql.server.test.queries.ExecutionInputQueriesAndMutations; +import io.helidon.microprofile.graphql.server.test.queries.SimpleQueriesAndMutations; +import io.helidon.microprofile.graphql.server.test.types.DateTimePojo; +import io.helidon.microprofile.graphql.server.test.types.SimpleDateTime; +import io.helidon.microprofile.tests.junit5.AddBean; +import javax.inject.Inject; +import org.junit.jupiter.api.Test; + +/** + * Tests for {@link graphql.ExecutionInput} injection. + */ +@AddBean(ExecutionInputQueriesAndMutations.class) +class ExecutionInputIT extends AbstractGraphQlCdiIT { + + @Inject + ExecutionInputIT(GraphQlCdiExtension graphQlCdiExtension) { + super(graphQlCdiExtension); + } + + @Test + @SuppressWarnings("unchecked") + public void testExecutionInputNoArgs() throws Exception { + setupIndex(indexFileName, ExecutionInputQueriesAndMutations.class); + InvocationHandler executionContext = createInvocationHandler(); + String query = "query { testExecutionInputNoArgs }"; + Map mapResults = getAndAssertResult(executionContext.execute(query)); + assertThat(mapResults, is(notNullValue())); + String results = (String) mapResults.get("testExecutionInputNoArgs"); + assertThat(results, is(query)); + } + + @Test + @SuppressWarnings("unchecked") + public void testExecutionInputWithArgs() throws Exception { + setupIndex(indexFileName, ExecutionInputQueriesAndMutations.class); + InvocationHandler executionContext = createInvocationHandler(); + + String query = "query { testExecutionInputWithArgs(name: \"Tim\") }"; + Map mapResults = getAndAssertResult(executionContext.execute(query)); + assertThat(mapResults, is(notNullValue())); + String results = (String) mapResults.get("testExecutionInputWithArgs"); + assertThat(results, is("Tim" + query)); + } + + @Test + @SuppressWarnings("unchecked") + public void testExecutionInputWithArgs2() throws Exception { + setupIndex(indexFileName, ExecutionInputQueriesAndMutations.class); + InvocationHandler executionContext = createInvocationHandler(); + + String query = "query { testExecutionInputWithArgs2(name1: \"Tim\", name2: \"Tim\") }"; + Map mapResults = getAndAssertResult(executionContext.execute(query)); + assertThat(mapResults, is(notNullValue())); + String results = (String) mapResults.get("testExecutionInputWithArgs2"); + assertThat(results, is("TimTim" + query )); + } + +} From 6149b0d6b8cccb166e70a11cb4b27e94c561e175 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Tue, 20 Jul 2021 10:48:11 +0800 Subject: [PATCH 2/8] Minor comment update --- .../microprofile/graphql/server/SchemaFieldDefinition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java index 6d038c715ea..1d89229d6c5 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java @@ -142,7 +142,7 @@ public String getSchemaAsString() { StringBuilder sb = new StringBuilder(getSchemaElementDescription(format())) .append(name()); - // determine if there are any arguments that are not ExecutionInput as they should + // determine if there are any arguments that are ExecutionInput as they should // not be included as standard types boolean hasSchemaArguments = listSchemaArguments.stream().anyMatch(a -> !a.isExecutionInput()); From 09164410c8ec1ca7fd481acc89f000279c762a5c Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Tue, 20 Jul 2021 11:48:58 +0800 Subject: [PATCH 3/8] Remove unused imports --- .../graphql/server/ExecutionInputIT.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java b/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java index 6fb10e2235f..ea175f82662 100644 --- a/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java +++ b/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java @@ -16,31 +16,18 @@ package io.helidon.microprofile.graphql.server; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.Map; -import java.util.Optional; -import static io.helidon.graphql.server.GraphQlConstants.ERRORS; -import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.DATETIME_SCALAR; -import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.DATE_SCALAR; -import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.FORMATTED_DATE_SCALAR; -import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.FORMATTED_TIME_SCALAR; -import static io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.TIME_SCALAR; +import javax.inject.Inject; + import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import io.helidon.graphql.server.InvocationHandler; -import io.helidon.microprofile.graphql.server.test.db.TestDB; import io.helidon.microprofile.graphql.server.test.queries.ExecutionInputQueriesAndMutations; -import io.helidon.microprofile.graphql.server.test.queries.SimpleQueriesAndMutations; -import io.helidon.microprofile.graphql.server.test.types.DateTimePojo; -import io.helidon.microprofile.graphql.server.test.types.SimpleDateTime; import io.helidon.microprofile.tests.junit5.AddBean; -import javax.inject.Inject; + import org.junit.jupiter.api.Test; /** From 537955737d1f84119e2fd68fab1dea588b3bd2be Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Wed, 21 Jul 2021 08:14:44 +0800 Subject: [PATCH 4/8] Fix copyright --- .../main/java/io/helidon/graphql/server/ExecutionContext.java | 2 +- .../java/io/helidon/graphql/server/ExecutionContextImpl.java | 2 +- .../java/io/helidon/graphql/server/InvocationHandlerImpl.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java index 0d5c9d798d0..0c8714ac645 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. + * Copyright (c) 2020,2021 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java index 3f3c9844134..6deabe8e9c2 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java b/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java index d9e2fafdc9f..16a15625d70 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 4e2bee615a39394a2faba00e215ba2b9cd1ce817 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Fri, 23 Jul 2021 08:38:53 +0800 Subject: [PATCH 5/8] Fix copyright year --- .../main/java/io/helidon/graphql/server/ExecutionContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java index 0c8714ac645..4f4f277f0ac 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020,2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From bacfdaac36e627653f535c3b1114c654c65a6253 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Tue, 27 Jul 2021 15:21:12 +0800 Subject: [PATCH 6/8] Update to use DataFetchingEnvironment instead of ExecutionInput --- .../graphql/server/ExecutionContext.java | 15 ---------- .../graphql/server/ExecutionContextImpl.java | 13 -------- .../graphql/server/InvocationHandlerImpl.java | 2 -- .../graphql/server/DataFetcherUtils.java | 13 ++++---- .../graphql/server/SchemaArgument.java | 30 ++++++++++--------- .../graphql/server/SchemaFieldDefinition.java | 4 +-- .../graphql/server/SchemaGenerator.java | 6 ++-- .../graphql/server/SchemaArgumentTest.java | 4 +-- ...tchingEnvironmentQueriesAndMutations.java} | 20 ++++++------- ...IT.java => DataFetchingEnvironmentIT.java} | 27 ++++++++--------- 10 files changed, 51 insertions(+), 83 deletions(-) rename microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/{ExecutionInputQueriesAndMutations.java => DataFetchingEnvironmentQueriesAndMutations.java} (66%) rename tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/{ExecutionInputIT.java => DataFetchingEnvironmentIT.java} (72%) diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java index 4f4f277f0ac..46efd9dcce5 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java @@ -16,7 +16,6 @@ package io.helidon.graphql.server; -import graphql.ExecutionInput; /** * GraphQL execution context to support partial results. @@ -42,18 +41,4 @@ public interface ExecutionContext { * @return true if there was a partial results exception */ boolean hasPartialResultsException(); - - /** - * Add the {@link ExecutionInput}. - * - * @param input {@link ExecutionInput} - */ - void setExecutionInput(ExecutionInput input); - - /** - * Retrieve the {@link ExecutionInput}. - * - * @return the {@link ExecutionInput} - */ - ExecutionInput executionInput(); } diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java index 6deabe8e9c2..8adb0218e03 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContextImpl.java @@ -18,11 +18,8 @@ import java.util.concurrent.atomic.AtomicReference; -import graphql.ExecutionInput; - class ExecutionContextImpl implements ExecutionContext { private final AtomicReference currentThrowable = new AtomicReference<>(); - private final AtomicReference currentExecutionInput = new AtomicReference<>(); ExecutionContextImpl() { } @@ -41,14 +38,4 @@ public Throwable partialResultsException() { public boolean hasPartialResultsException() { return currentThrowable.get() != null; } - - @Override - public void setExecutionInput(ExecutionInput input) { - currentExecutionInput.set(input); - } - - @Override - public ExecutionInput executionInput() { - return currentExecutionInput.get(); - } } diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java b/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java index 16a15625d70..ba8a81b37ec 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/InvocationHandlerImpl.java @@ -92,8 +92,6 @@ private Map doExecute(String query, String operationName, Map errors = result.getErrors(); diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/DataFetcherUtils.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/DataFetcherUtils.java index 290e6c1b5a9..16d2097b28b 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/DataFetcherUtils.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/DataFetcherUtils.java @@ -47,7 +47,6 @@ import io.helidon.graphql.server.ExecutionContext; -import graphql.ExecutionInput; import graphql.GraphQLException; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; @@ -123,16 +122,14 @@ static DataFetcher newMethodDataFetcher(Schema schema, Class clazz, Me } ExecutionContext executionContext; - // check for a single ExecutionInput parameter as args will be zero + // check for a single DataFetchingEnvironment parameter as args will be zero Parameter[] parameters = method.getParameters(); - if (parameters.length == 1 && parameters[0].getType().equals(ExecutionInput.class)) { - executionContext = environment.getContext(); - listArgumentValues.add(executionContext.executionInput()); + if (parameters.length == 1 && parameters[0].getType().equals(DataFetchingEnvironment.class)) { + listArgumentValues.add(environment); } else if (args.length > 0) { for (SchemaArgument argument : args) { - if (argument.isExecutionInput()) { - executionContext = environment.getContext(); - listArgumentValues.add(executionContext.executionInput()); + if (argument.isDataFetchingEnvironment()) { + listArgumentValues.add(environment); } else { // ensure a Map is not used as an input type Class originalType = argument.originalType(); diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java index 611b4f4e8e5..360c14e3088 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java @@ -19,6 +19,8 @@ import java.util.Arrays; import java.util.Objects; +import graphql.schema.DataFetchingEnvironment; + /** * The representation of a GraphQL Argument or Parameter. */ @@ -81,7 +83,7 @@ class SchemaArgument extends AbstractDescriptiveElement implements ElementGenera /** * Indicates if the argument type is the {@link graphql.ExecutionInput} and must be ignored in schema generation. */ - private boolean isExecutionInput; + private boolean isDataFetchingEnvironment; /** * Construct a {@link SchemaArgument}. @@ -100,7 +102,7 @@ private SchemaArgument(Builder builder) { this.arrayLevels = builder.arrayLevels; this.isArrayReturnTypeMandatory = builder.isArrayReturnTypeMandatory; this.originalArrayType = builder.originalArrayType; - this.isExecutionInput = builder.isExecutionInput; + this.isDataFetchingEnvironment = builder.isDataFetchingEnvironment; description(builder.description); } @@ -306,12 +308,12 @@ public void arrayReturnTypeMandatory(boolean arrayReturnTypeMandatory) { } /** - * Indicates if the argument type is the {@link graphql.ExecutionInput} and must be ignored in schema generation. + * Indicates if the argument type is the {@link DataFetchingEnvironment} and must be ignored in schema generation. * - * @return true if the argument type is the {@link graphql.ExecutionInput} + * @return true if the argument type is the {@link DataFetchingEnvironment} */ - public boolean isExecutionInput() { - return isExecutionInput; + public boolean isDataFetchingEnvironment() { + return isDataFetchingEnvironment; } /** @@ -344,7 +346,7 @@ public String toString() { + ", isReturnTypeMandatory=" + isArrayReturnTypeMandatory + ", isArrayReturnType=" + isArrayReturnType + ", originalArrayType=" + originalArrayType - + ", isExecutionInput=" + isExecutionInput + + ", isDataFetchingEnvironment=" + isDataFetchingEnvironment + ", arrayLevels=" + arrayLevels + ", format=" + Arrays.toString(format) + ", description='" + description() + '\'' + '}'; @@ -369,14 +371,14 @@ public boolean equals(Object o) { && Arrays.equals(format, schemaArgument.format) && Objects.equals(sourceArgument, schemaArgument.sourceArgument) && Objects.equals(originalArrayType, schemaArgument.originalArrayType) - && Objects.equals(isExecutionInput, schemaArgument.isExecutionInput) + && Objects.equals(isDataFetchingEnvironment, schemaArgument.isDataFetchingEnvironment) && Objects.equals(description(), schemaArgument.description()) && Objects.equals(defaultValue, schemaArgument.defaultValue); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), argumentName, argumentType, sourceArgument, isExecutionInput, + return Objects.hash(super.hashCode(), argumentName, argumentType, sourceArgument, isDataFetchingEnvironment, isMandatory, defaultValue, description(), originalType, format, originalArrayType); } @@ -397,7 +399,7 @@ public static class Builder implements io.helidon.common.Builder private int arrayLevels; private boolean isArrayReturnTypeMandatory; private Class originalArrayType; - private boolean isExecutionInput; + private boolean isDataFetchingEnvironment; /** * Set the argument name. @@ -534,13 +536,13 @@ public Builder originalArrayType(Class originalArrayType) { } /** - * Set if the argument type is the {@link graphql.ExecutionInput} and must be ignored in schema generation. + * Set if the argument type is the {@link DataFetchingEnvironment} and must be ignored in schema generation. * - * @param isExecutionInput if the argument type is the {@link graphql.ExecutionInput} + * @param isDataFetchingEnvironment if the argument type is the {@link DataFetchingEnvironment} * @return updated builder instance */ - public Builder executionInput(boolean isExecutionInput) { - this.isExecutionInput = isExecutionInput; + public Builder dataFetchingEnvironment(boolean isDataFetchingEnvironment) { + this.isDataFetchingEnvironment = isDataFetchingEnvironment; return this; } diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java index 1d89229d6c5..7c6afa7895c 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java @@ -144,13 +144,13 @@ public String getSchemaAsString() { // determine if there are any arguments that are ExecutionInput as they should // not be included as standard types - boolean hasSchemaArguments = listSchemaArguments.stream().anyMatch(a -> !a.isExecutionInput()); + boolean hasSchemaArguments = listSchemaArguments.stream().anyMatch(a -> !a.isDataFetchingEnvironment()); if (hasSchemaArguments) { sb.append(OPEN_PARENTHESES) .append(NEWLINE) .append(listSchemaArguments.stream() - .filter(a -> !a.isExecutionInput()) + .filter(a -> !a.isDataFetchingEnvironment()) .map(SchemaArgument::getSchemaAsString) .collect(Collectors.joining(COMMA_SPACE + NEWLINE))); sb.append(NEWLINE).append(CLOSE_PARENTHESES); diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaGenerator.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaGenerator.java index b1a5409d01d..757c3d64470 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaGenerator.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaGenerator.java @@ -44,9 +44,9 @@ import io.helidon.microprofile.graphql.server.SchemaGeneratorHelper.DiscoveredMethod; -import graphql.ExecutionInput; import graphql.schema.DataFetcher; import graphql.schema.DataFetcherFactories; +import graphql.schema.DataFetchingEnvironment; import graphql.schema.GraphQLScalarType; import graphql.schema.PropertyDataFetcher; import org.eclipse.microprofile.graphql.Description; @@ -551,7 +551,7 @@ private void processGraphQLApiAnnotations(SchemaType rootQueryType, a.argumentType(typeName); String returnType = a.argumentType(); - if (originalTypeName.equals(returnType) && !ID.equals(returnType) && !a.isExecutionInput()) { + if (originalTypeName.equals(returnType) && !ID.equals(returnType) && !a.isDataFetchingEnvironment()) { // type name has not changed, so this must be either a Scalar, Enum or a Type // Note: Interfaces are not currently supported as InputTypes in 1.0 of the Specification // if is Scalar or enum then add to unresolved types and they will be dealt with @@ -1243,7 +1243,7 @@ private void processMethodParameters(Method method, DiscoveredMethod discoveredM .defaultValue(argumentDefaultValue) .originalType(paramType) .description(getDescription(parameter.getAnnotation(Description.class))) - .executionInput(paramType.equals(ExecutionInput.class)) + .dataFetchingEnvironment(paramType.equals(DataFetchingEnvironment.class)) .build(); String[] argumentFormat = getFormattingAnnotation(parameter); diff --git a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java index 2d378e6a8c6..9c403b41a5f 100644 --- a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java +++ b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java @@ -124,11 +124,11 @@ public void testSchemaGenerationWithArrays() { public void testSchemaArgumentGenerationWithExecutionInput() { SchemaArgument schemaArgument = SchemaArgument.builder() .argumentName("test") - .executionInput(true) + .dataFetchingEnvironment(true) .argumentType("String") .build(); - assertThat(schemaArgument.isExecutionInput(), is(true)); + assertThat(schemaArgument.isDataFetchingEnvironment(), is(true)); } @Test diff --git a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/ExecutionInputQueriesAndMutations.java b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/DataFetchingEnvironmentQueriesAndMutations.java similarity index 66% rename from microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/ExecutionInputQueriesAndMutations.java rename to microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/DataFetchingEnvironmentQueriesAndMutations.java index 7b90a8cf460..f1819991588 100644 --- a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/ExecutionInputQueriesAndMutations.java +++ b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/DataFetchingEnvironmentQueriesAndMutations.java @@ -16,7 +16,7 @@ package io.helidon.microprofile.graphql.server.test.queries; -import graphql.ExecutionInput; +import graphql.schema.DataFetchingEnvironment; import javax.enterprise.context.ApplicationScoped; @@ -25,27 +25,27 @@ import org.eclipse.microprofile.graphql.Query; /** - * Class that holds queries and mutations using {@link graphql.ExecutionInput}. + * Class that holds queries and mutations using {@link DataFetchingEnvironment}. */ @GraphQLApi @ApplicationScoped -public class ExecutionInputQueriesAndMutations { +public class DataFetchingEnvironmentQueriesAndMutations { - public ExecutionInputQueriesAndMutations() { + public DataFetchingEnvironmentQueriesAndMutations() { } @Query - public String testExecutionInputNoArgs(ExecutionInput input) { - return input.getQuery(); + public String testExecutionInputNoArgs(DataFetchingEnvironment env) { + return env.getField().getName(); } @Query - public String testExecutionInputWithArgs(@Name("name") String name, ExecutionInput input) { - return name + input.getQuery(); + public String testExecutionInputWithArgs(@Name("name") String name, DataFetchingEnvironment env) { + return name + env.getField().getName(); } @Query - public String testExecutionInputWithArgs2(@Name("name1") String name1, ExecutionInput input, @Name("name2") String name2) { - return name1 + name2 + input.getQuery(); + public String testExecutionInputWithArgs2(@Name("name1") String name1, DataFetchingEnvironment env, @Name("name2") String name2) { + return name1 + name2 + env.getField().getName(); } } diff --git a/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java b/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/DataFetchingEnvironmentIT.java similarity index 72% rename from tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java rename to tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/DataFetchingEnvironmentIT.java index ea175f82662..6885985344e 100644 --- a/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/ExecutionInputIT.java +++ b/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/DataFetchingEnvironmentIT.java @@ -25,7 +25,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import io.helidon.graphql.server.InvocationHandler; -import io.helidon.microprofile.graphql.server.test.queries.ExecutionInputQueriesAndMutations; +import io.helidon.microprofile.graphql.server.test.queries.DataFetchingEnvironmentQueriesAndMutations; import io.helidon.microprofile.tests.junit5.AddBean; import org.junit.jupiter.api.Test; @@ -33,50 +33,49 @@ /** * Tests for {@link graphql.ExecutionInput} injection. */ -@AddBean(ExecutionInputQueriesAndMutations.class) -class ExecutionInputIT extends AbstractGraphQlCdiIT { +@AddBean(DataFetchingEnvironmentQueriesAndMutations.class) +class DataFetchingEnvironmentIT extends AbstractGraphQlCdiIT { @Inject - ExecutionInputIT(GraphQlCdiExtension graphQlCdiExtension) { + DataFetchingEnvironmentIT(GraphQlCdiExtension graphQlCdiExtension) { super(graphQlCdiExtension); } @Test @SuppressWarnings("unchecked") - public void testExecutionInputNoArgs() throws Exception { - setupIndex(indexFileName, ExecutionInputQueriesAndMutations.class); + public void testWithNoArgs() throws Exception { + setupIndex(indexFileName, DataFetchingEnvironmentQueriesAndMutations.class); InvocationHandler executionContext = createInvocationHandler(); String query = "query { testExecutionInputNoArgs }"; Map mapResults = getAndAssertResult(executionContext.execute(query)); assertThat(mapResults, is(notNullValue())); String results = (String) mapResults.get("testExecutionInputNoArgs"); - assertThat(results, is(query)); + assertThat(results, is("testExecutionInputNoArgs")); } @Test @SuppressWarnings("unchecked") - public void testExecutionInputWithArgs() throws Exception { - setupIndex(indexFileName, ExecutionInputQueriesAndMutations.class); + public void testWithArgs() throws Exception { + setupIndex(indexFileName, DataFetchingEnvironmentQueriesAndMutations.class); InvocationHandler executionContext = createInvocationHandler(); String query = "query { testExecutionInputWithArgs(name: \"Tim\") }"; Map mapResults = getAndAssertResult(executionContext.execute(query)); assertThat(mapResults, is(notNullValue())); String results = (String) mapResults.get("testExecutionInputWithArgs"); - assertThat(results, is("Tim" + query)); + assertThat(results, is("Tim" + "testExecutionInputWithArgs")); } @Test @SuppressWarnings("unchecked") - public void testExecutionInputWithArgs2() throws Exception { - setupIndex(indexFileName, ExecutionInputQueriesAndMutations.class); + public void testWithArgs2() throws Exception { + setupIndex(indexFileName, DataFetchingEnvironmentQueriesAndMutations.class); InvocationHandler executionContext = createInvocationHandler(); String query = "query { testExecutionInputWithArgs2(name1: \"Tim\", name2: \"Tim\") }"; Map mapResults = getAndAssertResult(executionContext.execute(query)); assertThat(mapResults, is(notNullValue())); String results = (String) mapResults.get("testExecutionInputWithArgs2"); - assertThat(results, is("TimTim" + query )); + assertThat(results, is("TimTim" + "testExecutionInputWithArgs2" )); } - } From defcc808f3ef86f0638a4616b39e25c2043241cc Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Tue, 27 Jul 2021 15:46:05 +0800 Subject: [PATCH 7/8] Minor comment fixes and typos --- .../graphql/server/ExecutionContext.java | 1 - .../graphql/server/SchemaArgument.java | 2 +- .../graphql/server/SchemaFieldDefinition.java | 2 +- ...etchingEnvironmentQueriesAndMutations.java | 6 +++--- .../server/DataFetchingEnvironmentIT.java | 20 +++++++++---------- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java index 46efd9dcce5..d0b939c2037 100644 --- a/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java +++ b/graphql/server/src/main/java/io/helidon/graphql/server/ExecutionContext.java @@ -16,7 +16,6 @@ package io.helidon.graphql.server; - /** * GraphQL execution context to support partial results. */ diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java index 360c14e3088..7e50a43bf0b 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaArgument.java @@ -81,7 +81,7 @@ class SchemaArgument extends AbstractDescriptiveElement implements ElementGenera private Class originalArrayType; /** - * Indicates if the argument type is the {@link graphql.ExecutionInput} and must be ignored in schema generation. + * Indicates if the argument type is the {@link DataFetchingEnvironment} and must be ignored in schema generation. */ private boolean isDataFetchingEnvironment; diff --git a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java index 7c6afa7895c..81b108450fb 100644 --- a/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java +++ b/microprofile/graphql/server/src/main/java/io/helidon/microprofile/graphql/server/SchemaFieldDefinition.java @@ -142,7 +142,7 @@ public String getSchemaAsString() { StringBuilder sb = new StringBuilder(getSchemaElementDescription(format())) .append(name()); - // determine if there are any arguments that are ExecutionInput as they should + // determine if there are any arguments that are DataFetcherEnvironment as they should // not be included as standard types boolean hasSchemaArguments = listSchemaArguments.stream().anyMatch(a -> !a.isDataFetchingEnvironment()); diff --git a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/DataFetchingEnvironmentQueriesAndMutations.java b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/DataFetchingEnvironmentQueriesAndMutations.java index f1819991588..6ad9f9cccd0 100644 --- a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/DataFetchingEnvironmentQueriesAndMutations.java +++ b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/test/queries/DataFetchingEnvironmentQueriesAndMutations.java @@ -35,17 +35,17 @@ public DataFetchingEnvironmentQueriesAndMutations() { } @Query - public String testExecutionInputNoArgs(DataFetchingEnvironment env) { + public String testNoArgs(DataFetchingEnvironment env) { return env.getField().getName(); } @Query - public String testExecutionInputWithArgs(@Name("name") String name, DataFetchingEnvironment env) { + public String testWithArgs(@Name("name") String name, DataFetchingEnvironment env) { return name + env.getField().getName(); } @Query - public String testExecutionInputWithArgs2(@Name("name1") String name1, DataFetchingEnvironment env, @Name("name2") String name2) { + public String testWithArgs2(@Name("name1") String name1, DataFetchingEnvironment env, @Name("name2") String name2) { return name1 + name2 + env.getField().getName(); } } diff --git a/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/DataFetchingEnvironmentIT.java b/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/DataFetchingEnvironmentIT.java index 6885985344e..b8607b5e52b 100644 --- a/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/DataFetchingEnvironmentIT.java +++ b/tests/integration/mp-graphql/src/test/java/io/helidon/microprofile/graphql/server/DataFetchingEnvironmentIT.java @@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test; /** - * Tests for {@link graphql.ExecutionInput} injection. + * Tests for {@link graphql.schema.DataFetchingEnvironment} injection. */ @AddBean(DataFetchingEnvironmentQueriesAndMutations.class) class DataFetchingEnvironmentIT extends AbstractGraphQlCdiIT { @@ -46,11 +46,11 @@ class DataFetchingEnvironmentIT extends AbstractGraphQlCdiIT { public void testWithNoArgs() throws Exception { setupIndex(indexFileName, DataFetchingEnvironmentQueriesAndMutations.class); InvocationHandler executionContext = createInvocationHandler(); - String query = "query { testExecutionInputNoArgs }"; + String query = "query { testNoArgs }"; Map mapResults = getAndAssertResult(executionContext.execute(query)); assertThat(mapResults, is(notNullValue())); - String results = (String) mapResults.get("testExecutionInputNoArgs"); - assertThat(results, is("testExecutionInputNoArgs")); + String results = (String) mapResults.get("testNoArgs"); + assertThat(results, is("testNoArgs")); } @Test @@ -59,11 +59,11 @@ public void testWithArgs() throws Exception { setupIndex(indexFileName, DataFetchingEnvironmentQueriesAndMutations.class); InvocationHandler executionContext = createInvocationHandler(); - String query = "query { testExecutionInputWithArgs(name: \"Tim\") }"; + String query = "query { testWithArgs(name: \"Tim\") }"; Map mapResults = getAndAssertResult(executionContext.execute(query)); assertThat(mapResults, is(notNullValue())); - String results = (String) mapResults.get("testExecutionInputWithArgs"); - assertThat(results, is("Tim" + "testExecutionInputWithArgs")); + String results = (String) mapResults.get("testWithArgs"); + assertThat(results, is("Tim" + "testWithArgs")); } @Test @@ -72,10 +72,10 @@ public void testWithArgs2() throws Exception { setupIndex(indexFileName, DataFetchingEnvironmentQueriesAndMutations.class); InvocationHandler executionContext = createInvocationHandler(); - String query = "query { testExecutionInputWithArgs2(name1: \"Tim\", name2: \"Tim\") }"; + String query = "query { testWithArgs2(name1: \"Tim\", name2: \"Tim\") }"; Map mapResults = getAndAssertResult(executionContext.execute(query)); assertThat(mapResults, is(notNullValue())); - String results = (String) mapResults.get("testExecutionInputWithArgs2"); - assertThat(results, is("TimTim" + "testExecutionInputWithArgs2" )); + String results = (String) mapResults.get("testWithArgs2"); + assertThat(results, is("TimTim" + "testWithArgs2" )); } } From 381becc16ed03a09a4e1553ae19c5efead09d769 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Tue, 27 Jul 2021 15:47:49 +0800 Subject: [PATCH 8/8] minor --- .../helidon/microprofile/graphql/server/SchemaArgumentTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java index 9c403b41a5f..755b73c9b99 100644 --- a/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java +++ b/microprofile/graphql/server/src/test/java/io/helidon/microprofile/graphql/server/SchemaArgumentTest.java @@ -121,7 +121,7 @@ public void testSchemaGenerationWithArrays() { } @Test - public void testSchemaArgumentGenerationWithExecutionInput() { + public void testSchemaArgumentGenerationWithDataFetchingEnvironment() { SchemaArgument schemaArgument = SchemaArgument.builder() .argumentName("test") .dataFetchingEnvironment(true)