-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Missing validation of schema directive argument types #3912
Comments
I was also surprised by this behavior. Context is that I use Looking at the spec, I don't see where exactly where it explicitly says that directive arguments in the schema get validated. Maybe I just don't know where to look. I was expecting to find it in section 3.3 which states:
Is it possible this is a gap in the spec? I was able to confirm that this behavior still reproduces on Update: It looks like this is a gap in the spec: #1389 |
Agree it should be in section 3; but not sure whether it should be throughout or centralized. We define directive definition validation here: https://spec.graphql.org/draft/#sec-Type-System.Directives.Validation For each of the possible schema directive locations (not runtime locations) we need to add to their validation rules that each of the directives applied pass the same or similar checks as in https://spec.graphql.org/draft/#sec-Validation.Directives and https://spec.graphql.org/draft/#sec-Values. E.g. we already have "for each field of an Object type..." We could add "For each directive applied to an Object type..." and do so for each of the directive locations; but I think that would get a bit redundant. Instead, we should maybe add another section immediately below https://spec.graphql.org/draft/#sec-Type-System.Directives.Validation that is something like "Application validation" that validates the applied directives across all of their locations. I think the main issue is we don't really have a "validate SDL" part of the spec, and the schema itself (in spec terms, not necessarily implementations) doesn't contain "applied directives" - the idea is that tooling would apply the directives by making changes to the schema, but the resulting schema would not "store" that these changes have happened. E.g. |
Yeah, I think that's a good explanation for why we find ourselves in this state. That said, I think that we now have several examples of directives that are used to encode additional information that consumers/clients want to be able to see. (This next bit is veering out on a tangent a bit) |
My understanding is that one complication is that directives could be used to construct the type system, for example via combination of SDL documents (such as via an import directive). Validating directives with the type system may be tricky considering that the type system may not be fully built. We could require that any original directive uses be validated based on the final type system. We could also validate directives that use only specified types. |
We should note that there are two use cases for schema directives:
Currently GraphQL only caters to the former (with the nuance that To your point, @yaacovCR, I think that validating a schema SDL would be opt-in, so tooling that works in interesting ways (e.g. merging remote SDL) would be down to the tooling to validate or not the inputs. Nothing in the spec requires an SDL document, or any GraphQL document for that matter, to be valid on its own; it's dependent on how it's used - currently we only require that an executable document be valid in order to execute it (and even then, there are caveats around when you can skip validation). You're right that it's essential we continue to reflect this nuance if/when writing up SDL validation into the spec. |
It seems there is no validation for the argument types of custom schema directives.
Passing an argument with the wrong type to a custom schema directive doesn't throw an error during schema building, e.g. with
buildASTSchema
orbuildSchema
. Meanwhile, built-in schema directives likedeprecated
seem to validate their argument types correctly.This results in the arguments of a custom schema directive possibly ending up with an unexpected type and your server breaking at runtime when you figure out the bug in your schema. Notably, the type ends up being
EnumValue
if it doesn't exist as this seems to be the default type.Steps to reproduce
deno repl
and paste in, or run from file withdeno run file.ts
Expected result
The
buildSchema(source1)
call throws like thebuildSchema(source2)
does.Actual result
The
buildSchema(source1)
call doesn't throw.The text was updated successfully, but these errors were encountered: