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
validate non-nullable directive args #3551
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,23 +195,53 @@ class GraphQLArgumentTest extends Specification { | |
resolvedDefaultValue == null | ||
} | ||
|
||
def "Applied schema directives arguments are validated for programmatic schemas"() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not certain, but I think "Applied" in the test case name meant something different from a GraphQLAppliedDirective, which this test case doesn't use. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah the reason this is confusing is explained on the main PR comments. Nominally a type should have BOTH a GraphQLAppliedDirective for every GraphQLDirective - but tests allow this not to happen - or more properly programatic building of schemas allow it (since it could also happen in production code if you build your schema directly and not via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See |
||
def "schema directive arguments are validated for programmatic schemas"() { | ||
given: | ||
def arg = newArgument().name("arg").type(GraphQLInt).valueProgrammatic(ImmutableKit.emptyMap()).build() // Retain for test coverage | ||
def directive = GraphQLDirective.newDirective().name("cached").argument(arg).build() | ||
def directive = newDirective().name("cached").argument(arg).build() | ||
def field = newFieldDefinition() | ||
.name("hello") | ||
.type(GraphQLString) | ||
.argument(arg) | ||
.withDirective(directive) | ||
.build() | ||
.name("hello") | ||
.type(GraphQLString) | ||
.argument(arg) | ||
.withDirective(directive) | ||
.build() | ||
when: | ||
newSchema().query( | ||
newSchema() | ||
.query( | ||
newObject() | ||
.name("Query") | ||
.field(field) | ||
.build()) | ||
.name("Query") | ||
.field(field) | ||
.build() | ||
) | ||
.additionalDirective(directive) | ||
.build() | ||
then: | ||
def e = thrown(InvalidSchemaException) | ||
e.message.contains("Invalid argument 'arg' for applied directive of name 'cached'") | ||
} | ||
|
||
def "applied directive arguments are validated for programmatic schemas"() { | ||
given: | ||
def arg = newArgument() | ||
.name("arg") | ||
.type(GraphQLNonNull.nonNull(GraphQLInt)) | ||
.build() | ||
def directive = newDirective().name("cached").argument(arg).build() | ||
def field = newFieldDefinition() | ||
.name("hello") | ||
.type(GraphQLString) | ||
.withAppliedDirective(directive.toAppliedDirective()) | ||
.build() | ||
when: | ||
newSchema() | ||
.query( | ||
newObject() | ||
.name("Query") | ||
.field(field) | ||
.build() | ||
) | ||
.additionalDirective(directive) | ||
.build() | ||
then: | ||
def e = thrown(InvalidSchemaException) | ||
e.message.contains("Invalid argument 'arg' for applied directive of name 'cached'") | ||
|
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 suspect we need to do some more work here on how default values get put into place at runtime. Because if its not null but it has a default than thats ok right.
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.
Actually look at the code - we make an assumption that the default value is transferred into the
GraphQLArgument
/GraphQLAppliedDirectiveArgument
at creation time and hence it should be validated if its a non null type