-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 coercion or validation for default values #3248
Comments
Thanks for the heads up on this! I bet the default value gets dropped in graphql-ruby/lib/graphql/types/int.rb Line 13 in 74bbeea
Like you said, I bet it's never validated. Is there any reason not to apply validation during configuration (ie, during the |
Two potential complications came up during the Working Group meeting:
class A < GraphApi::InputObject
field :a, A, required: true, default_value: A.new
end |
Hey @eapache and @rmosolgo,
When opting-in to use the Interpreter (with |
It sounds like a specific behavior is in draft in the spec: graphql/graphql-wg#645 (comment) |
The GraphQL Spec states that this situation should throw, I think: |
@rmosolgo I took a look into fixing this and ran into a bunch of interesting points:
Options I've considered:
Is there another option I'm missing? Do we care about context in custom scalar coercion (at a quick glance none of Shopify's scalars use it)? |
I agree that your first suggestion is the best. A dummy context will likely be good enough, and if those intense cases come up, we can investigate one of those more intense approaches. Here's a dummy context used elsewhere for purposes like this:
|
👍 can you give me a hint where I should hook to handle late-bound types? |
☠️ Here there be dragons 🐉 When root types are added to the schema, any indirect type references ( graphql-ruby/lib/graphql/schema.rb Lines 1785 to 1787 in bace1e4
After the normal type references are added, the indirect references are visited: graphql-ruby/lib/graphql/schema.rb Line 1789 in bace1e4
The indirect references are dereferenced in their own ways: graphql-ruby/lib/graphql/schema.rb Lines 1791 to 1792 in bace1e4
graphql-ruby/lib/graphql/schema.rb Lines 1797 to 1798 in bace1e4
Then passed to graphql-ruby/lib/graphql/schema.rb Lines 1821 to 1874 in bace1e4
My first guess would be to hack it inside |
Possible a simple question, possibly a complicated one: should default values be |
@rmosolgo I spoke with @leebyron and a few other folks working on implementations of this at the Working Group meeting yesterday. graphql-js and most others have moved to a two-pass schema building system (resolve all the types, then do a complete second pass for validations and such). This makes a lot of sense and would provide us with a cleaner solution, but is a much larger refactor than I can contribute right now. It sounds like you're OK with #3476 or perhaps a variation like 30722fb - I'm happy to polish up and add tests for whatever set of trade-offs you'd prefer to accept. Just let me know what direction you want to go. |
Fixed by #3496 |
Describe the bug
@benjie pointed out in graphql/graphql-spec#793 that the GraphQL Spec and JS reference implementations are both somewhat confusing/broken when dealing with mistyped default values. I haven't gone through and tried to reproduce all the various combinations of this issue, but I did demonstrate a simple case to show that graphql-ruby suffers from at least a similar class of bug.
Versions
graphql
version: 1.11.4 w/ interpreter, but I'm pretty sure it applies to master tooGraphQL schema
GraphQL query
Expected vs actual behaviour
There are two interesting points in this example:
default_value
is not making it through into the introspection output, so GraphiQL claims the argument needs a value. However, if you actually run it then it works (sorta).default_value
doesn't make it through into the resolver method, which getsnil
instead. This could really mess with resolver code which assumes a value (since the argument is required-with-a-default at the GraphQL layer).@rmosolgo there is still some debate on what the final specified behaviour should be, but I wanted to put this on your radar. The fact that the default value is getting stripped out in places suggests to me that we are validating it already somewhere, we're just not handling validation failures aggressively enough?
cc @swalkinshaw.
The text was updated successfully, but these errors were encountered: