Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wtfjoke/graphql-dgs-directives-demo
Repo to demonstrate GraphQL Directives with DGS Framework and Spring Boot
https://github.com/wtfjoke/graphql-dgs-directives-demo
dgs dgs-framework graphql graphql-directive graphql-java graphql-server netflix-dgs
Last synced: about 2 months ago
JSON representation
Repo to demonstrate GraphQL Directives with DGS Framework and Spring Boot
- Host: GitHub
- URL: https://github.com/wtfjoke/graphql-dgs-directives-demo
- Owner: WtfJoke
- License: mit
- Created: 2021-08-13T08:03:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-16T13:57:44.000Z (over 2 years ago)
- Last Synced: 2024-03-20T13:01:17.850Z (9 months ago)
- Topics: dgs, dgs-framework, graphql, graphql-directive, graphql-java, graphql-server, netflix-dgs
- Language: Kotlin
- Homepage:
- Size: 68.4 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GraphQL DGS Directives Demo
Repo to demonstrate using directives in GraphQL with [DGS Framework](https://netflix.github.io/dgs/)## Howto start
1. Execute `./gradlew bootRun` (or `gradlew.bat bootRun` in Windows)
2. Open [localhost:8080/graphiql](http://localhost:8080/graphiql)
3. Execute any query/mutation of your choice using [graphiql](https://github.com/graphql/graphiql) or click on any of the sample queries below :)### Sample queries
- [Valid Rating](http://localhost:8080/graphiql?query=mutation%20%7B%0A%20%20addRating(rating%3A%20%7Btitle%3A%20%22Inception%22%2C%20stars%3A%205%7D)%7B%0A%20%20%20%20stars%0A%20%20%7D%0A%7D%0A)
- [Invalid stars rating](http://localhost:8080/graphiql?query=mutation%20%7B%0A%20%20addRating(rating%3A%20%7Btitle%3A%20%22Inception%22%2C%20stars%3A%2010%7D)%7B%0A%20%20%20%20stars%0A%20%20%7D%0A%7D%0A)
- [Invalid title while rating](http://localhost:8080/graphiql?query=mutation%20%7B%0A%20%20addRating(rating%3A%20%7Btitle%3A%20%22%22%2C%20stars%3A%205%7D)%7B%0A%20%20%20%20stars%0A%20%20%7D%0A%7D%0A)## F.A.Q
>How are the directives registered?
Most directives (Range/NotBlank...) are from the library [graphql-java/graphql-java-extended-validation](https://github.com/graphql-java/graphql-java-extended-validation).
They get registered with DGS in [AddExtendedValidationDirectiveWiring](src/main/kotlin/com/github/wtfjoke/dgsDirectivesExamples/graphql/directives/wirings/AddExtendedValidationDirectiveWiring.kt)>Why can't I find the code for Movie/Rating?
I use the [DGS Codegen Plugin](https://netflix.github.io/dgs/generating-code-from-schema/) 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](src/main/kotlin/com/github/wtfjoke/dgsDirectivesExamples/graphql/directives/StringCaseDirective.kt) as an example of a custom directive.