-
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
[Validation] Nested inline fragments may be unreachable #367
Comments
Another option, say option (3) (sorry for not spotting this before), is to just make the following query valid query { there seems to be no problem as it would just give an empty result while evaluating and, as expected, would be equivalent to: query { |
The area in the specification which is invoked here is section http://facebook.github.io/graphql/October2016/#sec-Fragment-spread-is-possible (Section 5.4.2.3) and its following subsections. The spec defines that you check a spread in its "immediate" context and not in the possible contextual "path" that the spread occurs in. The "immediate" check is easy to implement, but will exhibit the behavior you mention. It is mostly there to capture nonsensical queries which are valid enough to execute but are likely to be mistakes. To implement a better solution, one must take the full contextual path into consideration. The path is something like However, it remains to be shown that there are no situations in which this expansion is actually desirable by the developer. In that case, we cannot use it as a validation because the it might occur legally in some query documents and have the intended behavior. It is not a priori clear to me that such a situation can never occur, so one definitely has to be careful here. |
I just updated the title for this. This is an area where additional validation could be applied and is just presently missing. @jlouis is correct that we would need to be careful not to inadvertently make a request invalid which is actually useful. I think that tightening the validation to only apply for immediately nested inline fragments would be useful, however the same could not be extended to typical fragments. |
I'm not sure if this is the place to put this issue. It is about an unexpected behavior of the inline Type fragments in the current GraphQL spec.
Consider the GraphQL schema defined in the example page http://graphql.org/swapi-graphql. The following query is invalid as "Person" can never be of type "Vehicle" so the object cannot be spread.
Nevertheless, the following query is valid which seems to be counterintuitive
In this case the validity came from the fact that "...on Node" can be spread as a "Person" is always a "Node", and moreover, "...on Vehicle" can be spread in the scope of a "Node". This is counter intuitive since the "...on Node" is in the scope of "Person" which makes the "...on Vehicle" fragment to always be in the scope of the "Person"so anyway it cannot be spread. Executing this last query at http://graphql.org/swapi-graphql gives
{
"data": {
"allPeople": {
"people": [
{},
{},
.... (several times)....
{}
]
} } }
I think that this design would lead to some misunderstanding from users. I have thought on two possible options to deal with this:
or
The text was updated successfully, but these errors were encountered: