FieldAndArgError(String message, Field field, ExecutionPath path) { this.message = message; this.locations = field == null ? null : Collections.singletonList(field.getSourceLocation()); this.path = path == null ? null : path.toList(); }
public SourceLocation getSourceLocation() { return getField().getSingleField().getSourceLocation(); }
private FetchedValue handleExceptionWhileFetching(Field field, ExecutionPath path, Throwable exception) { ExceptionWhileDataFetching exceptionWhileDataFetching = new ExceptionWhileDataFetching(path, exception, field.getSourceLocation()); return FetchedValue.newFetchedValue().errors(singletonList(exceptionWhileDataFetching)).build(); }
Optional<SourceLocation> baseLocation = Optional.ofNullable(fields.getSingleField().getSourceLocation());
@Override public void checkField(Field field) { GraphQLOutputType type = getValidationContext().getOutputType(); if (type == null) return; if (isLeaf(type)) { if (field.getSelectionSet() != null) { String message = String.format("Sub selection not allowed on leaf type %s of field %s", type.getName(), field.getName()); addError(ValidationErrorType.SubSelectionNotAllowed, field.getSourceLocation(), message); } } else { if (field.getSelectionSet() == null) { String message = String.format("Sub selection required for type %s of field %s", type.getName(), field.getName()); addError(ValidationErrorType.SubSelectionRequired, field.getSourceLocation(), message); } } } }
@Override public void checkField(Field field) { GraphQLCompositeType parentType = getValidationContext().getParentType(); // this means the parent type is not a CompositeType, which is an error handled elsewhere if (parentType == null) return; GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef(); if (fieldDef == null) { String message = String.format("Field '%s' in type '%s' is undefined", field.getName(), parentType.getName()); addError(ValidationErrorType.FieldUndefined, field.getSourceLocation(), message); } } }
public void onFetchingException(ExecutionStrategyParameters parameters, Throwable e) { ExceptionWhileDataFetching error = new ExceptionWhileDataFetching(parameters.getPath(), e, parameters.getField().getSingleField().getSourceLocation()); onError(error); }
@Override public Field deepCopy() { return new Field(name, alias, deepCopy(arguments), deepCopy(directives), deepCopy(selectionSet), getSourceLocation(), getComments(), getIgnoredChars() ); }
@Override public void checkField(Field field) { GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef(); if (fieldDef == null) return; Map<String, Argument> argumentMap = argumentMap(field.getArguments()); for (GraphQLArgument graphQLArgument : fieldDef.getArguments()) { Argument argument = argumentMap.get(graphQLArgument.getName()); if (argument == null && (isNonNull(graphQLArgument.getType())) && (graphQLArgument.getDefaultValue() == null)) { String message = String.format("Missing field argument %s", graphQLArgument.getName()); addError(ValidationErrorType.MissingFieldArgument, field.getSourceLocation(), message); } } }
private Builder(Field existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.alias = existing.getAlias(); this.arguments = existing.getArguments(); this.directives = existing.getDirectives(); this.selectionSet = existing.getSelectionSet(); this.ignoredChars = existing.getIgnoredChars(); }
FieldAndArgError(String message, Field field, ExecutionPath path) { this.message = message; this.locations = field == null ? null : Collections.singletonList(field.getSourceLocation()); this.path = path == null ? null : path.toList(); }
public SourceLocation getSourceLocation() { return getField().getSingleField().getSourceLocation(); }
private FetchedValue handleExceptionWhileFetching(Field field, ExecutionPath path, Throwable exception) { ExceptionWhileDataFetching exceptionWhileDataFetching = new ExceptionWhileDataFetching(path, exception, field.getSourceLocation()); return FetchedValue.newFetchedValue().errors(singletonList(exceptionWhileDataFetching)).build(); }
@Override public void checkField(Field field) { GraphQLOutputType type = getValidationContext().getOutputType(); if (type == null) return; if (isLeaf(type)) { if (field.getSelectionSet() != null) { String message = String.format("Sub selection not allowed on leaf type %s of field %s", type.getName(), field.getName()); addError(ValidationErrorType.SubSelectionNotAllowed, field.getSourceLocation(), message); } } else { if (field.getSelectionSet() == null) { String message = String.format("Sub selection required for type %s of field %s", type.getName(), field.getName()); addError(ValidationErrorType.SubSelectionRequired, field.getSourceLocation(), message); } } } }
@Override public void checkField(Field field) { GraphQLCompositeType parentType = getValidationContext().getParentType(); // this means the parent type is not a CompositeType, which is an error handled elsewhere if (parentType == null) return; GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef(); if (fieldDef == null) { String message = String.format("Field '%s' in type '%s' is undefined", field.getName(), parentType.getName()); addError(ValidationErrorType.FieldUndefined, field.getSourceLocation(), message); } } }
public void onFetchingException(ExecutionStrategyParameters parameters, Throwable e) { ExceptionWhileDataFetching error = new ExceptionWhileDataFetching(parameters.getPath(), e, parameters.getField().getSingleField().getSourceLocation()); onError(error); }
@Override public Field deepCopy() { return new Field(name, alias, deepCopy(arguments), deepCopy(directives), deepCopy(selectionSet), getSourceLocation(), getComments(), getIgnoredChars() ); }
/** * This will set up the {@link GraphQLError#getLocations()} and {@link graphql.GraphQLError#getPath()} for you from the * fetching environment. * * @param dataFetchingEnvironment the data fetching environment * * @return a builder of {@link graphql.GraphQLError}s */ public static GraphqlErrorBuilder newError(DataFetchingEnvironment dataFetchingEnvironment) { return new GraphqlErrorBuilder() .location(dataFetchingEnvironment.getField().getSourceLocation()) .path(dataFetchingEnvironment.getExecutionStepInfo().getPath()); }
@Override public void checkField(Field field) { GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef(); if (fieldDef == null) return; Map<String, Argument> argumentMap = argumentMap(field.getArguments()); for (GraphQLArgument graphQLArgument : fieldDef.getArguments()) { Argument argument = argumentMap.get(graphQLArgument.getName()); if (argument == null && (isNonNull(graphQLArgument.getType())) && (graphQLArgument.getDefaultValue() == null)) { String message = String.format("Missing field argument %s", graphQLArgument.getName()); addError(ValidationErrorType.MissingFieldArgument, field.getSourceLocation(), message); } } }
private Builder(Field existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.alias = existing.getAlias(); this.arguments = existing.getArguments(); this.directives = existing.getDirectives(); this.selectionSet = existing.getSelectionSet(); this.ignoredChars = existing.getIgnoredChars(); }