Skip to content

Allow empty object types#1228

Open
benjie wants to merge 1 commit into
empty-selection-setsfrom
empty-object-types
Open

Allow empty object types#1228
benjie wants to merge 1 commit into
empty-selection-setsfrom
empty-object-types

Conversation

@benjie
Copy link
Copy Markdown
Member

@benjie benjie commented May 23, 2026

Merge first:


Since 2015 we've always required an object type to define at least 1 field. As we continue to explore GraphQL's position in the new AI-world, we realise that we need schema subsets that represents part of a larger interface, in these cases it's sometimes useful to leave in type references without including full definitions of those types:

type Query {
  topAuthors: [Author!]
}
type Author {
  name: String!
  salesVolume: Int
  averageRating: Float
  topBooks: [Book!]
  mediaCoverage: [Article!]
  recentPublishers: [Publisher!]
}
type Book
type Article
type Publisher

Here the AI can see a basic schema it can write queries against, but it can also ask to expand the parts of the schema that are relevant to its interests - e.g. books or articles or publishers - without wasting context on things it doesn't care about.

We can make a schema like this valid by including at least one field on each of these types, but it's hard for a tool to know which field(s) to include, and not including fields makes it much more obvious to the LLM that the schema is partial. Making this partial schema itself valid would be helpful for tooling.

AI aside:

  • This is also very useful for mutation payloads where no obvious value exists to return yet but we may wish to expand in future. Currently type MyMutationPayload { success: Boolean! } is used as a workaround, but it's messy.
  • This is also very useful for schema evolution - it allows you to create a type before you know what it will contain, and allows you to deprecate all fields of a type without the schema being invalid.

Related:

@netlify
Copy link
Copy Markdown

netlify Bot commented May 23, 2026

Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit 8c40697
🔍 Latest deploy log https://app.netlify.com/projects/graphql-spec-draft/deploys/6a122f4f925e460007248957
😎 Deploy Preview https://deploy-preview-1228--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
@benjie benjie changed the base branch from main to empty-selection-sets May 23, 2026 22:51
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.

+1000

@benjie benjie force-pushed the empty-object-types branch from 8c40697 to 21a2a8c Compare May 25, 2026 11:37
@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.

The ability to represent empty objects

2 participants