From 146346a7c5be47c6d21ab4c8aaf8139c223cf3dd Mon Sep 17 00:00:00 2001 From: dondonz <13839920+dondonz@users.noreply.github.com> Date: Tue, 24 May 2022 16:43:13 +1000 Subject: [PATCH] Cherry pick raw and coerced variable refactor --- src/main/java/graphql/ExecutionInput.java | 35 ++- .../analysis/NodeVisitorWithTypeTracking.java | 3 +- .../java/graphql/analysis/QueryTraverser.java | 16 +- .../graphql/execution/CoercedVariables.java | 35 +++ .../graphql/execution/ConditionalNodes.java | 2 +- .../java/graphql/execution/Execution.java | 7 +- .../graphql/execution/ExecutionContext.java | 17 +- .../execution/ExecutionContextBuilder.java | 16 +- .../execution/ExecutionStepInfoFactory.java | 2 +- .../graphql/execution/ExecutionStrategy.java | 2 +- .../java/graphql/execution/RawVariables.java | 35 +++ .../graphql/execution/ValuesResolver.java | 47 ++-- .../directives/DirectivesResolver.java | 3 +- .../execution/nextgen/ExecutionHelper.java | 11 +- .../execution/nextgen/ValueFetcher.java | 2 +- .../ExecutableNormalizedOperationFactory.java | 21 +- .../groovy/graphql/ExecutionInputTest.groovy | 28 +++ src/test/groovy/graphql/GraphQLTest.groovy | 4 - .../execution/ConditionalNodesTest.groovy | 7 +- .../ExecutionContextBuilderTest.groovy | 222 +++++++++++++++--- .../graphql/execution/ExecutionTest.groovy | 8 +- .../execution/ValuesResolverTest.groovy | 84 +++---- ...tableNormalizedOperationFactoryTest.groovy | 180 +++++++------- ...ormalizedOperationToAstCompilerTest.groovy | 3 +- src/test/java/benchmark/NQBenchmark1.java | 3 +- src/test/java/benchmark/NQBenchmark2.java | 5 +- 26 files changed, 527 insertions(+), 271 deletions(-) create mode 100644 src/main/java/graphql/execution/CoercedVariables.java create mode 100644 src/main/java/graphql/execution/RawVariables.java diff --git a/src/main/java/graphql/ExecutionInput.java b/src/main/java/graphql/ExecutionInput.java index 777b2d4ab7..eb81404e92 100644 --- a/src/main/java/graphql/ExecutionInput.java +++ b/src/main/java/graphql/ExecutionInput.java @@ -2,6 +2,7 @@ import graphql.cachecontrol.CacheControl; import graphql.execution.ExecutionId; +import graphql.execution.RawVariables; import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationState; import org.dataloader.DataLoaderRegistry; @@ -24,7 +25,7 @@ public class ExecutionInput { private final GraphQLContext graphQLContext; private final Object localContext; private final Object root; - private final Map variables; + private final RawVariables rawVariables; private final Map extensions; private final DataLoaderRegistry dataLoaderRegistry; private final CacheControl cacheControl; @@ -39,7 +40,7 @@ private ExecutionInput(Builder builder) { this.context = builder.context; this.graphQLContext = assertNotNull(builder.graphQLContext); this.root = builder.root; - this.variables = builder.variables; + this.rawVariables = builder.rawVariables; this.dataLoaderRegistry = builder.dataLoaderRegistry; this.cacheControl = builder.cacheControl; this.executionId = builder.executionId; @@ -97,10 +98,17 @@ public Object getRoot() { } /** - * @return a map of variables that can be referenced via $syntax in the query + * @return a map of raw variables that can be referenced via $syntax in the query. */ public Map getVariables() { - return variables; + return rawVariables.toMap(); + } + + /** + * @return a map of raw variables that can be referenced via $syntax in the query. + */ + public RawVariables getRawVariables() { + return rawVariables; } /** @@ -158,7 +166,7 @@ public ExecutionInput transform(Consumer builderConsumer) { .root(this.root) .dataLoaderRegistry(this.dataLoaderRegistry) .cacheControl(this.cacheControl) - .variables(this.variables) + .variables(this.rawVariables.toMap()) .extensions(this.extensions) .executionId(this.executionId) .locale(this.locale); @@ -176,7 +184,7 @@ public String toString() { ", context=" + context + ", graphQLContext=" + graphQLContext + ", root=" + root + - ", variables=" + variables + + ", rawVariables=" + rawVariables + ", dataLoaderRegistry=" + dataLoaderRegistry + ", executionId= " + executionId + ", locale= " + locale + @@ -209,7 +217,7 @@ public static class Builder { private Object context = graphQLContext; // we make these the same object on purpose - legacy code will get the same object if this change nothing private Object localContext; private Object root; - private Map variables = Collections.emptyMap(); + private RawVariables rawVariables = RawVariables.emptyVariables(); public Map extensions = Collections.emptyMap(); // // this is important - it allows code to later known if we never really set a dataloader and hence it can optimize @@ -242,7 +250,6 @@ public Builder executionId(ExecutionId executionId) { return this; } - /** * Sets the locale to use for this operation * @@ -351,8 +358,16 @@ public Builder root(Object root) { return this; } - public Builder variables(Map variables) { - this.variables = assertNotNull(variables, () -> "variables map can't be null"); + /** + * Adds raw (not coerced) variables + * + * @param rawVariables the map of raw variables + * + * @return this builder + */ + public Builder variables(Map rawVariables) { + assertNotNull(rawVariables, () -> "variables map can't be null"); + this.rawVariables = new RawVariables(rawVariables); return this; } diff --git a/src/main/java/graphql/analysis/NodeVisitorWithTypeTracking.java b/src/main/java/graphql/analysis/NodeVisitorWithTypeTracking.java index 4c66d6e772..1302393280 100644 --- a/src/main/java/graphql/analysis/NodeVisitorWithTypeTracking.java +++ b/src/main/java/graphql/analysis/NodeVisitorWithTypeTracking.java @@ -1,6 +1,7 @@ package graphql.analysis; import graphql.Internal; +import graphql.execution.CoercedVariables; import graphql.execution.ConditionalNodes; import graphql.execution.ValuesResolver; import graphql.introspection.Introspection; @@ -154,7 +155,7 @@ public TraversalControl visitField(Field field, TraverserContext context) boolean isTypeNameIntrospectionField = fieldDefinition == schema.getIntrospectionTypenameFieldDefinition(); GraphQLFieldsContainer fieldsContainer = !isTypeNameIntrospectionField ? (GraphQLFieldsContainer) unwrapAll(parentEnv.getOutputType()) : null; GraphQLCodeRegistry codeRegistry = schema.getCodeRegistry(); - Map argumentValues = valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), field.getArguments(), variables); + Map argumentValues = valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), field.getArguments(), new CoercedVariables(variables)); QueryVisitorFieldEnvironment environment = new QueryVisitorFieldEnvironmentImpl(isTypeNameIntrospectionField, field, fieldDefinition, diff --git a/src/main/java/graphql/analysis/QueryTraverser.java b/src/main/java/graphql/analysis/QueryTraverser.java index a05e780214..7b5ff7735e 100644 --- a/src/main/java/graphql/analysis/QueryTraverser.java +++ b/src/main/java/graphql/analysis/QueryTraverser.java @@ -1,6 +1,8 @@ package graphql.analysis; import graphql.PublicApi; +import graphql.execution.CoercedVariables; +import graphql.execution.RawVariables; import graphql.execution.ValuesResolver; import graphql.language.Document; import graphql.language.FragmentDefinition; @@ -42,7 +44,7 @@ public class QueryTraverser { private final Collection roots; private final GraphQLSchema schema; private final Map fragmentsByName; - private final Map variables; + private CoercedVariables coercedVariables; private final GraphQLCompositeType rootParentType; @@ -50,18 +52,18 @@ private QueryTraverser(GraphQLSchema schema, Document document, String operation, Map variables) { - assertNotNull(document, () -> "document can't be null"); + assertNotNull(document, () -> "document can't be null"); NodeUtil.GetOperationResult getOperationResult = NodeUtil.getOperation(document, operation); List variableDefinitions = getOperationResult.operationDefinition.getVariableDefinitions(); this.schema = assertNotNull(schema, () -> "schema can't be null"); this.fragmentsByName = getOperationResult.fragmentsByName; this.roots = singletonList(getOperationResult.operationDefinition); this.rootParentType = getRootTypeFromOperation(getOperationResult.operationDefinition); - this.variables = coerceVariables(assertNotNull(variables, () -> "variables can't be null"), variableDefinitions); + this.coercedVariables = coerceVariables(assertNotNull(variables, () -> "variables can't be null"), variableDefinitions); } - private Map coerceVariables(Map rawVariables, List variableDefinitions) { - return new ValuesResolver().coerceVariableValues(schema, variableDefinitions, rawVariables); + private CoercedVariables coerceVariables(Map rawVariables, List variableDefinitions) { + return new ValuesResolver().coerceVariableValues(schema, variableDefinitions, new RawVariables(rawVariables)); } private QueryTraverser(GraphQLSchema schema, @@ -70,11 +72,11 @@ private QueryTraverser(GraphQLSchema schema, Map fragmentsByName, Map variables) { this.schema = assertNotNull(schema, () -> "schema can't be null"); - this.variables = assertNotNull(variables, () -> "variables can't be null"); assertNotNull(root, () -> "root can't be null"); this.roots = Collections.singleton(root); this.rootParentType = assertNotNull(rootParentType, () -> "rootParentType can't be null"); this.fragmentsByName = assertNotNull(fragmentsByName, () -> "fragmentsByName can't be null"); + this.coercedVariables = new CoercedVariables(assertNotNull(variables, () -> "variables can't be null")); } public Object visitDepthFirst(QueryVisitor queryVisitor) { @@ -181,7 +183,7 @@ private Object visitImpl(QueryVisitor visitFieldCallback, Boolean preOrder) { } NodeTraverser nodeTraverser = new NodeTraverser(rootVars, this::childrenOf); - NodeVisitorWithTypeTracking nodeVisitorWithTypeTracking = new NodeVisitorWithTypeTracking(preOrderCallback, postOrderCallback, variables, schema, fragmentsByName); + NodeVisitorWithTypeTracking nodeVisitorWithTypeTracking = new NodeVisitorWithTypeTracking(preOrderCallback, postOrderCallback, coercedVariables.toMap(), schema, fragmentsByName); return nodeTraverser.depthFirst(nodeVisitorWithTypeTracking, roots); } diff --git a/src/main/java/graphql/execution/CoercedVariables.java b/src/main/java/graphql/execution/CoercedVariables.java new file mode 100644 index 0000000000..25aad43b27 --- /dev/null +++ b/src/main/java/graphql/execution/CoercedVariables.java @@ -0,0 +1,35 @@ +package graphql.execution; + +import graphql.Internal; +import graphql.collect.ImmutableKit; +import graphql.collect.ImmutableMapWithNullValues; + +import java.util.Map; + +/** + * Holds coerced variables + */ +@Internal +public class CoercedVariables { + private final ImmutableMapWithNullValues coercedVariables; + + public CoercedVariables(Map coercedVariables) { + this.coercedVariables = ImmutableMapWithNullValues.copyOf(coercedVariables); + } + + public Map toMap() { + return coercedVariables; + } + + public boolean containsKey(String key) { + return coercedVariables.containsKey(key); + } + + public Object get(String key) { + return coercedVariables.get(key); + } + + public static CoercedVariables emptyVariables() { + return new CoercedVariables(ImmutableKit.emptyMap()); + } +} diff --git a/src/main/java/graphql/execution/ConditionalNodes.java b/src/main/java/graphql/execution/ConditionalNodes.java index bd13855318..b1afe580ad 100644 --- a/src/main/java/graphql/execution/ConditionalNodes.java +++ b/src/main/java/graphql/execution/ConditionalNodes.java @@ -34,7 +34,7 @@ public boolean shouldInclude(Map variables, List dire private boolean getDirectiveResult(Map variables, List directives, String directiveName, boolean defaultValue) { Directive foundDirective = NodeUtil.findNodeByName(directives, directiveName); if (foundDirective != null) { - Map argumentValues = valuesResolver.getArgumentValues(SkipDirective.getArguments(), foundDirective.getArguments(), variables); + Map argumentValues = valuesResolver.getArgumentValues(SkipDirective.getArguments(), foundDirective.getArguments(), new CoercedVariables(variables)); Object flag = argumentValues.get("if"); Assert.assertTrue(flag instanceof Boolean, () -> String.format("The '%s' directive MUST have a value for the 'if' argument", directiveName)); return (Boolean) flag; diff --git a/src/main/java/graphql/execution/Execution.java b/src/main/java/graphql/execution/Execution.java index 01e6e85034..5e113f1621 100644 --- a/src/main/java/graphql/execution/Execution.java +++ b/src/main/java/graphql/execution/Execution.java @@ -30,7 +30,6 @@ import static graphql.execution.ExecutionContextBuilder.newExecutionContextBuilder; import static graphql.execution.ExecutionStepInfo.newExecutionStepInfo; import static graphql.execution.ExecutionStrategyParameters.newParameters; -import static graphql.execution.nextgen.Common.getOperationRootType; import static graphql.language.OperationDefinition.Operation.MUTATION; import static graphql.language.OperationDefinition.Operation.QUERY; import static graphql.language.OperationDefinition.Operation.SUBSCRIPTION; @@ -62,10 +61,10 @@ public CompletableFuture execute(Document document, GraphQLSche Map fragmentsByName = getOperationResult.fragmentsByName; OperationDefinition operationDefinition = getOperationResult.operationDefinition; - Map inputVariables = executionInput.getVariables(); + RawVariables inputVariables = executionInput.getRawVariables(); List variableDefinitions = operationDefinition.getVariableDefinitions(); - Map coercedVariables; + CoercedVariables coercedVariables; try { coercedVariables = valuesResolver.coerceVariableValues(graphQLSchema, variableDefinitions, inputVariables); } catch (RuntimeException rte) { @@ -88,7 +87,7 @@ public CompletableFuture execute(Document document, GraphQLSche .localContext(executionInput.getLocalContext()) .root(executionInput.getRoot()) .fragmentsByName(fragmentsByName) - .variables(coercedVariables) + .coercedVariables(coercedVariables) .document(document) .operationDefinition(operationDefinition) .dataLoaderRegistry(executionInput.getDataLoaderRegistry()) diff --git a/src/main/java/graphql/execution/ExecutionContext.java b/src/main/java/graphql/execution/ExecutionContext.java index a5019fe1d6..bf774165a3 100644 --- a/src/main/java/graphql/execution/ExecutionContext.java +++ b/src/main/java/graphql/execution/ExecutionContext.java @@ -9,7 +9,6 @@ import graphql.PublicApi; import graphql.cachecontrol.CacheControl; import graphql.collect.ImmutableKit; -import graphql.collect.ImmutableMapWithNullValues; import graphql.execution.instrumentation.Instrumentation; import graphql.execution.instrumentation.InstrumentationState; import graphql.language.Document; @@ -43,7 +42,7 @@ public class ExecutionContext { private final ImmutableMap fragmentsByName; private final OperationDefinition operationDefinition; private final Document document; - private final ImmutableMapWithNullValues variables; + private final CoercedVariables coercedVariables; private final Object root; private final Object context; private final GraphQLContext graphQLContext; @@ -66,7 +65,7 @@ public class ExecutionContext { this.mutationStrategy = builder.mutationStrategy; this.subscriptionStrategy = builder.subscriptionStrategy; this.fragmentsByName = builder.fragmentsByName; - this.variables = ImmutableMapWithNullValues.copyOf(builder.variables); + this.coercedVariables = builder.coercedVariables; this.document = builder.document; this.operationDefinition = builder.operationDefinition; this.context = builder.context; @@ -80,7 +79,7 @@ public class ExecutionContext { this.errors.set(builder.errors); this.localContext = builder.localContext; this.executionInput = builder.executionInput; - queryTree = FpKit.interThreadMemoize(() -> ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(graphQLSchema, operationDefinition, fragmentsByName, variables)); + queryTree = FpKit.interThreadMemoize(() -> ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(graphQLSchema, operationDefinition, fragmentsByName, coercedVariables)); } @@ -116,8 +115,16 @@ public OperationDefinition getOperationDefinition() { return operationDefinition; } + /** + * @deprecated use {@link #getCoercedVariables()} instead + */ + @Deprecated public Map getVariables() { - return variables; + return coercedVariables.toMap(); + } + + public CoercedVariables getCoercedVariables() { + return coercedVariables; } /** diff --git a/src/main/java/graphql/execution/ExecutionContextBuilder.java b/src/main/java/graphql/execution/ExecutionContextBuilder.java index 1affeabf0c..4f5dac8ac8 100644 --- a/src/main/java/graphql/execution/ExecutionContextBuilder.java +++ b/src/main/java/graphql/execution/ExecutionContextBuilder.java @@ -9,7 +9,6 @@ import graphql.PublicApi; import graphql.cachecontrol.CacheControl; import graphql.collect.ImmutableKit; -import graphql.collect.ImmutableMapWithNullValues; import graphql.execution.instrumentation.Instrumentation; import graphql.execution.instrumentation.InstrumentationState; import graphql.language.Document; @@ -39,7 +38,7 @@ public class ExecutionContextBuilder { Object root; Document document; OperationDefinition operationDefinition; - ImmutableMapWithNullValues variables = ImmutableMapWithNullValues.emptyMap(); + CoercedVariables coercedVariables = CoercedVariables.emptyVariables(); ImmutableMap fragmentsByName = ImmutableKit.emptyMap(); DataLoaderRegistry dataLoaderRegistry; CacheControl cacheControl; @@ -86,7 +85,7 @@ public ExecutionContextBuilder() { root = other.getRoot(); document = other.getDocument(); operationDefinition = other.getOperationDefinition(); - variables = ImmutableMapWithNullValues.copyOf(other.getVariables()); + coercedVariables = other.getCoercedVariables(); fragmentsByName = ImmutableMap.copyOf(other.getFragmentsByName()); dataLoaderRegistry = other.getDataLoaderRegistry(); cacheControl = other.getCacheControl(); @@ -151,8 +150,17 @@ public ExecutionContextBuilder root(Object root) { return this; } + /** + * @deprecated use {@link #coercedVariables(CoercedVariables)} instead + */ + @Deprecated public ExecutionContextBuilder variables(Map variables) { - this.variables = ImmutableMapWithNullValues.copyOf(variables); + this.coercedVariables = new CoercedVariables(variables); + return this; + } + + public ExecutionContextBuilder coercedVariables(CoercedVariables coercedVariables) { + this.coercedVariables = coercedVariables; return this; } diff --git a/src/main/java/graphql/execution/ExecutionStepInfoFactory.java b/src/main/java/graphql/execution/ExecutionStepInfoFactory.java index 31a2df65dd..57b8044a79 100644 --- a/src/main/java/graphql/execution/ExecutionStepInfoFactory.java +++ b/src/main/java/graphql/execution/ExecutionStepInfoFactory.java @@ -27,7 +27,7 @@ public ExecutionStepInfo newExecutionStepInfoForSubField(ExecutionContext execut GraphQLOutputType fieldType = fieldDefinition.getType(); List fieldArgs = mergedField.getArguments(); GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry(); - Supplier> argumentValues = FpKit.intraThreadMemoize(() -> valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), fieldArgs, executionContext.getVariables())); + Supplier> argumentValues = FpKit.intraThreadMemoize(() -> valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), fieldArgs, executionContext.getCoercedVariables())); ResultPath newPath = parentInfo.getPath().segment(mergedField.getResultKey()); diff --git a/src/main/java/graphql/execution/ExecutionStrategy.java b/src/main/java/graphql/execution/ExecutionStrategy.java index 5f5467292d..48f77e5964 100644 --- a/src/main/java/graphql/execution/ExecutionStrategy.java +++ b/src/main/java/graphql/execution/ExecutionStrategy.java @@ -817,7 +817,7 @@ protected ExecutionStepInfo createExecutionStepInfo(ExecutionContext executionCo if (!fieldArgDefs.isEmpty()) { List fieldArgs = field.getArguments(); GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry(); - argumentValues = FpKit.intraThreadMemoize(() -> valuesResolver.getArgumentValues(codeRegistry, fieldArgDefs, fieldArgs, executionContext.getVariables())); + argumentValues = FpKit.intraThreadMemoize(() -> valuesResolver.getArgumentValues(codeRegistry, fieldArgDefs, fieldArgs, executionContext.getCoercedVariables())); } diff --git a/src/main/java/graphql/execution/RawVariables.java b/src/main/java/graphql/execution/RawVariables.java new file mode 100644 index 0000000000..fca5d1014d --- /dev/null +++ b/src/main/java/graphql/execution/RawVariables.java @@ -0,0 +1,35 @@ +package graphql.execution; + +import graphql.Internal; +import graphql.collect.ImmutableKit; +import graphql.collect.ImmutableMapWithNullValues; + +import java.util.Map; + +/** + * Holds raw variables, which not have been coerced yet + */ +@Internal +public class RawVariables { + private final ImmutableMapWithNullValues rawVariables; + + public RawVariables(Map rawVariables) { + this.rawVariables = ImmutableMapWithNullValues.copyOf(rawVariables); + } + + public Map toMap() { + return rawVariables; + } + + public boolean containsKey(String key) { + return rawVariables.containsKey(key); + } + + public Object get(String key) { + return rawVariables.get(key); + } + + public static RawVariables emptyVariables() { + return new RawVariables(ImmutableKit.emptyMap()); + } +} diff --git a/src/main/java/graphql/execution/ValuesResolver.java b/src/main/java/graphql/execution/ValuesResolver.java index 23c51a5525..fc601ed55f 100644 --- a/src/main/java/graphql/execution/ValuesResolver.java +++ b/src/main/java/graphql/execution/ValuesResolver.java @@ -87,9 +87,9 @@ public enum ValueMode { * * @return coerced variable values as a map */ - public Map coerceVariableValues(GraphQLSchema schema, - List variableDefinitions, - Map rawVariables) throws CoercingParseValueException, NonNullableValueCoercedAsNullException { + public CoercedVariables coerceVariableValues(GraphQLSchema schema, + List variableDefinitions, + RawVariables rawVariables) throws CoercingParseValueException, NonNullableValueCoercedAsNullException { return externalValueToInternalValueForVariables(schema, variableDefinitions, rawVariables); } @@ -105,7 +105,7 @@ public Map coerceVariableValues(GraphQLSchema schema, */ public Map getNormalizedVariableValues(GraphQLSchema schema, List variableDefinitions, - Map rawVariables) { + RawVariables rawVariables) { GraphqlFieldVisibility fieldVisibility = schema.getCodeRegistry().getFieldVisibility(); Map result = new LinkedHashMap<>(); for (VariableDefinition variableDefinition : variableDefinitions) { @@ -145,7 +145,7 @@ public Map getNormalizedVariableValues(GraphQLSche */ public Map getArgumentValues(List argumentTypes, List arguments, - Map coercedVariables) { + CoercedVariables coercedVariables) { return getArgumentValuesImpl(DEFAULT_FIELD_VISIBILITY, argumentTypes, arguments, coercedVariables); } @@ -189,7 +189,7 @@ public Map getNormalizedArgumentValues(List getArgumentValues(GraphQLCodeRegistry codeRegistry, List argumentTypes, List arguments, - Map coercedVariables) { + CoercedVariables coercedVariables) { return getArgumentValuesImpl(codeRegistry.getFieldVisibility(), argumentTypes, arguments, coercedVariables); } @@ -248,7 +248,7 @@ public static Object valueToInternalValue(InputValueWithState inputValueWithStat return inputValueWithState.getValue(); } if (inputValueWithState.isLiteral()) { - return new ValuesResolver().literalToInternalValue(fieldVisibility, type, (Value) inputValueWithState.getValue(), emptyMap()); + return new ValuesResolver().literalToInternalValue(fieldVisibility, type, (Value) inputValueWithState.getValue(), new CoercedVariables(emptyMap())); } if (inputValueWithState.isExternal()) { return new ValuesResolver().externalValueToInternalValue(fieldVisibility, type, inputValueWithState.getValue()); @@ -316,9 +316,7 @@ private Object externalValueToLiteralForList(GraphqlFieldVisibility fieldVisibil GraphQLInputType wrappedType = (GraphQLInputType) listType.getWrappedType(); List result = FpKit.toListOrSingletonList(value) .stream() - .map(val -> { - return externalValueToLiteral(fieldVisibility, val, wrappedType, valueMode); - }) + .map(val -> externalValueToLiteral(fieldVisibility, val, wrappedType, valueMode)) .collect(toList()); if (valueMode == NORMALIZED) { return result; @@ -384,9 +382,9 @@ private Object externalValueToLiteralForObject(GraphqlFieldVisibility fieldVisib /** * performs validation too */ - private Map externalValueToInternalValueForVariables(GraphQLSchema schema, - List variableDefinitions, - Map rawVariables) { + private CoercedVariables externalValueToInternalValueForVariables(GraphQLSchema schema, + List variableDefinitions, + RawVariables rawVariables) { GraphqlFieldVisibility fieldVisibility = schema.getCodeRegistry().getFieldVisibility(); Map coercedValues = new LinkedHashMap<>(); for (VariableDefinition variableDefinition : variableDefinitions) { @@ -399,7 +397,7 @@ private Map externalValueToInternalValueForVariables(GraphQLSche boolean hasValue = rawVariables.containsKey(variableName); Object value = rawVariables.get(variableName); if (!hasValue && defaultValue != null) { - Object coercedDefaultValue = literalToInternalValue(fieldVisibility, variableType, defaultValue, Collections.emptyMap()); + Object coercedDefaultValue = literalToInternalValue(fieldVisibility, variableType, defaultValue, CoercedVariables.emptyVariables()); coercedValues.put(variableName, coercedDefaultValue); } else if (isNonNull(variableType) && (!hasValue || value == null)) { throw new NonNullableValueCoercedAsNullException(variableDefinition, variableType); @@ -423,15 +421,14 @@ private Map externalValueToInternalValueForVariables(GraphQLSche } } - return coercedValues; + return new CoercedVariables(coercedValues); } private Map getArgumentValuesImpl(GraphqlFieldVisibility fieldVisibility, List argumentTypes, List arguments, - Map coercedVariables - ) { + CoercedVariables coercedVariables) { if (argumentTypes.isEmpty()) { return Collections.emptyMap(); } @@ -474,7 +471,6 @@ private Map getArgumentValuesImpl(GraphqlFieldVisibility fieldVi } return coercedValues; - } private Map argumentMap(List arguments) { @@ -679,11 +675,10 @@ private List literalToNormalizedValueForList(GraphqlFieldVisibility fiel public Object literalToInternalValue(GraphqlFieldVisibility fieldVisibility, GraphQLType type, Value inputValue, - Map coercedVariables) { + CoercedVariables coercedVariables) { if (inputValue instanceof VariableReference) { - Object variableValue = coercedVariables.get(((VariableReference) inputValue).getName()); - return variableValue; + return coercedVariables.get(((VariableReference) inputValue).getName()); } if (inputValue instanceof NullValue) { return null; @@ -709,9 +704,9 @@ public Object literalToInternalValue(GraphqlFieldVisibility fieldVisibility, /** * no validation */ - private Object literalToInternalValueForScalar(Value inputValue, GraphQLScalarType scalarType, Map variables) { + private Object literalToInternalValueForScalar(Value inputValue, GraphQLScalarType scalarType, CoercedVariables coercedVariables) { // the CoercingParseLiteralException exception that could happen here has been validated earlier via ValidationUtil - return scalarType.getCoercing().parseLiteral(inputValue, variables); + return scalarType.getCoercing().parseLiteral(inputValue, coercedVariables.toMap()); } /** @@ -720,7 +715,7 @@ private Object literalToInternalValueForScalar(Value inputValue, GraphQLScalarTy private Object literalToInternalValueForList(GraphqlFieldVisibility fieldVisibility, GraphQLList graphQLList, Value value, - Map coercedVariables) { + CoercedVariables coercedVariables) { if (value instanceof ArrayValue) { ArrayValue arrayValue = (ArrayValue) value; @@ -744,7 +739,7 @@ private Object literalToInternalValueForList(GraphqlFieldVisibility fieldVisibil private Object literalToInternalValueForInputObject(GraphqlFieldVisibility fieldVisibility, GraphQLInputObjectType type, ObjectValue inputValue, - Map coercedVariables) { + CoercedVariables coercedVariables) { Map coercedValues = new LinkedHashMap<>(); Map inputFieldsByName = mapObjectValueFieldsByName(inputValue); @@ -813,7 +808,7 @@ private Object defaultValueToInternalValue(GraphqlFieldVisibility fieldVisibilit } if (defaultValue.isLiteral()) { // default value literals can't reference variables, this is why the variables are empty - return literalToInternalValue(fieldVisibility, type, (Value) defaultValue.getValue(), Collections.emptyMap()); + return literalToInternalValue(fieldVisibility, type, (Value) defaultValue.getValue(), CoercedVariables.emptyVariables()); } if (defaultValue.isExternal()) { // performs validation too diff --git a/src/main/java/graphql/execution/directives/DirectivesResolver.java b/src/main/java/graphql/execution/directives/DirectivesResolver.java index 40295d756c..13b518b1a1 100644 --- a/src/main/java/graphql/execution/directives/DirectivesResolver.java +++ b/src/main/java/graphql/execution/directives/DirectivesResolver.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; import graphql.Internal; +import graphql.execution.CoercedVariables; import graphql.execution.ValuesResolver; import graphql.language.Directive; import graphql.schema.GraphQLArgument; @@ -38,7 +39,7 @@ public Map resolveDirectives(List directive } private void buildArguments(GraphQLDirective.Builder directiveBuilder, GraphQLCodeRegistry codeRegistry, GraphQLDirective protoType, Directive fieldDirective, Map variables) { - Map argumentValues = valuesResolver.getArgumentValues(codeRegistry, protoType.getArguments(), fieldDirective.getArguments(), variables); + Map argumentValues = valuesResolver.getArgumentValues(codeRegistry, protoType.getArguments(), fieldDirective.getArguments(), new CoercedVariables(variables)); directiveBuilder.clearArguments(); protoType.getArguments().forEach(protoArg -> { if (argumentValues.containsKey(protoArg.getName())) { diff --git a/src/main/java/graphql/execution/nextgen/ExecutionHelper.java b/src/main/java/graphql/execution/nextgen/ExecutionHelper.java index ac3453dda9..5d26e1b65e 100644 --- a/src/main/java/graphql/execution/nextgen/ExecutionHelper.java +++ b/src/main/java/graphql/execution/nextgen/ExecutionHelper.java @@ -2,12 +2,14 @@ import graphql.ExecutionInput; import graphql.Internal; +import graphql.execution.CoercedVariables; import graphql.execution.ExecutionContext; import graphql.execution.ExecutionId; import graphql.execution.ExecutionStepInfo; import graphql.execution.FieldCollector; import graphql.execution.FieldCollectorParameters; import graphql.execution.MergedSelectionSet; +import graphql.execution.RawVariables; import graphql.execution.ResultPath; import graphql.execution.ValuesResolver; import graphql.execution.instrumentation.InstrumentationState; @@ -49,11 +51,10 @@ public ExecutionData createExecutionData(Document document, OperationDefinition operationDefinition = getOperationResult.operationDefinition; ValuesResolver valuesResolver = new ValuesResolver(); - Map inputVariables = executionInput.getVariables(); + RawVariables inputVariables = executionInput.getRawVariables(); List variableDefinitions = operationDefinition.getVariableDefinitions(); - Map coercedVariables; - coercedVariables = valuesResolver.coerceVariableValues(graphQLSchema, variableDefinitions, inputVariables); + CoercedVariables coercedVariables = valuesResolver.coerceVariableValues(graphQLSchema, variableDefinitions, inputVariables); ExecutionContext executionContext = newExecutionContextBuilder() .executionId(executionId) @@ -63,7 +64,7 @@ public ExecutionData createExecutionData(Document document, .graphQLContext(executionInput.getGraphQLContext()) .root(executionInput.getRoot()) .fragmentsByName(fragmentsByName) - .variables(coercedVariables) + .coercedVariables(coercedVariables) .document(document) .operationDefinition(operationDefinition) .build(); @@ -71,7 +72,6 @@ public ExecutionData createExecutionData(Document document, ExecutionData executionData = new ExecutionData(); executionData.executionContext = executionContext; return executionData; - } public FieldSubSelection getFieldSubSelection(ExecutionContext executionContext) { @@ -95,6 +95,5 @@ public FieldSubSelection getFieldSubSelection(ExecutionContext executionContext) .executionInfo(executionInfo) .build(); return fieldSubSelection; - } } diff --git a/src/main/java/graphql/execution/nextgen/ValueFetcher.java b/src/main/java/graphql/execution/nextgen/ValueFetcher.java index f808062e37..65c38a54c6 100644 --- a/src/main/java/graphql/execution/nextgen/ValueFetcher.java +++ b/src/main/java/graphql/execution/nextgen/ValueFetcher.java @@ -123,7 +123,7 @@ public CompletableFuture fetchValue(ExecutionContext executionCont GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry(); GraphQLFieldsContainer parentType = getFieldsContainer(executionInfo); - Supplier> argumentValues = FpKit.intraThreadMemoize(() -> valuesResolver.getArgumentValues(codeRegistry, fieldDef.getArguments(), field.getArguments(), executionContext.getVariables())); + Supplier> argumentValues = FpKit.intraThreadMemoize(() -> valuesResolver.getArgumentValues(codeRegistry, fieldDef.getArguments(), field.getArguments(), executionContext.getCoercedVariables())); QueryDirectivesImpl queryDirectives = new QueryDirectivesImpl(sameFields, executionContext.getGraphQLSchema(), executionContext.getVariables()); diff --git a/src/main/java/graphql/normalized/ExecutableNormalizedOperationFactory.java b/src/main/java/graphql/normalized/ExecutableNormalizedOperationFactory.java index b9d679a689..502c503238 100644 --- a/src/main/java/graphql/normalized/ExecutableNormalizedOperationFactory.java +++ b/src/main/java/graphql/normalized/ExecutableNormalizedOperationFactory.java @@ -6,8 +6,10 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import graphql.Internal; +import graphql.execution.CoercedVariables; import graphql.execution.ConditionalNodes; import graphql.execution.MergedField; +import graphql.execution.RawVariables; import graphql.execution.ValuesResolver; import graphql.execution.nextgen.Common; import graphql.introspection.Introspection; @@ -61,23 +63,22 @@ public class ExecutableNormalizedOperationFactory { public static ExecutableNormalizedOperation createExecutableNormalizedOperation(GraphQLSchema graphQLSchema, Document document, String operationName, - Map coercedVariableValues) { + CoercedVariables coercedVariableValues) { NodeUtil.GetOperationResult getOperationResult = NodeUtil.getOperation(document, operationName); return new ExecutableNormalizedOperationFactory().createNormalizedQueryImpl(graphQLSchema, getOperationResult.operationDefinition, getOperationResult.fragmentsByName, coercedVariableValues, null); } - public static ExecutableNormalizedOperation createExecutableNormalizedOperation(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition, Map fragments, - Map coercedVariableValues) { + CoercedVariables coercedVariableValues) { return new ExecutableNormalizedOperationFactory().createNormalizedQueryImpl(graphQLSchema, operationDefinition, fragments, coercedVariableValues, null); } public static ExecutableNormalizedOperation createExecutableNormalizedOperationWithRawVariables(GraphQLSchema graphQLSchema, Document document, String operationName, - Map rawVariables) { + RawVariables rawVariables) { NodeUtil.GetOperationResult getOperationResult = NodeUtil.getOperation(document, operationName); return new ExecutableNormalizedOperationFactory().createExecutableNormalizedOperationImplWithRawVariables(graphQLSchema, getOperationResult.operationDefinition, getOperationResult.fragmentsByName, rawVariables); } @@ -85,13 +86,13 @@ public static ExecutableNormalizedOperation createExecutableNormalizedOperationW private ExecutableNormalizedOperation createExecutableNormalizedOperationImplWithRawVariables(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition, Map fragments, - Map rawVariables + RawVariables rawVariables ) { List variableDefinitions = operationDefinition.getVariableDefinitions(); - Map coerceVariableValues = valuesResolver.coerceVariableValues(graphQLSchema, variableDefinitions, rawVariables); + CoercedVariables coercedVariableValues = valuesResolver.coerceVariableValues(graphQLSchema, variableDefinitions, rawVariables); Map normalizedVariableValues = valuesResolver.getNormalizedVariableValues(graphQLSchema, variableDefinitions, rawVariables); - return createNormalizedQueryImpl(graphQLSchema, operationDefinition, fragments, coerceVariableValues, normalizedVariableValues); + return createNormalizedQueryImpl(graphQLSchema, operationDefinition, fragments, coercedVariableValues, normalizedVariableValues); } /** @@ -100,13 +101,13 @@ private ExecutableNormalizedOperation createExecutableNormalizedOperationImplWit private ExecutableNormalizedOperation createNormalizedQueryImpl(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition, Map fragments, - Map coercedVariableValues, + CoercedVariables coercedVariableValues, @Nullable Map normalizedVariableValues) { FieldCollectorNormalizedQueryParams parameters = FieldCollectorNormalizedQueryParams .newParameters() .fragments(fragments) .schema(graphQLSchema) - .coercedVariables(coercedVariableValues) + .coercedVariables(coercedVariableValues.toMap()) .normalizedVariables(normalizedVariableValues) .build(); @@ -305,7 +306,7 @@ private ExecutableNormalizedField createNF(FieldCollectorNormalizedQueryParams p String fieldName = field.getName(); GraphQLFieldDefinition fieldDefinition = Introspection.getFieldDef(parameters.getGraphQLSchema(), objectTypes.iterator().next(), fieldName); - Map argumentValues = valuesResolver.getArgumentValues(fieldDefinition.getArguments(), field.getArguments(), parameters.getCoercedVariableValues()); + Map argumentValues = valuesResolver.getArgumentValues(fieldDefinition.getArguments(), field.getArguments(), new CoercedVariables(parameters.getCoercedVariableValues())); Map normalizedArgumentValues = null; if (parameters.getNormalizedVariableValues() != null) { normalizedArgumentValues = valuesResolver.getNormalizedArgumentValues(fieldDefinition.getArguments(), field.getArguments(), parameters.getNormalizedVariableValues()); diff --git a/src/test/groovy/graphql/ExecutionInputTest.groovy b/src/test/groovy/graphql/ExecutionInputTest.groovy index 423fb8994e..9ab6a8930a 100644 --- a/src/test/groovy/graphql/ExecutionInputTest.groovy +++ b/src/test/groovy/graphql/ExecutionInputTest.groovy @@ -2,6 +2,7 @@ package graphql import graphql.cachecontrol.CacheControl import graphql.execution.ExecutionId +import graphql.execution.RawVariables import graphql.schema.DataFetcher import graphql.schema.DataFetchingEnvironment import org.dataloader.DataLoaderRegistry @@ -35,6 +36,7 @@ class ExecutionInputTest extends Specification { executionInput.graphQLContext.get("a") == "b" executionInput.root == root executionInput.variables == variables + executionInput.rawVariables.toMap() == variables executionInput.dataLoaderRegistry == registry executionInput.cacheControl == cacheControl executionInput.query == query @@ -111,6 +113,32 @@ class ExecutionInputTest extends Specification { executionInput.query == "new query" } + def "transform works and sets variables"() { + when: + def executionInputOld = ExecutionInput.newExecutionInput().query(query) + .dataLoaderRegistry(registry) + .cacheControl(cacheControl) + .extensions([some: "map"]) + .root(root) + .graphQLContext({ it.of(["a": "b"]) }) + .locale(Locale.GERMAN) + .build() + def graphQLContext = executionInputOld.getGraphQLContext() + def executionInput = executionInputOld.transform({ bldg -> bldg + .query("new query") + .variables(variables) }) + + then: + executionInput.graphQLContext == graphQLContext + executionInput.root == root + executionInput.rawVariables.toMap() == variables + executionInput.dataLoaderRegistry == registry + executionInput.cacheControl == cacheControl + executionInput.locale == Locale.GERMAN + executionInput.extensions == [some: "map"] + executionInput.query == "new query" + } + def "defaults query into builder as expected"() { when: def executionInput = ExecutionInput.newExecutionInput("{ q }").build() diff --git a/src/test/groovy/graphql/GraphQLTest.groovy b/src/test/groovy/graphql/GraphQLTest.groovy index 33c5f78868..caa4fe9d10 100644 --- a/src/test/groovy/graphql/GraphQLTest.groovy +++ b/src/test/groovy/graphql/GraphQLTest.groovy @@ -973,8 +973,6 @@ many lines'''] then: def assEx = thrown(AssertException) assEx.message.contains("variables map can't be null") - - } def "query can't be null via ExecutionInput"() { @@ -986,8 +984,6 @@ many lines'''] then: def assEx = thrown(AssertException) assEx.message.contains("query can't be null") - - } def "query must be set via ExecutionInput"() { diff --git a/src/test/groovy/graphql/execution/ConditionalNodesTest.groovy b/src/test/groovy/graphql/execution/ConditionalNodesTest.groovy index 55ea94e844..7c76600727 100644 --- a/src/test/groovy/graphql/execution/ConditionalNodesTest.groovy +++ b/src/test/groovy/graphql/execution/ConditionalNodesTest.groovy @@ -1,6 +1,6 @@ package graphql.execution -import graphql.Directives + import graphql.language.Argument import graphql.language.BooleanValue import graphql.language.Directive @@ -8,18 +8,14 @@ import spock.lang.Specification class ConditionalNodesTest extends Specification { - def "should include false for skip = true"() { given: def variables = new LinkedHashMap() ConditionalNodes conditionalNodes = new ConditionalNodes() - conditionalNodes.valuesResolver = Mock(ValuesResolver) def argument = Argument.newArgument("if", new BooleanValue(true)).build() def directives = [Directive.newDirective().name("skip").arguments([argument]).build()] - conditionalNodes.valuesResolver.getArgumentValues(Directives.SkipDirective.getArguments(), [argument], variables) >> ["if": true] - expect: !conditionalNodes.shouldInclude(variables, directives) } @@ -31,6 +27,5 @@ class ConditionalNodesTest extends Specification { expect: conditionalNodes.shouldInclude(variables, []) - } } diff --git a/src/test/groovy/graphql/execution/ExecutionContextBuilderTest.groovy b/src/test/groovy/graphql/execution/ExecutionContextBuilderTest.groovy index 762a85a343..747160bd2d 100644 --- a/src/test/groovy/graphql/execution/ExecutionContextBuilderTest.groovy +++ b/src/test/groovy/graphql/execution/ExecutionContextBuilderTest.groovy @@ -13,58 +13,204 @@ import spock.lang.Specification class ExecutionContextBuilderTest extends Specification { + Instrumentation instrumentation = Mock(Instrumentation) + ExecutionStrategy queryStrategy = Mock(ExecutionStrategy) + ExecutionStrategy mutationStrategy = Mock(ExecutionStrategy) + ExecutionStrategy subscriptionStrategy = Mock(ExecutionStrategy) + GraphQLSchema schema = Mock(GraphQLSchema) + def executionId = ExecutionId.generate() + def context = "context" + def graphQLContext = GraphQLContext.newContext().build() + def root = "root" + Document document = new Parser().parseDocument("query myQuery(\$var: String){...MyFragment} fragment MyFragment on Query{foo}") + def operation = document.definitions[0] as OperationDefinition + def fragment = document.definitions[1] as FragmentDefinition + def dataLoaderRegistry = new DataLoaderRegistry() + def cacheControl = CacheControl.newCacheControl() def "builds the correct ExecutionContext"() { - given: - ExecutionContextBuilder executionContextBuilder = new ExecutionContextBuilder() - - Instrumentation instrumentation = Mock(Instrumentation) - executionContextBuilder.instrumentation(instrumentation) - - ExecutionStrategy queryStrategy = Mock(ExecutionStrategy) - executionContextBuilder.queryStrategy(queryStrategy) - - ExecutionStrategy mutationStrategy = Mock(ExecutionStrategy) - executionContextBuilder.mutationStrategy(mutationStrategy) - - ExecutionStrategy subscriptionStrategy = Mock(ExecutionStrategy) - executionContextBuilder.subscriptionStrategy(subscriptionStrategy) + when: + def executionContext = new ExecutionContextBuilder() + .instrumentation(instrumentation) + .queryStrategy(queryStrategy) + .mutationStrategy(mutationStrategy) + .subscriptionStrategy(subscriptionStrategy) + .graphQLSchema(schema) + .executionId(executionId) + .context(context) + .graphQLContext(graphQLContext) + .root(root) + .operationDefinition(operation) + .fragmentsByName([MyFragment: fragment]) + .variables([var: 'value']) + .dataLoaderRegistry(dataLoaderRegistry) + .cacheControl(cacheControl) + .build() - GraphQLSchema schema = Mock(GraphQLSchema) - executionContextBuilder.graphQLSchema(schema) + then: + executionContext.executionId == executionId + executionContext.instrumentation == instrumentation + executionContext.graphQLSchema == schema + executionContext.queryStrategy == queryStrategy + executionContext.mutationStrategy == mutationStrategy + executionContext.subscriptionStrategy == subscriptionStrategy + executionContext.root == root + executionContext.context == context + executionContext.graphQLContext == graphQLContext + executionContext.variables == [var: 'value'] + executionContext.getFragmentsByName() == [MyFragment: fragment] + executionContext.operationDefinition == operation + executionContext.dataLoaderRegistry == dataLoaderRegistry + executionContext.cacheControl == cacheControl + } - def executionId = ExecutionId.generate() - executionContextBuilder.executionId(executionId) + def "builds the correct ExecutionContext with coerced variables"() { + given: + def coercedVariables = new CoercedVariables([var: 'value']) - def context = "context" - executionContextBuilder.context(context) + when: + def executionContext = new ExecutionContextBuilder() + .instrumentation(instrumentation) + .queryStrategy(queryStrategy) + .mutationStrategy(mutationStrategy) + .subscriptionStrategy(subscriptionStrategy) + .graphQLSchema(schema) + .executionId(executionId) + .context(context) + .graphQLContext(graphQLContext) + .root(root) + .operationDefinition(operation) + .fragmentsByName([MyFragment: fragment]) + .coercedVariables(coercedVariables) + .dataLoaderRegistry(dataLoaderRegistry) + .cacheControl(cacheControl) + .build() - def graphQLContext = GraphQLContext.newContext().build() - executionContextBuilder.graphQLContext(graphQLContext) + then: + executionContext.executionId == executionId + executionContext.instrumentation == instrumentation + executionContext.graphQLSchema == schema + executionContext.queryStrategy == queryStrategy + executionContext.mutationStrategy == mutationStrategy + executionContext.subscriptionStrategy == subscriptionStrategy + executionContext.root == root + executionContext.context == context + executionContext.graphQLContext == graphQLContext + executionContext.coercedVariables == coercedVariables + executionContext.getFragmentsByName() == [MyFragment: fragment] + executionContext.operationDefinition == operation + executionContext.dataLoaderRegistry == dataLoaderRegistry + executionContext.cacheControl == cacheControl + } - def root = "root" - executionContextBuilder.root(root) + def "builds the correct ExecutionContext, if both variables and coercedVariables are set, latest value set takes precedence"() { + given: + def coercedVariables = new CoercedVariables([var: 'value']) - Document document = new Parser().parseDocument("query myQuery(\$var: String){...MyFragment} fragment MyFragment on Query{foo}") - def operation = document.definitions[0] as OperationDefinition - def fragment = document.definitions[1] as FragmentDefinition - executionContextBuilder.operationDefinition(operation) + when: + def executionContext = new ExecutionContextBuilder() + .instrumentation(instrumentation) + .queryStrategy(queryStrategy) + .mutationStrategy(mutationStrategy) + .subscriptionStrategy(subscriptionStrategy) + .graphQLSchema(schema) + .executionId(executionId) + .context(context) + .graphQLContext(graphQLContext) + .root(root) + .operationDefinition(operation) + .fragmentsByName([MyFragment: fragment]) + .variables([var: 'value']) + .coercedVariables(coercedVariables) + .dataLoaderRegistry(dataLoaderRegistry) + .cacheControl(cacheControl) + .build() - executionContextBuilder.fragmentsByName([MyFragment: fragment]) + then: + executionContext.executionId == executionId + executionContext.instrumentation == instrumentation + executionContext.graphQLSchema == schema + executionContext.queryStrategy == queryStrategy + executionContext.mutationStrategy == mutationStrategy + executionContext.subscriptionStrategy == subscriptionStrategy + executionContext.root == root + executionContext.context == context + executionContext.graphQLContext == graphQLContext + executionContext.coercedVariables == coercedVariables + executionContext.getFragmentsByName() == [MyFragment: fragment] + executionContext.operationDefinition == operation + executionContext.dataLoaderRegistry == dataLoaderRegistry + executionContext.cacheControl == cacheControl + } - def variables = Collections.emptyMap() - executionContextBuilder.variables(variables) + def "transform works and copies values with coerced variables"() { + given: + def oldCoercedVariables = CoercedVariables.emptyVariables() + def executionContextOld = new ExecutionContextBuilder() + .instrumentation(instrumentation) + .queryStrategy(queryStrategy) + .mutationStrategy(mutationStrategy) + .subscriptionStrategy(subscriptionStrategy) + .graphQLSchema(schema) + .executionId(executionId) + .context(context) + .graphQLContext(graphQLContext) + .root(root) + .operationDefinition(operation) + .coercedVariables(oldCoercedVariables) + .fragmentsByName([MyFragment: fragment]) + .dataLoaderRegistry(dataLoaderRegistry) + .cacheControl(cacheControl) + .build() - executionContextBuilder.variables([var: 'value']) + when: + def coercedVariables = new CoercedVariables([var: 'value']) + def executionContext = executionContextOld.transform(builder -> builder + .coercedVariables(coercedVariables)) - def dataLoaderRegistry = new DataLoaderRegistry() - executionContextBuilder.dataLoaderRegistry(dataLoaderRegistry) + then: + executionContext.executionId == executionId + executionContext.instrumentation == instrumentation + executionContext.graphQLSchema == schema + executionContext.queryStrategy == queryStrategy + executionContext.mutationStrategy == mutationStrategy + executionContext.subscriptionStrategy == subscriptionStrategy + executionContext.root == root + executionContext.context == context + executionContext.graphQLContext == graphQLContext + executionContext.coercedVariables == coercedVariables + executionContext.getFragmentsByName() == [MyFragment: fragment] + executionContext.operationDefinition == operation + executionContext.dataLoaderRegistry == dataLoaderRegistry + executionContext.cacheControl == cacheControl + } - def cacheControl = CacheControl.newCacheControl() - executionContextBuilder.cacheControl(cacheControl) + def "transform copies values, if both variables and coercedVariables set, latest value set takes precedence"() { + given: + def oldCoercedVariables = CoercedVariables.emptyVariables() + def executionContextOld = new ExecutionContextBuilder() + .instrumentation(instrumentation) + .queryStrategy(queryStrategy) + .mutationStrategy(mutationStrategy) + .subscriptionStrategy(subscriptionStrategy) + .graphQLSchema(schema) + .executionId(executionId) + .context(context) + .graphQLContext(graphQLContext) + .root(root) + .operationDefinition(operation) + .variables([:]) + .coercedVariables(oldCoercedVariables) + .fragmentsByName([MyFragment: fragment]) + .dataLoaderRegistry(dataLoaderRegistry) + .cacheControl(cacheControl) + .build() when: - def executionContext = executionContextBuilder.build() + def coercedVariables = new CoercedVariables([var: 'value']) + def executionContext = executionContextOld.transform(builder -> builder + .variables([var: 'value']) + .coercedVariables(coercedVariables)) then: executionContext.executionId == executionId @@ -76,7 +222,7 @@ class ExecutionContextBuilderTest extends Specification { executionContext.root == root executionContext.context == context executionContext.graphQLContext == graphQLContext - executionContext.variables == [var: 'value'] + executionContext.coercedVariables == coercedVariables executionContext.getFragmentsByName() == [MyFragment: fragment] executionContext.operationDefinition == operation executionContext.dataLoaderRegistry == dataLoaderRegistry diff --git a/src/test/groovy/graphql/execution/ExecutionTest.groovy b/src/test/groovy/graphql/execution/ExecutionTest.groovy index b4af50a5b2..c2539ef6c6 100644 --- a/src/test/groovy/graphql/execution/ExecutionTest.groovy +++ b/src/test/groovy/graphql/execution/ExecutionTest.groovy @@ -99,7 +99,7 @@ class ExecutionTest extends Specification { subscriptionStrategy.execute == 1 } - def "Update query strategy when instrumenting exection context" (){ + def "Update query strategy when instrumenting execution context" (){ given: def query = ''' query { @@ -114,12 +114,12 @@ class ExecutionTest extends Specification { def instrumentation = new SimpleInstrumentation() { @Override - public ExecutionContext instrumentExecutionContext(ExecutionContext executionContext, - InstrumentationExecutionParameters parameters) { + ExecutionContext instrumentExecutionContext(ExecutionContext executionContext, + InstrumentationExecutionParameters parameters) { return ExecutionContextBuilder.newExecutionContextBuilder(executionContext) .queryStrategy(queryStrategyUpdatedToDuringExecutionContextInstrument) - .build(); + .build() } } diff --git a/src/test/groovy/graphql/execution/ValuesResolverTest.groovy b/src/test/groovy/graphql/execution/ValuesResolverTest.groovy index 783fb1cdc1..570e88741d 100644 --- a/src/test/groovy/graphql/execution/ValuesResolverTest.groovy +++ b/src/test/groovy/graphql/execution/ValuesResolverTest.groovy @@ -39,16 +39,15 @@ class ValuesResolverTest extends Specification { ValuesResolver resolver = new ValuesResolver() - @Unroll def "getVariableValues: simple variable input #inputValue"() { given: def schema = TestUtil.schemaWithInputType(inputType) VariableDefinition variableDefinition = new VariableDefinition("variable", variableType, null) when: - def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], [variable: inputValue]) + def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: inputValue])) then: - resolvedValues['variable'] == outputValue + resolvedValues.get('variable') == outputValue where: inputType | variableType | inputValue || outputValue @@ -56,7 +55,6 @@ class ValuesResolverTest extends Specification { GraphQLString | new TypeName("String") | 'someString' || 'someString' GraphQLBoolean | new TypeName("Boolean") | 'true' || true GraphQLFloat | new TypeName("Float") | '42.43' || 42.43d - } def "getVariableValues: map object as variable input"() { @@ -76,9 +74,9 @@ class ValuesResolverTest extends Specification { VariableDefinition variableDefinition = new VariableDefinition("variable", new TypeName("Person")) when: - def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], [variable: inputValue]) + def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: inputValue])) then: - resolvedValues['variable'] == outputValue + resolvedValues.get('variable') == outputValue where: inputValue || outputValue [name: 'a', id: 123] || [name: 'a', id: 123] @@ -116,7 +114,7 @@ class ValuesResolverTest extends Specification { when: def obj = new Person('a', 123) - resolver.coerceVariableValues(schema, [variableDefinition], [variable: obj]) + resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: obj])) then: thrown(CoercingParseValueException) } @@ -127,10 +125,9 @@ class ValuesResolverTest extends Specification { VariableDefinition variableDefinition = new VariableDefinition("variable", new ListType(new TypeName("String"))) String value = "world" when: - def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], [variable: value]) + def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: value])) then: - resolvedValues['variable'] == ['world'] - + resolvedValues.get('variable') == ['world'] } def "getVariableValues: list value gets resolved to a list when the type is a List"() { @@ -139,10 +136,9 @@ class ValuesResolverTest extends Specification { VariableDefinition variableDefinition = new VariableDefinition("variable", new ListType(new TypeName("String"))) List value = ["hello","world"] when: - def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], [variable: value]) + def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: value])) then: - resolvedValues['variable'] == ['hello','world'] - + resolvedValues.get('variable') == ['hello','world'] } def "getVariableValues: array value gets resolved to a list when the type is a List"() { @@ -151,16 +147,14 @@ class ValuesResolverTest extends Specification { VariableDefinition variableDefinition = new VariableDefinition("variable", new ListType(new TypeName("String"))) String[] value = ["hello","world"] as String[] when: - def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], [variable: value]) + def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: value])) then: - resolvedValues['variable'] == ['hello','world'] - + resolvedValues.get('variable') == ['hello','world'] } - def "getArgumentValues: resolves argument with variable reference"() { given: - def variables = [var: 'hello'] + def variables = new CoercedVariables([var: 'hello']) def fieldArgument = newArgument().name("arg").type(GraphQLString).build() def argument = new Argument("arg", new VariableReference("var")) @@ -181,8 +175,8 @@ class ValuesResolverTest extends Specification { def argument = new Argument("arg", new VariableReference("var")) when: - def variables = [:] - def values = resolver.getArgumentValues([fieldArgument], [argument], variables as Map) + def variables = CoercedVariables.emptyVariables() + def values = resolver.getArgumentValues([fieldArgument], [argument], variables) then: values['arg'] == 'hello' @@ -212,7 +206,7 @@ class ValuesResolverTest extends Specification { when: def argument = new Argument("arg", inputValue) - def values = resolver.getArgumentValues([fieldArgument], [argument], [:]) + def values = resolver.getArgumentValues([fieldArgument], [argument], CoercedVariables.emptyVariables()) then: values['arg'] == outputValue @@ -260,7 +254,7 @@ class ValuesResolverTest extends Specification { when: def argument = new Argument("arg", inputValue) - def values = resolver.getArgumentValues([fieldArgument], [argument], [:]) + def values = resolver.getArgumentValues([fieldArgument], [argument], CoercedVariables.emptyVariables()) then: values['arg'] == outputValue @@ -308,7 +302,7 @@ class ValuesResolverTest extends Specification { def fieldArgument1 = newArgument().name("arg1").type(enumType).build() def fieldArgument2 = newArgument().name("arg2").type(enumType).build() when: - def values = resolver.getArgumentValues([fieldArgument1, fieldArgument2], [argument1, argument2], [:]) + def values = resolver.getArgumentValues([fieldArgument1, fieldArgument2], [argument1, argument2], CoercedVariables.emptyVariables()) then: values['arg1'] == 'PLUTO' @@ -325,11 +319,10 @@ class ValuesResolverTest extends Specification { def fieldArgument = newArgument().name("arg").type(list(GraphQLBoolean)).build() when: - def values = resolver.getArgumentValues([fieldArgument], [argument], [:]) + def values = resolver.getArgumentValues([fieldArgument], [argument], CoercedVariables.emptyVariables()) then: values['arg'] == [true, false] - } def "getArgumentValues: resolves single value literal to a list when type is a list "() { @@ -340,11 +333,10 @@ class ValuesResolverTest extends Specification { def fieldArgument = newArgument().name("arg").type(list(GraphQLString)).build() when: - def values = resolver.getArgumentValues([fieldArgument], [argument], [:]) + def values = resolver.getArgumentValues([fieldArgument], [argument], CoercedVariables.emptyVariables()) then: values['arg'] == ['world'] - } def "getVariableValues: enum as variable input"() { @@ -359,14 +351,13 @@ class ValuesResolverTest extends Specification { VariableDefinition variableDefinition = new VariableDefinition("variable", new TypeName("Test")) when: - def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], [variable: inputValue]) + def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: inputValue])) then: - resolvedValues['variable'] == outputValue + resolvedValues.get('variable') == outputValue where: inputValue || outputValue "A_TEST" || "A_TEST" "VALUE_TEST" || 1 - } @Unroll @@ -388,20 +379,18 @@ class ValuesResolverTest extends Specification { VariableDefinition variableDefinition = new VariableDefinition("variable", new TypeName("InputObject")) when: - def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], [variable: inputValue]) + def resolvedValues = resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: inputValue])) then: - resolvedValues['variable'] == outputValue + resolvedValues.get('variable') == outputValue where: inputValue || outputValue [intKey: 10] || [intKey: 10, stringKey: 'defaultString'] [intKey: 10, stringKey: null] || [intKey: 10, stringKey: null] - } def "getVariableInput: Missing InputObject fields which are non-null cause error"() { - given: def inputObjectType = newInputObject() .name("InputObject") @@ -417,7 +406,7 @@ class ValuesResolverTest extends Specification { VariableDefinition variableDefinition = new VariableDefinition("variable", new TypeName("InputObject")) when: - resolver.coerceVariableValues(schema, [variableDefinition], [variable: inputValue]) + resolver.coerceVariableValues(schema, [variableDefinition], new RawVariables([variable: inputValue])) then: thrown(GraphQLException) @@ -436,10 +425,10 @@ class ValuesResolverTest extends Specification { VariableDefinition barVarDef = new VariableDefinition("bar", new TypeName("String")) when: - def resolvedValues = resolver.coerceVariableValues(schema, [fooVarDef, barVarDef], InputValue) + def resolvedValues = resolver.coerceVariableValues(schema, [fooVarDef, barVarDef], new RawVariables(InputValue)) then: - resolvedValues == outputValue + resolvedValues.toMap() == outputValue where: InputValue || outputValue @@ -454,7 +443,7 @@ class ValuesResolverTest extends Specification { VariableDefinition fooVarDef = new VariableDefinition("foo", new NonNullType(new TypeName("String"))) when: - resolver.coerceVariableValues(schema, [fooVarDef], [:]) + resolver.coerceVariableValues(schema, [fooVarDef], RawVariables.emptyVariables()) then: thrown(GraphQLException) @@ -470,14 +459,14 @@ class ValuesResolverTest extends Specification { def defaultValueForBar = new StringValue("defaultValueForBar") VariableDefinition barVarDef = new VariableDefinition("bar", new TypeName("String"), defaultValueForBar) - def variableValuesMap = ["foo": null, "bar": "barValue"] + def variableValuesMap = new RawVariables(["foo": null, "bar": "barValue"]) when: def resolvedVars = resolver.coerceVariableValues(schema, [fooVarDef, barVarDef], variableValuesMap) then: - resolvedVars['foo'] == null - resolvedVars['bar'] == "barValue" + resolvedVars.get('foo') == null + resolvedVars.get('bar') == "barValue" } def "coerceVariableValues: if variableType is a Non-Nullable type and value is null, throw a query error"() { @@ -487,8 +476,7 @@ class ValuesResolverTest extends Specification { def defaultValueForFoo = new StringValue("defaultValueForFoo") VariableDefinition fooVarDef = new VariableDefinition("foo", new NonNullType(new TypeName("String")), defaultValueForFoo) - - def variableValuesMap = ["foo": null] + def variableValuesMap = new RawVariables(["foo": null]) when: resolver.coerceVariableValues(schema, [fooVarDef], variableValuesMap) @@ -506,7 +494,7 @@ class ValuesResolverTest extends Specification { def type = new ListType(new NonNullType(new TypeName("String"))) VariableDefinition fooVarDef = new VariableDefinition("foo", type, defaultValueForFoo) - def variableValuesMap = ["foo": [null]] + def variableValuesMap = new RawVariables(["foo": [null]]) when: resolver.coerceVariableValues(schema, [fooVarDef], variableValuesMap) @@ -528,8 +516,8 @@ class ValuesResolverTest extends Specification { def argument = new Argument("arg", NullValue.newNullValue().build()) when: - def variables = [:] - def values = resolver.getArgumentValues([fieldArgument], [argument], variables as Map) + def variables = CoercedVariables.emptyVariables() + def values = resolver.getArgumentValues([fieldArgument], [argument], variables) then: values['arg'] == null @@ -545,7 +533,7 @@ class ValuesResolverTest extends Specification { def argument = new Argument("arg", new VariableReference("var")) when: - def variables = ["var": null] + def variables = new CoercedVariables(["var": null]) def values = resolver.getArgumentValues([fieldArgument], [argument], variables) then: @@ -562,7 +550,7 @@ class ValuesResolverTest extends Specification { def argument = new Argument("arg", new VariableReference("var")) when: - def variables = ["var": null] + def variables = new CoercedVariables(["var": null]) resolver.getArgumentValues([fieldArgument], [argument], variables) then: diff --git a/src/test/groovy/graphql/normalized/ExecutableNormalizedOperationFactoryTest.groovy b/src/test/groovy/graphql/normalized/ExecutableNormalizedOperationFactoryTest.groovy index b39225a4c1..3199148d1e 100644 --- a/src/test/groovy/graphql/normalized/ExecutableNormalizedOperationFactoryTest.groovy +++ b/src/test/groovy/graphql/normalized/ExecutableNormalizedOperationFactoryTest.groovy @@ -2,7 +2,9 @@ package graphql.normalized import graphql.GraphQL import graphql.TestUtil +import graphql.execution.CoercedVariables import graphql.execution.MergedField +import graphql.execution.RawVariables import graphql.language.Document import graphql.language.Field import graphql.language.FragmentDefinition @@ -106,8 +108,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -192,8 +194,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -272,8 +274,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -323,8 +325,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: @@ -366,8 +368,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: @@ -416,8 +418,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: @@ -479,8 +481,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -525,8 +527,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: @@ -569,8 +571,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: @@ -613,8 +615,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: @@ -645,8 +647,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: @@ -696,8 +698,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -734,8 +736,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: @@ -779,7 +781,7 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) def dependencyGraph = new ExecutableNormalizedOperationFactory() - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -819,7 +821,7 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) def dependencyGraph = new ExecutableNormalizedOperationFactory() - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -867,7 +869,7 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) def dependencyGraph = new ExecutableNormalizedOperationFactory() - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -935,8 +937,8 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) def subFooField = (document.getDefinitions()[1] as FragmentDefinition).getSelectionSet().getSelections()[0] as Field - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def fieldToNormalizedField = tree.getFieldToNormalizedField() expect: @@ -978,8 +980,8 @@ type Dog implements Animal{ def petsField = (document.getDefinitions()[0] as OperationDefinition).getSelectionSet().getSelections()[0] as Field def idField = petsField.getSelectionSet().getSelections()[0] as Field - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def fieldToNormalizedField = tree.getFieldToNormalizedField() @@ -1027,8 +1029,8 @@ type Dog implements Animal{ def schemaField = selections[2] as Field def typeField = selections[3] as Field - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def fieldToNormalizedField = tree.getFieldToNormalizedField() expect: @@ -1084,13 +1086,13 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: printedTree == ['-Query.pet: Pet', - '--[Dog, Cat].name: String']; + '--[Dog, Cat].name: String'] } def "same result key but different field"() { @@ -1127,14 +1129,14 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTree(tree) expect: printedTree == ['Query.pet', 'name: Dog.otherField', - 'Cat.name']; + 'Cat.name'] } def "normalized field to MergedField is build"() { @@ -1155,20 +1157,20 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) - def normalizedFieldToMergedField = tree.getNormalizedFieldToMergedField(); - Traverser traverser = Traverser.depthFirst({ it.getChildren() }); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) + def normalizedFieldToMergedField = tree.getNormalizedFieldToMergedField() + Traverser traverser = Traverser.depthFirst({ it.getChildren() }) List result = new ArrayList<>() when: traverser.traverse(tree.getTopLevelFields(), new TraverserVisitorStub() { @Override TraversalControl enter(TraverserContext context) { - ExecutableNormalizedField normalizedField = context.thisNode(); + ExecutableNormalizedField normalizedField = context.thisNode() result.add(normalizedFieldToMergedField[normalizedField]) - return TraversalControl.CONTINUE; + return TraversalControl.CONTINUE } - }); + }) then: result.size() == 4 @@ -1193,10 +1195,10 @@ type Dog implements Animal{ Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def coordinatesToNormalizedFields = tree.coordinatesToNormalizedFields then: @@ -1294,8 +1296,8 @@ schema { Document document = TestUtil.parseQuery(mutation) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); - def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, [:]) + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() + def tree = dependencyGraph.createExecutableNormalizedOperation(graphQLSchema, document, null, CoercedVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) expect: @@ -1343,7 +1345,7 @@ schema { assertValidQuery(graphQLSchema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() def variables = [ var1: [bar: 123], var2: [foo: "foo", input2: [bar: 123]] @@ -1351,7 +1353,7 @@ schema { // the normalized arg value should be the same regardless of how the value was provided def expectedNormalizedArgValue = [foo: new NormalizedInputValue("String", parseValue('"foo"')), input2: new NormalizedInputValue("Input2", [bar: new NormalizedInputValue("Int", parseValue("123"))])] when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, variables) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, new RawVariables(variables)) def topLevelField = tree.getTopLevelFields().get(0) def secondField = topLevelField.getChildren().get(0) def arg1 = secondField.getNormalizedArgument("arg1") @@ -1393,7 +1395,7 @@ schema { def dependencyGraph = new ExecutableNormalizedOperationFactory() def variables = [:] when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, variables) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, new RawVariables(variables)) then: def topLevelField = tree.getTopLevelFields().get(0) @@ -1432,7 +1434,7 @@ schema { otherVar: null, ] when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, variables) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, new RawVariables(variables)) then: def topLevelField = tree.getTopLevelFields().get(0) @@ -1482,9 +1484,9 @@ schema { ] assertValidQuery(graphQLSchema, query, variables) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, variables) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, new RawVariables(variables)) def topLevelField = tree.getTopLevelFields().get(0) def arg1 = topLevelField.getNormalizedArgument("arg1") def arg2 = topLevelField.getNormalizedArgument("arg2") @@ -1535,9 +1537,9 @@ schema { ] assertValidQuery(graphQLSchema, query, variables) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, variables) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, new RawVariables(variables)) def topLevelField = tree.getTopLevelFields().get(0) def arg1 = topLevelField.getNormalizedArgument("arg1") def arg2 = topLevelField.getNormalizedArgument("arg2") @@ -1590,9 +1592,9 @@ schema { ''' assertValidQuery(graphQLSchema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, RawVariables.emptyVariables()) then: tree.normalizedFieldToMergedField.size() == 3 @@ -1648,9 +1650,9 @@ schema { ''' assertValidQuery(graphQLSchema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, RawVariables.emptyVariables()) println String.join("\n", printTree(tree)) /** @@ -1694,9 +1696,9 @@ schema { ''' assertValidQuery(graphQLSchema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, graphQLSchema) then: @@ -1765,9 +1767,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -1829,9 +1831,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -1886,9 +1888,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -1961,9 +1963,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -2023,9 +2025,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -2065,9 +2067,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -2108,9 +2110,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -2151,9 +2153,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -2226,9 +2228,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -2302,9 +2304,9 @@ schema { ''' assertValidQuery(schema, query) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, [:]) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, document, null, RawVariables.emptyVariables()) def printedTree = printTreeWithLevelInfo(tree, schema) then: @@ -2364,9 +2366,9 @@ schema { def variables = ["true": Boolean.TRUE, "false": Boolean.FALSE] assertValidQuery(graphQLSchema, query, variables) Document document = TestUtil.parseQuery(query) - ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory(); + ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() when: - def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, variables) + def tree = dependencyGraph.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, new RawVariables(variables)) println String.join("\n", printTree(tree)) def printedTree = printTree(tree) @@ -2394,7 +2396,7 @@ schema { assertValidQuery(graphQLSchema, query) Document document = TestUtil.parseQuery(query) when: - def tree = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, [:]) + def tree = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperationWithRawVariables(graphQLSchema, document, null, RawVariables.emptyVariables()) println String.join("\n", printTree(tree)) def printedTree = printTree(tree) diff --git a/src/test/groovy/graphql/normalized/ExecutableNormalizedOperationToAstCompilerTest.groovy b/src/test/groovy/graphql/normalized/ExecutableNormalizedOperationToAstCompilerTest.groovy index 8d036db2d1..92ef468bba 100644 --- a/src/test/groovy/graphql/normalized/ExecutableNormalizedOperationToAstCompilerTest.groovy +++ b/src/test/groovy/graphql/normalized/ExecutableNormalizedOperationToAstCompilerTest.groovy @@ -2,6 +2,7 @@ package graphql.normalized import graphql.GraphQL import graphql.TestUtil +import graphql.execution.RawVariables import graphql.language.AstPrinter import graphql.language.AstSorter import graphql.language.Document @@ -2044,7 +2045,7 @@ class ExecutableNormalizedOperationToAstCompilerTest extends Specification { Document originalDocument = TestUtil.parseQuery(query) ExecutableNormalizedOperationFactory dependencyGraph = new ExecutableNormalizedOperationFactory() - return dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, originalDocument, null, variables) + return dependencyGraph.createExecutableNormalizedOperationWithRawVariables(schema, originalDocument, null, new RawVariables(variables)) } private List createNormalizedFields(GraphQLSchema schema, String query, Map variables = [:]) { diff --git a/src/test/java/benchmark/NQBenchmark1.java b/src/test/java/benchmark/NQBenchmark1.java index 1ab7aa9e6d..f96dd27447 100644 --- a/src/test/java/benchmark/NQBenchmark1.java +++ b/src/test/java/benchmark/NQBenchmark1.java @@ -2,6 +2,7 @@ import com.google.common.base.Charsets; import com.google.common.io.Resources; +import graphql.execution.CoercedVariables; import graphql.language.Document; import graphql.normalized.ExecutableNormalizedOperation; import graphql.normalized.ExecutableNormalizedOperationFactory; @@ -83,7 +84,7 @@ public void benchMarkThroughput(MyState myState, Blackhole blackhole ) { } private void runImpl(MyState myState, Blackhole blackhole) { - ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, Collections.emptyMap()); + ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, CoercedVariables.emptyVariables()); blackhole.consume(executableNormalizedOperation); } diff --git a/src/test/java/benchmark/NQBenchmark2.java b/src/test/java/benchmark/NQBenchmark2.java index 65862a6f86..931e1160f9 100644 --- a/src/test/java/benchmark/NQBenchmark2.java +++ b/src/test/java/benchmark/NQBenchmark2.java @@ -3,6 +3,7 @@ import com.google.common.base.Charsets; import com.google.common.collect.ImmutableListMultimap; import com.google.common.io.Resources; +import graphql.execution.CoercedVariables; import graphql.language.Document; import graphql.language.Field; import graphql.normalized.ExecutableNormalizedField; @@ -77,7 +78,7 @@ private String readFromClasspath(String file) throws IOException { @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) public ExecutableNormalizedOperation benchMarkAvgTime(MyState myState) throws ExecutionException, InterruptedException { - ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, Collections.emptyMap()); + ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, CoercedVariables.emptyVariables()); // System.out.println("fields size:" + normalizedQuery.getFieldToNormalizedField().size()); return executableNormalizedOperation; } @@ -85,7 +86,7 @@ public ExecutableNormalizedOperation benchMarkAvgTime(MyState myState) throws Ex public static void main(String[] args) { MyState myState = new MyState(); myState.setup(); - ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, Collections.emptyMap()); + ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, CoercedVariables.emptyVariables()); // System.out.println(printTree(normalizedQuery)); ImmutableListMultimap fieldToNormalizedField = executableNormalizedOperation.getFieldToNormalizedField(); System.out.println(fieldToNormalizedField.size());