-
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
[RFC] allow empty selections #674
base: main
Are you sure you want to change the base?
Conversation
Sometimes, product code might only be interested in the existence of an object. Currently, this forces a workaround of either querying `__typename` or adding a bool field like `has_thing`. It seems natural and not too confusing to allow empty selections: ``` query { event { location {} } } ``` The response should either return `null` or an empty object for `location`.
Thanks for pushing this! I think we've thought about this so many times over the years that it's time to get crisp about whether we want to do this or not. I think earlier proposals suggested allowing the subselection to be omitted, but that was rejected because it could also be an easy mistake, this variant is less likely to be confused in that way. Some things that may help:
It would also be really great if you could capture this kind of context into an RFC document as a first step (in |
Want to call out that this would also make it easier to implement programs which transform Documents. For example federation might cause fields to be removed from a selection set and inserted into another query, making it easy to end up inadvertently creating an empty selection set. Furthermore Flow/TypeScript types doesn't catch empty selection sets either as you can't reject empty arrays with those type systems. Instead you end up with a runtime error. |
For what it's worth, I'd favor omitting the subselection entirely.
I think allowing empty object selections would raise the expectation to support empty object types (which is why I'm commenting on this issue, since I worked a bit on this, see #606). You'd open up GraphQL to "marker objects" as it'd remove concerns about having to "select fields down to scalar values". I think this would be a net positive but I think the issues are related. |
e5d241d
to
6c81ed8
Compare
Sometimes, product code might only be interested in the existence of an object. Currently, this forces a workaround of either querying
__typename
or adding a bool field likehas_thing
.It seems natural and not too confusing to allow empty selections:
The response should either return
null
or an empty object forlocation
.(The spec changes are incomplete.)