-
Notifications
You must be signed in to change notification settings - Fork 50
Add query/operation directives documentation #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -44,7 +44,7 @@ This made up example shows how you can pass yourself information to help execute | |||
UserContext contextForUser = YourGraphqlContextBuilder.getContextForUser(getCurrentUser()); | |||
|
|||
ExecutionInput executionInput = ExecutionInput.newExecutionInput() | |||
.context(contextForUser) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff has gotten confused about mapping which files got renamed, don't worry they are identical
@@ -75,7 +83,7 @@ class AuthorisationDirective implements SchemaDirectiveWiring { | |||
|
|||
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From other PR, removing deprecated method uses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment
|
||
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace changes
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