Repo to demonstrate using directives in GraphQL with DGS Framework
- Execute
./gradlew bootRun
(orgradlew.bat bootRun
in Windows) - Open localhost:8080/graphiql
- Execute any query/mutation of your choice using graphiql or click on any of the sample queries below :)
How are the directives registered?
Most directives (Range/NotBlank...) are from the library graphql-java/graphql-java-extended-validation.
They get registered with DGS in AddExtendedValidationDirectiveWiring
Why can't I find the code for Movie/Rating?
I use the DGS Codegen Plugin to automatically generate them from the defined schema during the build.
What do I need to do for a custom directive?
You need to implement the interface SchemaDirectiveWiring
, register it using @DgsRuntimeWiring
and implement/override the method for each directiveLocation you implement (eg onInputObjectType
, onField
etc...)
See StringCaseDirective as an example of a custom directive.