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)); } }
NonNullableFieldWasNullException nonNullException = new NonNullableFieldWasNullException(executionStepInfo, path); executionContext.addError(new NonNullableFieldWasNullError(nonNullException), path); throw nonNullException;
/** * 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 ExecutionResult createER() { List<GraphQLError> errors = new ArrayList<>(); errors.add(new ValidationError(ValidationErrorType.UnknownType, mkLocations(), "Test ValidationError")); errors.add(new MissingRootTypeException("Mutations are not supported.", null)); errors.add(new InvalidSyntaxError(mkLocations(), "Not good syntax m'kay")); errors.add(new NonNullableFieldWasNullError(new NonNullableFieldWasNullException(mkExecutionInfo(), mkPath()))); errors.add(new SerializationError(mkPath(), new CoercingSerializeException("Bad coercing"))); errors.add(new ExceptionWhileDataFetching(mkPath(), new RuntimeException("Bang"), mkLocation(666, 999))); return new ExecutionResultImpl(null, errors); }
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)); } }
NonNullableFieldWasNullException nonNullException = new NonNullableFieldWasNullException(executionStepInfo, path); executionContext.addError(new NonNullableFieldWasNullError(nonNullException), path); throw nonNullException;
/** * 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 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); }