-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Spec clarification: recursive coercion of scalar values into lists (Oct2016 section 3.1.7) #372
Comments
leebyron
added a commit
that referenced
this issue
May 1, 2018
This adds some additional copy to list result coercion about handling errors and nullability for items, and clarified copy and new examples for input coercion to better clarify the single-item rule, recursive coercion, and null values. Fixes #372
Thanks for bringing this up - the original intention was that this applied recursively but I can see from the spec text how this was not as clear as it could be. I'm glad you were able to correctly interpret it for the erlang implementation. I added an edit which includes some clarity on why single value wrapping in inputs is valuable and examples of this coercion. |
leebyron
added a commit
that referenced
this issue
May 1, 2018
This adds some additional copy to list result coercion about handling errors and nullability for items, and clarified copy and new examples for input coercion to better clarify the single-item rule, recursive coercion, and null values. Fixes #372
leebyron
added a commit
that referenced
this issue
May 1, 2018
This adds some additional copy to list result coercion about handling errors and nullability for items, and clarified copy and new examples for input coercion to better clarify the single-item rule, recursive coercion, and null values. Fixes #372
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Background
Suppose I have a schema which contains
Question
If I have an arg which expect a value of type
[Pet]
and I supply the valueDOG
, the spec is clear that the system should coerce this value into[DOG]
which is valid in the context.However, the spec is not clear about what to do with recursive definitions of this. There are two ways we can interpret the coercion:
Furthermore, we can consider the following rules:
T
.Consider a case where my schema has
gameOfLife(matrix: [[PET]])
. Now, if I supplyDOG
, there are two interpretations, when we consider the above:DOG
into[DOG]
and then recurse, yielding[[DOG]]
as the final answer.Implementation
In my Erlang implementation of GraphQL (https://github.com/shopgun/graphql-erlang) we currently recurse. This seems somewhat easier to handle in a functional language. We just "wrap" one level and then call again with the new structure. In turn, once the correct form is met, we accept the type. In the execution phase, the same thing happens.
Discussion
The coercion is definitely one of convenience for the programmer. A type system is more complex if it has to deal with this, and can't rely on straightforward equality. So from a type theory point of view, this coercion should just be rejected altogether.
For a programmer of a statically typed language, it doesn't seem to me that this is useful. You would probably use a "type provider" system to make sure everything is fitting and thus you would always input something of type
[Pet]
in the example above. For dynamic languages, this could be more useful.What I am trying to get at is this: would the recursive nature help a programmer in any way? If not, then rejecting it is probably the better option because it could eliminate some surprise and room for error. OTOH, if there is a legitimate use, then it could prove to be a useful feature. I can only guess that this may also be the reason this coercion happens in the first place.
The text was updated successfully, but these errors were encountered: