public static NonNullableFieldWasNullException newNullableException(FetchedValueAnalysis fetchedValueAnalysis, Collection<ExecutionResultNode> children) { // can only happen for the root node if (fetchedValueAnalysis == null) { return null; } Assert.assertNotNull(children); boolean listIsNonNull = fetchedValueAnalysis.getExecutionStepInfo().isNonNullType(); if (listIsNonNull) { Optional<NonNullableFieldWasNullException> firstNonNullableException = getFirstNonNullableException(children); if (firstNonNullableException.isPresent()) { return new NonNullableFieldWasNullException(firstNonNullableException.get()); } } return null; }
protected void assertNonNullFieldPrecondition(NonNullableFieldWasNullException e, CompletableFuture<?> completableFuture) throws NonNullableFieldWasNullException { ExecutionStepInfo executionStepInfo = e.getExecutionStepInfo(); if (executionStepInfo.hasParent() && executionStepInfo.getParent().isNonNullType()) { completableFuture.completeExceptionally(new NonNullableFieldWasNullException(e)); } }
/** * 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); } }
if (executionStepInfo.isNonNullType()) {
/** * This allows you to morph a type into a more specialized form yet return the same * parent and non-null ness, for example taking a {@link GraphQLInterfaceType} * and turning it into a specific {@link graphql.schema.GraphQLObjectType} * after type resolution has occurred * * @param newType the new type to be * * @return a new type info with the same */ public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLOutputType newType) { assertTrue(!GraphQLTypeUtil.isNonNull(newType), "newType can't be non null"); if (isNonNullType()) { return new ExecutionStepInfo(GraphQLNonNull.nonNull(newType), fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } else { return new ExecutionStepInfo(newType, fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } }
public ExecutionResultNode createResultNode(FetchedValueAnalysis fetchedValueAnalysis) { if (fetchedValueAnalysis.isNullValue() && fetchedValueAnalysis.getExecutionStepInfo().isNonNullType()) { NonNullableFieldWasNullException nonNullableFieldWasNullException = new NonNullableFieldWasNullException(fetchedValueAnalysis.getExecutionStepInfo(), fetchedValueAnalysis.getExecutionStepInfo().getPath()); return new LeafExecutionResultNode(fetchedValueAnalysis, nonNullableFieldWasNullException); } if (fetchedValueAnalysis.isNullValue()) { return new LeafExecutionResultNode(fetchedValueAnalysis, null); } if (fetchedValueAnalysis.getValueType() == FetchedValueAnalysis.FetchedValueType.OBJECT) { return createUnresolvedNode(fetchedValueAnalysis); } if (fetchedValueAnalysis.getValueType() == FetchedValueAnalysis.FetchedValueType.LIST) { return createListResultNode(fetchedValueAnalysis); } return new LeafExecutionResultNode(fetchedValueAnalysis, null); }
public static NonNullableFieldWasNullException newNullableException(FetchedValueAnalysis fetchedValueAnalysis, Collection<ExecutionResultNode> children) { // can only happen for the root node if (fetchedValueAnalysis == null) { return null; } Assert.assertNotNull(children); boolean listIsNonNull = fetchedValueAnalysis.getExecutionStepInfo().isNonNullType(); if (listIsNonNull) { Optional<NonNullableFieldWasNullException> firstNonNullableException = getFirstNonNullableException(children); if (firstNonNullableException.isPresent()) { return new NonNullableFieldWasNullException(firstNonNullableException.get()); } } return null; }
protected void assertNonNullFieldPrecondition(NonNullableFieldWasNullException e, CompletableFuture<?> completableFuture) throws NonNullableFieldWasNullException { ExecutionStepInfo executionStepInfo = e.getExecutionStepInfo(); if (executionStepInfo.hasParent() && executionStepInfo.getParent().isNonNullType()) { completableFuture.completeExceptionally(new NonNullableFieldWasNullException(e)); } }
if (executionStepInfo.isNonNullType()) {
/** * 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); } }
/** * This allows you to morph a type into a more specialized form yet return the same * parent and non-null ness, for example taking a {@link GraphQLInterfaceType} * and turning it into a specific {@link graphql.schema.GraphQLObjectType} * after type resolution has occurred * * @param newType the new type to be * * @return a new type info with the same */ public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLOutputType newType) { assertTrue(!GraphQLTypeUtil.isNonNull(newType), "newType can't be non null"); if (isNonNullType()) { return new ExecutionStepInfo(GraphQLNonNull.nonNull(newType), fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } else { return new ExecutionStepInfo(newType, fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } }
public ExecutionResultNode createResultNode(FetchedValueAnalysis fetchedValueAnalysis) { if (fetchedValueAnalysis.isNullValue() && fetchedValueAnalysis.getExecutionStepInfo().isNonNullType()) { NonNullableFieldWasNullException nonNullableFieldWasNullException = new NonNullableFieldWasNullException(fetchedValueAnalysis.getExecutionStepInfo(), fetchedValueAnalysis.getExecutionStepInfo().getPath()); return new LeafExecutionResultNode(fetchedValueAnalysis, nonNullableFieldWasNullException); } if (fetchedValueAnalysis.isNullValue()) { return new LeafExecutionResultNode(fetchedValueAnalysis, null); } if (fetchedValueAnalysis.getValueType() == FetchedValueAnalysis.FetchedValueType.OBJECT) { return createUnresolvedNode(fetchedValueAnalysis); } if (fetchedValueAnalysis.getValueType() == FetchedValueAnalysis.FetchedValueType.LIST) { return createListResultNode(fetchedValueAnalysis); } return new LeafExecutionResultNode(fetchedValueAnalysis, null); }