Skip to content

Comments

Make deprecated reason non-null#3759

Merged
dondonz merged 5 commits intomasterfrom
3736-deprecated-reason
Dec 5, 2024
Merged

Make deprecated reason non-null#3759
dondonz merged 5 commits intomasterfrom
3736-deprecated-reason

Conversation

@dondonz
Copy link
Member

@dondonz dondonz commented Dec 1, 2024

Closes #3736

An incoming spec change will require the @deprecated reason to be non-nullable. graphql/graphql-spec#1040.

Whilst this is technically a breaking change, the reason already has a default value, so it is only a breaking change if the reason null was previously used.

Update: when I started the PR it was at RFC1 stage, at the time of merging the proposal reached RFC3 (Accepted) stage and is already in the draft spec document: https://spec.graphql.org/draft/#sec--deprecated

@dondonz dondonz added the breaking change requires a new major version to be relased label Dec 1, 2024
@dondonz dondonz added this to the 23.x breaking changes milestone Dec 1, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2024

Test Results

  306 files    306 suites   47s ⏱️
3 479 tests 3 474 ✅ 5 💤 0 ❌
3 568 runs  3 563 ✅ 5 💤 0 ❌

Results for commit a95cc02.

♻️ This comment has been updated with latest results.

});
changeNode(context, newElement);
return TraversalControl.ABORT;
}
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 am guessing the Anonymizer pre-dates the split of GraphQLDirective and GraphQLAppliedDirective

Now that applied directives are separated, there shouldn't be any transformation in this GraphQLDirective visitor method. The deprecated directive as defined in the schema should be unchanged, as any other built-in directive in the next lines

if (DirectiveInfo.isGraphqlSpecifiedDirective(graphQLDirective.getName())) {
    return TraversalControl.ABORT;
}

@@ -285,7 +274,8 @@ public TraversalControl visitGraphQLAppliedDirective(GraphQLAppliedDirective gra
if (Directives.DEPRECATED_DIRECTIVE_DEFINITION.getName().equals(graphQLDirective.getName())) {
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 I mentioned above, the censoring of @deprecated reasons should actually only be here, in the GraphQLAppliedDirective visitor method only

@@ -285,7 +274,8 @@ public TraversalControl visitGraphQLAppliedDirective(GraphQLAppliedDirective gra
if (Directives.DEPRECATED_DIRECTIVE_DEFINITION.getName().equals(graphQLDirective.getName())) {
GraphQLAppliedDirectiveArgument reason = GraphQLAppliedDirectiveArgument.newArgument().name("reason")
.type(Scalars.GraphQLString)
Copy link
Member Author

Choose a reason for hiding this comment

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

It's ok for an applied directive's argument to be nullable. In this case, the default value ("No longer supported") as defined in the schema will be used

"Marks the field, argument, input field or enum value as deprecated"
directive @deprecated(
"The reason for the deprecation"
reason: String = "No longer supported"
Copy link
Member Author

Choose a reason for hiding this comment

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

All that follows is a number of tests which need updating

.name("reason")
.description(createDescription("The reason for the deprecation"))
.type(newTypeName().name(STRING).build())
.type(newNonNullType(newTypeName().name(STRING).build()).build())
Copy link
Member

Choose a reason for hiding this comment

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

what is newNonNullType ???

Copy link
Member

Choose a reason for hiding this comment

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

ahh a builder

@dondonz
Copy link
Member Author

dondonz commented Dec 5, 2024

This proposed change has been included in the draft specification today: https://spec.graphql.org/draft/#sec--deprecated

graphql/graphql-spec#1040

@dondonz dondonz added the spec-change Tracking GraphQL specification changes label Dec 5, 2024
@dondonz dondonz merged commit 08cf170 into master Dec 5, 2024
@dondonz dondonz deleted the 3736-deprecated-reason branch December 5, 2024 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change requires a new major version to be relased spec-change Tracking GraphQL specification changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking spec change: non-nullable reason for @deprecated

2 participants