diff --git a/src/main/java/graphql/execution/ExecutionStrategy.java b/src/main/java/graphql/execution/ExecutionStrategy.java index 41d80eccf1..2286192afd 100644 --- a/src/main/java/graphql/execution/ExecutionStrategy.java +++ b/src/main/java/graphql/execution/ExecutionStrategy.java @@ -349,21 +349,21 @@ protected CompletableFuture handleFetchingException(ExecutionContext exec .build(); try { - return asyncHandleException(dataFetcherExceptionHandler, handlerParameters, executionContext); + return asyncHandleException(dataFetcherExceptionHandler, handlerParameters); } catch (Exception handlerException) { handlerParameters = DataFetcherExceptionHandlerParameters.newExceptionParameters() .dataFetchingEnvironment(environment) .exception(handlerException) .build(); - return asyncHandleException(new SimpleDataFetcherExceptionHandler(), handlerParameters, executionContext); + return asyncHandleException(new SimpleDataFetcherExceptionHandler(), handlerParameters); } } - private CompletableFuture asyncHandleException(DataFetcherExceptionHandler handler, DataFetcherExceptionHandlerParameters handlerParameters, ExecutionContext executionContext) { + private CompletableFuture asyncHandleException(DataFetcherExceptionHandler handler, DataFetcherExceptionHandlerParameters handlerParameters) { //noinspection unchecked - return handler.handleException(handlerParameters) - .thenApply(handlerResult -> (T) DataFetcherResult.newResult().errors(handlerResult.getErrors()).build() - ); + return handler.handleException(handlerParameters).thenApply( + handlerResult -> (T) DataFetcherResult.newResult().errors(handlerResult.getErrors()).build() + ); } /** @@ -620,7 +620,7 @@ protected CompletableFuture completeValueForScalar(ExecutionCon protected CompletableFuture completeValueForEnum(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLEnumType enumType, Object result) { Object serialized; try { - serialized = enumType.serialize(result); + serialized = enumType.serialize(result, executionContext.getGraphQLContext(), executionContext.getLocale()); } catch (CoercingSerializeException e) { serialized = handleCoercionProblem(executionContext, parameters, e); } @@ -633,7 +633,7 @@ protected CompletableFuture completeValueForEnum(ExecutionConte } /** - * Called to turn an java object value into an graphql object value + * Called to turn a java object value into an graphql object value * * @param executionContext contains the top level execution parameters * @param parameters contains the parameters holding the fields to be executed and source object @@ -649,7 +649,7 @@ protected CompletableFuture completeValueForObject(ExecutionCon .schema(executionContext.getGraphQLSchema()) .objectType(resolvedObjectType) .fragments(executionContext.getFragmentsByName()) - .variables(executionContext.getVariables()) + .variables(executionContext.getCoercedVariables().toMap()) .build(); MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, parameters.getField()); @@ -679,7 +679,6 @@ private Object handleCoercionProblem(ExecutionContext context, ExecutionStrategy return null; } - /** * Converts an object that is known to should be an Iterable into one * @@ -694,6 +693,10 @@ protected Iterable toIterable(Object result) { } protected GraphQLObjectType resolveType(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLType fieldType) { + // we can avoid a method call and type resolver environment allocation if we know it's an object type + if (fieldType instanceof GraphQLObjectType) { + return (GraphQLObjectType) fieldType; + } return resolvedType.resolveType(executionContext, parameters.getField(), parameters.getSource(), parameters.getExecutionStepInfo(), fieldType, parameters.getLocalContext()); } @@ -743,7 +746,7 @@ protected GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLObject } /** - * See (http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability), + * See (...), *

* If a non nullable child field type actually resolves to a null value and the parent type is nullable * then the parent must in fact become null diff --git a/src/main/java/graphql/execution/ResolveType.java b/src/main/java/graphql/execution/ResolveType.java index fbc9b5f536..3ef9c556fb 100644 --- a/src/main/java/graphql/execution/ResolveType.java +++ b/src/main/java/graphql/execution/ResolveType.java @@ -1,5 +1,6 @@ package graphql.execution; +import graphql.Assert; import graphql.Internal; import graphql.TypeResolutionEnvironment; import graphql.normalized.ExecutableNormalizedField; @@ -19,9 +20,9 @@ @Internal public class ResolveType { - public GraphQLObjectType resolveType(ExecutionContext executionContext, MergedField field, Object source, ExecutionStepInfo executionStepInfo, GraphQLType fieldType, Object localContext) { - GraphQLObjectType resolvedType; + Assert.assertTrue(fieldType instanceof GraphQLInterfaceType || fieldType instanceof GraphQLUnionType, + () -> "The passed in fieldType MUST be an interface or union type : " + fieldType.getClass().getName()); DataFetchingFieldSelectionSet fieldSelectionSet = buildSelectionSet(executionContext, field, (GraphQLOutputType) fieldType, executionStepInfo); TypeResolutionEnvironment env = TypeResolutionParameters.newParameters() .field(field) @@ -35,13 +36,10 @@ public GraphQLObjectType resolveType(ExecutionContext executionContext, MergedFi .schema(executionContext.getGraphQLSchema()) .build(); if (fieldType instanceof GraphQLInterfaceType) { - resolvedType = resolveTypeForInterface(env, (GraphQLInterfaceType) fieldType); - } else if (fieldType instanceof GraphQLUnionType) { - resolvedType = resolveTypeForUnion(env, (GraphQLUnionType) fieldType); + return resolveTypeForInterface(env, (GraphQLInterfaceType) fieldType); } else { - resolvedType = (GraphQLObjectType) fieldType; + return resolveTypeForUnion(env, (GraphQLUnionType) fieldType); } - return resolvedType; } private DataFetchingFieldSelectionSet buildSelectionSet(ExecutionContext executionContext, MergedField field, GraphQLOutputType fieldType, ExecutionStepInfo executionStepInfo) { @@ -65,11 +63,9 @@ private GraphQLObjectType resolveAbstractType(TypeResolutionEnvironment env, Typ if (result == null) { throw new UnresolvedTypeException(abstractType); } - if (!env.getSchema().isPossibleType(abstractType, result)) { throw new UnresolvedTypeException(abstractType, result); } - return result; }