public NonNullableFieldWasNullException(NonNullableFieldWasNullException previousException) { super( mkMessage( assertNotNull(previousException.executionStepInfo.getParent()), assertNotNull(previousException.executionStepInfo.getParent().getPath()) ), previousException ); this.executionStepInfo = previousException.executionStepInfo.getParent(); this.path = previousException.executionStepInfo.getParent().getPath(); }
private GraphQLFieldsContainer getFieldsContainer(ExecutionStepInfo executionStepInfo) { GraphQLOutputType type = executionStepInfo.getParent().getType(); return (GraphQLFieldsContainer) GraphQLTypeUtil.unwrapAll(type); }
protected void assertNonNullFieldPrecondition(NonNullableFieldWasNullException e, CompletableFuture<?> completableFuture) throws NonNullableFieldWasNullException { ExecutionStepInfo executionStepInfo = e.getExecutionStepInfo(); if (executionStepInfo.hasParent() && executionStepInfo.getParent().isNonNullType()) { completableFuture.completeExceptionally(new NonNullableFieldWasNullException(e)); } }
private static String mkMessage(ExecutionStepInfo executionStepInfo, ExecutionPath path) { GraphQLType unwrappedTyped = executionStepInfo.getUnwrappedNonNullType(); if (executionStepInfo.hasParent()) { GraphQLType unwrappedParentType = executionStepInfo.getParent().getUnwrappedNonNullType(); return String.format("Cannot return null for non-nullable type: '%s' within parent '%s' (%s)", unwrappedTyped.getName(), unwrappedParentType.getName(), path); } return String.format("Cannot return null for non-nullable type: '%s' (%s)", unwrappedTyped.getName(), path); }
fetchMap.put("parentType", executionStepInfo.getParent().getUnwrappedNonNullType().getName()); fetchMap.put("returnType", executionStepInfo.simplePrint()); fetchMap.put("fieldName", executionStepInfo.getFieldDefinition().getName());
/** * See (http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability), * <p> * 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 * so we use exceptions to indicate this special case. However if the parent is in fact a non nullable type * itself then we need to bubble that upwards again until we get to the root in which case the result * is meant to be null. * * @param e this indicates that a null value was returned for a non null field, which needs to cause the parent field * to become null OR continue on as an exception * * @throws NonNullableFieldWasNullException if a non null field resolves to a null value */ protected void assertNonNullFieldPrecondition(NonNullableFieldWasNullException e) throws NonNullableFieldWasNullException { ExecutionStepInfo executionStepInfo = e.getExecutionStepInfo(); if (executionStepInfo.hasParent() && executionStepInfo.getParent().isNonNullType()) { throw new NonNullableFieldWasNullException(e); } }
private String mkMessage(ExecutionPath path, UnresolvedTypeException exception, ExecutionStepInfo info) { return format("Can't resolve '%s'. Abstract type '%s' must resolve to an Object type at runtime for field '%s.%s'. %s", path, exception.getInterfaceOrUnionType().getName(), info.getParent().getUnwrappedNonNullType().getName(), info.getFieldDefinition().getName(), exception.getMessage()); }
.field(currentParentExecutionStepInfo.getField()) .path(currentParentExecutionStepInfo.getPath()) .parentInfo(currentParentExecutionStepInfo.getParent()) .build();
public NonNullableFieldWasNullException(NonNullableFieldWasNullException previousException) { super( mkMessage( assertNotNull(previousException.executionStepInfo.getParent()), assertNotNull(previousException.executionStepInfo.getParent().getPath()) ), previousException ); this.executionStepInfo = previousException.executionStepInfo.getParent(); this.path = previousException.executionStepInfo.getParent().getPath(); }
private GraphQLFieldsContainer getFieldsContainer(ExecutionStepInfo executionStepInfo) { GraphQLOutputType type = executionStepInfo.getParent().getType(); return (GraphQLFieldsContainer) GraphQLTypeUtil.unwrapAll(type); }
protected void assertNonNullFieldPrecondition(NonNullableFieldWasNullException e, CompletableFuture<?> completableFuture) throws NonNullableFieldWasNullException { ExecutionStepInfo executionStepInfo = e.getExecutionStepInfo(); if (executionStepInfo.hasParent() && executionStepInfo.getParent().isNonNullType()) { completableFuture.completeExceptionally(new NonNullableFieldWasNullException(e)); } }
private static String mkMessage(ExecutionStepInfo executionStepInfo, ExecutionPath path) { GraphQLType unwrappedTyped = executionStepInfo.getUnwrappedNonNullType(); if (executionStepInfo.hasParent()) { GraphQLType unwrappedParentType = executionStepInfo.getParent().getUnwrappedNonNullType(); return String.format("Cannot return null for non-nullable type: '%s' within parent '%s' (%s)", unwrappedTyped.getName(), unwrappedParentType.getName(), path); } return String.format("Cannot return null for non-nullable type: '%s' (%s)", unwrappedTyped.getName(), path); }
fetchMap.put("parentType", executionStepInfo.getParent().getUnwrappedNonNullType().getName()); fetchMap.put("returnType", executionStepInfo.simplePrint()); fetchMap.put("fieldName", executionStepInfo.getFieldDefinition().getName());
if (step.hasParent() && step.getParent().getField() != null) { FragmentDirectiveCollector fragmentDirectiveCollector = FragmentDirectiveCollector.collect(env, step); directives.put(Introspection.DirectiveLocation.INLINE_FRAGMENT, parseDirectives(fragmentDirectiveCollector.getInlineFragmentDirs(), env));
private String mkMessage(ExecutionPath path, UnresolvedTypeException exception, ExecutionStepInfo info) { return format("Can't resolve '%s'. Abstract type '%s' must resolve to an Object type at runtime for field '%s.%s'. %s", path, exception.getInterfaceOrUnionType().getName(), info.getParent().getUnwrappedNonNullType().getName(), info.getFieldDefinition().getName(), exception.getMessage()); }
/** * See (http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability), * <p> * 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 * so we use exceptions to indicate this special case. However if the parent is in fact a non nullable type * itself then we need to bubble that upwards again until we get to the root in which case the result * is meant to be null. * * @param e this indicates that a null value was returned for a non null field, which needs to cause the parent field * to become null OR continue on as an exception * * @throws NonNullableFieldWasNullException if a non null field resolves to a null value */ protected void assertNonNullFieldPrecondition(NonNullableFieldWasNullException e) throws NonNullableFieldWasNullException { ExecutionStepInfo executionStepInfo = e.getExecutionStepInfo(); if (executionStepInfo.hasParent() && executionStepInfo.getParent().isNonNullType()) { throw new NonNullableFieldWasNullException(e); } }
public static FragmentDirectiveCollector collect(DataFetchingEnvironment env, ExecutionStepInfo step) { FragmentDirectiveCollector fragmentDirectiveCollector = new FragmentDirectiveCollector(env); // This is safe because top-level fields don't get to here and all deeper fields at least have a parent (source object) and a grand-parent (query root) ExecutionStepInfo rootStep = step.getParent().getParent(); if (rootStep == null) { //Should never be possible, see above return fragmentDirectiveCollector; } GraphQLType rootParentType = GraphQLUtils.unwrapNonNull(rootStep.getType()); while(!(rootParentType instanceof GraphQLObjectType)) { rootStep = rootStep.getParent(); rootParentType = GraphQLUtils.unwrapNonNull(rootStep.getType()); } QueryTraversal traversal = QueryTraversal.newQueryTraversal() .fragmentsByName(env.getExecutionContext().getFragmentsByName()) .schema(env.getGraphQLSchema()) .variables(env.getExecutionContext().getVariables()) .root(env.getExecutionStepInfo().getParent().getField()) .rootParentType((GraphQLObjectType) rootParentType) .build(); traversal.visitPostOrder(fragmentDirectiveCollector); return fragmentDirectiveCollector; }
.field(currentParentExecutionStepInfo.getField()) .path(currentParentExecutionStepInfo.getPath()) .parentInfo(currentParentExecutionStepInfo.getParent()) .build();