Skip to content

Allow empty selection sets#1227

Open
benjie wants to merge 1 commit into
mainfrom
empty-selection-sets
Open

Allow empty selection sets#1227
benjie wants to merge 1 commit into
mainfrom
empty-selection-sets

Conversation

@benjie

@benjie benjie commented May 23, 2026

Copy link
Copy Markdown
Member

Since 2015 we've requires selection sets to contain at least one field; however it's always been possible to have an empty object returned:

type A { a: Int }
type B { b: Int }
union U = A | B
type Query { u: U }

query {
  u {
    ... on A { __typename }
  }
}

Here, if u returns type B the 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?

  query LaunchDetails($launchId: ID!) {
    launch(id: $launchId) {
      isInCart @client
      site @client
    }
  }

There are many options (add __typename, remove launch, throw error, ...), but the safest solution is to allow the selection set to be empty. Hence, this PR.

@netlify

netlify Bot commented May 23, 2026

Copy link
Copy Markdown

Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit 220e8d4
🔍 Latest deploy log https://app.netlify.com/projects/graphql-spec-draft/deploys/6a1434990dc1e70008858c37
😎 Deploy Preview https://deploy-preview-1227--graphql-spec-draft.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@benjie benjie added 💭 Strawman (RFC 0) RFC Stage 0 (See CONTRIBUTING.md) 🚀 Next Stage? This RFC believes it is ready for the next stage labels May 23, 2026

@martinbonnin martinbonnin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread spec/Appendix B -- Notation Conventions.md Outdated
@benjie
benjie force-pushed the empty-selection-sets branch from 8c13477 to 220e8d4 Compare May 25, 2026 11:37

@jerelmiller jerelmiller left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Comment on lines +723 to +725
- 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.

@magicmark magicmark May 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@magicmark magicmark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :)

@leebyron leebyron added 💡 Proposal (RFC 1) RFC Stage 1 (See CONTRIBUTING.md) 📄 Draft (RFC 2) RFC Stage 2 (See CONTRIBUTING.md) and removed 💭 Strawman (RFC 0) RFC Stage 0 (See CONTRIBUTING.md) 🚀 Next Stage? This RFC believes it is ready for the next stage 💡 Proposal (RFC 1) RFC Stage 1 (See CONTRIBUTING.md) labels Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📄 Draft (RFC 2) RFC Stage 2 (See CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants