Allow empty selection sets - #1227
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
8c13477 to
220e8d4
Compare
| - The subselection set of that selection must not be present. | ||
| - If {selectionType} is an interface, union, or object: | ||
| - The subselection set of that selection must not be empty. | ||
| - The subselection set of that selection must be present. |
There was a problem hiding this comment.
Empty selection sets are being made valid by omission to the contrary, rather than being explicitly specified. (yes technically the grammar makes this explicit, but could be easy to miss)
"Empty selection sets are a bit weird/nonobvious, but they are valid" - is something along these lines worth calling out in the explanatory text below, or a non-norm note?
There was a problem hiding this comment.
@magicmark I've (hopefully) addressed this by adding examples. I considered adding non-normative notes to explain why this may be useful, but decided to avoid it in favour of simplicity.
|
I believe this is ready to merge, pending @yaacovCR's feedback on the GraphQL.js PR: |
|
If we're going to merge this, I think we can takeoff the experimental label on the associated PR? |
Excellent observation @yaacovCR. We can even probably drop the parameter altogether? |
|
I made another version of the PR if we decide to expedite this: My preference goes to "without experimental flag". Less complexity is better. |
|
I personally would keep the flag until next semver major, even if you default to enabling the feature. Reason: their security systems might not be set up to handle queries like this; consider: {
user {
a: friends {}
b: friends {}
c: friends {}
}
}if they're using complexity cost that multiples expected list length by selection set cost, and selection set cost is zero because there's no fields (previously not possible), it might have an impact on their security. (The IBM cost spec does not suffer from this AFAIK, but there are lots of models of query cost in the wild.) There may be other such concerns that we're not yet aware of, so giving people a way to opt out until v18 does not seem unwise. |
Works for me. All in all:
I have updated the PR in that direction. Let me know if something else is preferred. |
Since 2015 we've required selection sets to contain at least one field; however it's always been possible to have an empty object returned:
Here, if
ureturns typeBthe result will be{"data":{"u":{}}}- i.e. an empty object.GraphQL clients are getting smarter and smarter, and it's common to have client-side extensions such as Apollo's @client, Relay Resolvers or
@mock'd fields. In all of these cases, any selections of these fields need to be removed before the document is sent to the server. But what happens when all the fields in the selection set are to be removed?There are many options (add
__typename, removelaunch, throw error, ...), but the safest solution is to allow the selection set to be empty. Hence, this PR.