Skip to content

Conversation

@dondonz
Copy link
Member

@dondonz dondonz commented May 8, 2024

Fixes #3590

From the GraphQL specification:

The @deprecated directive must not appear on required (non-null without a default) arguments or input object field definitions.

This PR adds the schema validation rule to enforce this line of the spec.

@dondonz dondonz marked this pull request as ready for review May 9, 2024 00:29
@dondonz dondonz changed the title WIP Add @deprecated validation for input object fields, field arguments, directive arguments Ready: Add @deprecated validation for input object fields, field arguments, directive arguments May 12, 2024
@Override
public TraversalControl visitGraphQLInputObjectField(GraphQLInputObjectField inputObjectField, TraverserContext<GraphQLSchemaElement> context) {
// There can only be at most one @deprecated, because it is not a repeatable directive
GraphQLAppliedDirective deprecatedDirective = inputObjectField.getAppliedDirective("deprecated");
Copy link
Member

Choose a reason for hiding this comment

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

Use Directives.Deprecated.getName() perhaps to stop string spread

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's a better idea, I'll add that. Don't want a random string hanging out 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 fixed both strings in the commit after your review

@Override
public TraversalControl visitGraphQLArgument(GraphQLArgument argument, TraverserContext<GraphQLSchemaElement> context) {
// There can only be at most one @deprecated, because it is not a repeatable directive
GraphQLAppliedDirective deprecatedDirective = argument.getAppliedDirective("deprecated");
Copy link
Member

Choose a reason for hiding this comment

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

string constant suggestion as abovee

Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Nice one!

@dondonz dondonz added this pull request to the merge queue May 14, 2024
Merged via the queue into master with commit 2285351 May 14, 2024
@dondonz dondonz deleted the deprecated-validation branch May 14, 2024 21:58
@dondonz dondonz added this to the 22.1 milestone May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants