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
Copy link
Copy Markdown
Member

@benjie benjie commented May 23, 2026

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
Copy link
Copy Markdown

netlify Bot commented May 23, 2026

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
Copy link
Copy Markdown
Contributor

@martinbonnin martinbonnin left a comment

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚀 Next Stage? This RFC believes it is ready for the next stage 💭 Strawman (RFC 0) RFC Stage 0 (See CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants