-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe the bug
GraphQL specification prohibits deprecation directive on non-nullable arguments without a default value, but graphql-java allows creation of such schema programmatically although there is validation (DeprecatedInputObjectAndArgumentsAreValid) that should prevent that.
Let say a new argument is created like this:
GraphQLArgument deprecatedArg = GraphQLArgument.newArgument()
.name("argument")
.type(GraphQLNonNull.nonNull(Scalars.GraphQLString))
.deprecate("Some very good reason")
.build();
The validation then tries to find deprecated applied directive:
graphql-java/src/main/java/graphql/schema/validation/DeprecatedInputObjectAndArgumentsAreValid.java
Line 46 in aa0b31e
| GraphQLAppliedDirective deprecatedDirective = argument.getAppliedDirective(Directives.DEPRECATED_DIRECTIVE_DEFINITION.getName()); |
But deprecatedDirective is null, and so it's reported as valid schema. The fix seems to be calling of argument.isDeprecated(), or combination of both approaches.
To Reproduce
GraphQLArgument deprecatedArg = GraphQLArgument.newArgument()
.name("input")
.type(GraphQLNonNull.nonNull(Scalars.GraphQLString))
.deprecate("Some very good reason")
.build();
GraphQLFieldDefinition field = GraphQLFieldDefinition.newFieldDefinition()
.name("field")
.type(Scalars.GraphQLString)
.argument(deprecatedArg)
.dataFetcher(env -> env.getArgument("input")) // for simplicity
.build();
GraphQLObjectType queryType = GraphQLObjectType.newObject()
.name("Query")
.field(field)
.build();
GraphQLSchema.newSchema()
.query(queryType)
.build(); // this method internally do the validation and should throw exception
Equivalent schema (implicit parts are omitted):
type Query {
field(input: String! @deprecated(reason : "Some very good reason")): String
}