use of graphql.execution.instrumentation.fieldvalidation.FieldValidationEnvironment in project graphql-java by graphql-java.
the class InstrumentationExamples method fieldValidation.
private void fieldValidation() {
ExecutionPath fieldPath = ExecutionPath.parse("/user");
FieldValidation fieldValidation = new SimpleFieldValidation().addRule(fieldPath, new BiFunction<FieldAndArguments, FieldValidationEnvironment, Optional<GraphQLError>>() {
@Override
public Optional<GraphQLError> apply(FieldAndArguments fieldAndArguments, FieldValidationEnvironment environment) {
String nameArg = fieldAndArguments.getArgumentValue("name");
if (nameArg.length() > 255) {
return Optional.of(environment.mkError("Invalid user name", fieldAndArguments));
}
return Optional.empty();
}
});
FieldValidationInstrumentation instrumentation = new FieldValidationInstrumentation(fieldValidation);
GraphQL.newGraphQL(schema).instrumentation(instrumentation).build();
}
Aggregations