-
Notifications
You must be signed in to change notification settings - Fork 1.1k
failure to require leaf field selection when using fragments #610
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
Comments
Actually, I think that it is valid. The spec says :
It simply states that it must contain a subselection (could be an inline fragment as in your example). It doesn't specify that its subselections must be leaf field selections. I agree that in essence it should actually contain leaf selections for every possible subtype of the field's return type (e.g {
"character" : [{}, {}, {}]
} This also happens with union types, you are not obliged to specify each concrete type and therefore can get empty results. I imagine there must be some reason related to fragments ? |
Interesting question. |
@VladimirAlexiev Thanks for the question 👍
We have an RFC that makes it valid, please see #674
Because it's a common use case to get only data for certain types from union/interface.
In general empty selection was forbidden because most of the time they were used unintentionally. Forbidding empty objects was never a goal here. Moreover adding such requirement will break a lot of existing queries that contradicts "Backwards compatibility" principle: https://github.com/graphql/graphql-spec/blob/master/CONTRIBUTING.md#guiding-principles |
Assume a simple schema like this:
This query is not valid because it does not select down to leaf (scalar) fields (see https://graphql.github.io/graphql-spec/draft/#sec-Leaf-Field-Selections):
Then why is this query valid? It selects a scalar field, but only for Human. It'd return Droids without any fields i.e.
{}
.I asked the question on:
andrewingram replied: it's valid, which can seem counter-intuitive. it's valid in graphql-js, which is aligned with the spec.
I think the query exposes an omission in the spec?
The text was updated successfully, but these errors were encountered: