Skip to content

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

Merged
merged 8 commits into from
Jan 30, 2025

Conversation

dondonz
Copy link
Member

@dondonz dondonz commented Dec 26, 2024

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

@@ -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)
Copy link
Member Author

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
Copy link
Member Author

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

Copy link
Member Author

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();
Copy link
Member Author

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

Copy link
Member

@andimarek andimarek left a 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.
Copy link
Member

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.

Copy link
Member Author

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.

products = fetchAllProductsFromDatabase(ctx);
}
return products;
@Override
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace changes

@dondonz dondonz merged commit 8cad088 into master Jan 30, 2025
@dondonz dondonz deleted the query-directives-documentation branch January 30, 2025 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants