Add query/operation directives documentation#185
Conversation
| UserContext contextForUser = YourGraphqlContextBuilder.getContextForUser(getCurrentUser()); | ||
|
|
||
| ExecutionInput executionInput = ExecutionInput.newExecutionInput() | ||
| .context(contextForUser) |
There was a problem hiding this comment.
I branched off the other documentation PR because this work touches on the same directives file.
| @@ -3,6 +3,14 @@ title: "SDL directives" | |||
| date: 2018-09-09T12:52:46+10:00 | |||
There was a problem hiding this comment.
As with all our documentation there are v22 and master versions, however these happen to be the same information
I renamed this filed from sdl-directives to directives to make it clearer it contains both schema and query/operation directives
There was a problem hiding this comment.
The diff has gotten confused about mapping which files got renamed, don't worry they are identical
| @Override | ||
| public GraphQLFieldDefinition onField(SchemaDirectiveWiringEnvironment<GraphQLFieldDefinition> environment) { | ||
| String targetAuthRole = (String) environment.getDirective().getArgument("role").getArgumentValue().getValue(); | ||
| String targetAuthRole = (String) environment.getAppliedDirective().getArgument("role").getArgumentValue().getValue(); |
There was a problem hiding this comment.
From other PR, removing deprecated method uses
|
|
||
| [Directives](https://spec.graphql.org/draft/#sec-Language.Directives) are a powerful feature of GraphQL, allowing you to declare additional data to a schema or document. This data can then be used to change runtime execution or type validation behavior. | ||
|
|
||
| There are two broad categories of directives, schema and operation directives. Schema directives are used on schema elements, and operation directives are used in operations within a GraphQL document. |
There was a problem hiding this comment.
Unfortunately the whole Directives world is a bit confusing: to be very precise a Directive(definition) can be both if the Directive is allowed on Schema elements + Operation elements.
Therefore a Directive(definition) can be either or both.
An AppliedDirective (Directive instance) is always either one.
Not sure how or if we want to explain this here.
There was a problem hiding this comment.
I'll add a note so it's crystal clear
Note for those who love the details: the terminology of directives is a bit confusing. It is technically possible to define a directive that is both a schema and operation directive, in other words, defined for both schema and operation locations. However in practice, this is not common.
… and operation locations
| products = fetchAllProductsFromDatabase(ctx); | ||
| } | ||
| return products; | ||
| @Override |
Our documentation only explained schema (SDL) directives, but we didn't yet have a section on query/operation directives. This gave the wrong impression that GraphQL Java didn't support query/operation directives.
This PR adds documentation for query/operation directives.
See previous GitHub discussion threads: graphql-java/graphql-java#3311