Skip to content

Instantly share code, notes, and snippets.

@aSemy
Created June 1, 2018 08:44
Show Gist options
  • Save aSemy/851bb742f1413ec08b12547a3b7e0ff7 to your computer and use it in GitHub Desktop.
Save aSemy/851bb742f1413ec08b12547a3b7e0ff7 to your computer and use it in GitHub Desktop.
@Autowired
public GraphQlSampleController(final GraphQLRuleService ruleService) {
// Schema generated from query classes
GraphQLSchema schemaFromAnnotated = new GraphQLSchemaGenerator()//
// setup the schema
// ...
.generate();
// set up field validation
CustomFieldValidation fieldValidation = new CustomFieldValidation();
fieldValidation
// add rules for when user is registering
.addRules(ExecutionPath.parse("/userRegister"), UserRegisterRequest.getRules(ruleService))
;
FieldValidationInstrumentation instrumentation = new FieldValidationInstrumentation(fieldValidation);
// add rules to the schema
graphQlFromAnnotated = GraphQL.newGraphQL(schemaFromAnnotated)//
.instrumentation(instrumentation)//
.build();
LOGGER.info("Generated GraphQL schema using SPQR");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment