Skip to content

Allow empty object, interface, and union types - #1228

Open
benjie wants to merge 13 commits into
mainfrom
empty-object-types
Open

benjie wants to merge 13 commits into
mainfrom
empty-object-types

Conversation

@benjie

@benjie benjie commented May 23, 2026 •

Copy link
Copy Markdown
Member

Related:


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.

This need can also be expanded to interfaces and unions:

type Query {
  search(text: String!): Searchable
}
interface Searchable {}

type Mutation {
  someMutation: SomeMutationResult
}
union SomeMutationResult = {}

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.
  • This also enables mutation-only schemas whilst still supporting introspection Proposal: Do not require query as a root operation type #490

Related:

@netlify

netlify Bot commented May 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit 333d8c0
🔍 Latest deploy log https://app.netlify.com/projects/graphql-spec-draft/deploys/6aecff7be16f39034664835c
😎 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

@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.

+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

@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.

💯

@leebyron leebyron added 💡 Proposal (RFC 1) RFC Stage 1 (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 labels Jul 2, 2026
@leebyron

leebyron commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Notes from meeting:

We should support syntax grammar for {} to clearly define no fields

key motivation is that "a schema minus all deprecated elements is always valid" which today could be not true! For a bunch of reasons but in this case:

type Example {
  onlyField @deprecated
}

this cannot create a valid non-deprecated schema! that's our aim.

Another example: a mutation payload (relay style) that wants to be defined up front as

Specifically important because the LLM-focused subschema generation still has some issues we're working out, and it's unclear that providing type Book {} to the LLM is what we want to do or not.

@martinbonnin

Copy link
Copy Markdown
Contributor

Looks like we'll need the same for input objects?

@andimarek

Copy link
Copy Markdown
Contributor

I am not sure this is the right place to comment, but together with the issue about interfaces without fields and interfaces without objects implementing them I am wondering if we should distinguish between valid schemas vs valid and executable schemas.

For example an interface without an implementation is not something I find sensible for a real schema that should be executed but for schema during design it is ok.

@martinbonnin

martinbonnin commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

an interface without an implementation is not something I find sensible for a real schema that should be executed

@andimarek My preference here would be a lint warning. The spec is already a bit vague on SDL validation (see #1233 (comment)) so we're not really equipped to have executable vs non-executable validation yet.

Base automatically changed from empty-selection-sets to main September 17, 2026 17:43
@benjie benjie added the 🚀 Next Stage? This RFC believes it is ready for the next stage label Oct 15, 2026
@DaleSeo

DaleSeo commented Oct 26, 2026 •

Copy link
Copy Markdown

A data point from the AI WG. I’m writing the Schema Search RFC (graphql/ai-wg#187). It describes a service returning a valid subset of its schema as SDL in response to a natural language query. That subset is exactly the kind of partial schema this PR covers, so I wanted to share how the current rule affects it.

Since object types need at least one field today, our slicer has to drop any type that has no matching fields. That also removes every field that returns that type, so the model never learns that Author.topBooks exists. With this change, the slice can keep type Book {} and preserve the reference. If needed, the model can ask for Book in a later request.

This also enables mutation-only schemas while still supporting introspection.

We also hit this case when searches match only mutations, like "create an issue." The slice needs Mutation.createIssue and its input and payload types, but nothing from Query. However, a schema must have a query root type, and today that type must have at least one field. So the slicer has to pick an unrelated Query field, such as viewer: User!, and include User too. The model then sees types that have nothing to do with the question, and the choice of field differs between implementations. With this change, the slice can say type Query {} and stop there.

@DaleSeo

DaleSeo commented Oct 26, 2026

Copy link
Copy Markdown

Looks like we'll need the same for input objects?

+1 from the schema-search side, with one caveat that I think is worth stating, because input objects behave differently from output types here.

A slice guarantees that any operation that validates against the slice will also validate against the full schema. An empty input Filter {} only preserves that guarantee if the full Filter definition has no required fields. Otherwise, the slice still needs to include those required fields.

Comment thread spec/Section 3 -- Type System.md Resolved
@DaleSeo

DaleSeo commented Nov 5, 2026

Copy link
Copy Markdown

Ahead of today's WG, here is a short summary of the open syntax question, so we can settle it in the meeting.

Question: how do we write an object type, interface, or input object with no fields?

Option type T type T {} Grammar change
A stub, must be extended empty type + → *
B (#1245) empty type empty type, same meaning + → *
C (#1228, #1229, #1249) empty type syntax error, as today none
  • A is off the table. A union has only the bare form, so it cannot tell an empty union apart from a stub waiting for extension.
  • B gives two ways to write one thing. Parsers that predate it reject {}, so SDL written with {} breaks existing tools at parse time. It helps tools that remove fields as text and leave {} behind.
  • C keeps one way to write each kind, the same as unions. Existing parsers already read type T. Tools that print from an AST, such as printSchema in graphql-js, already print the bare form.

Suggestion: C. It needs no grammar change, and we can still add {} later if tools turn out to need it. Removing it later would be a breaking change. Martin is collecting data on tools that emit {}, and that data can drive a follow-up.

Asks for today:

  1. Agree on C.
  2. Advance Allow empty object, interface, and union types #1228 and Allow interfaces with no fields, unions with no members #1229 to RFC 2.
  3. Accept Allow empty input object types #1249 as RFC 1.

GraphQL.js: graphql/graphql-js#4934 implements all three behind experimentalAllowEmptyTypes.

@benjie

benjie commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

We agreed on option A, so I've merged the unions and interfaces into this PR and expanded our "odd duck" of unions to use the least-bad alternative syntax: union Foo = {}. I actually think this is a pretty solid syntax, because an empty union type really does conceptually represent an object with no fields. (Though really you can only ever use null because it has no valid __typename.)

@benjie benjie changed the title Allow empty object types Allow empty object, interface, and union types Nov 5, 2026
@benjie
benjie force-pushed the empty-object-types branch from 354b794 to 68e2b00 Compare November 5, 2026 21:43
@benjie

benjie commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

I've also added the requirement that Mutation must have at least one field (like Subscription). Query is allowed to be empty because a) Query is required, b) Query is how you do introspection, c) if you want a "mutation only" schema then you don't want to add any Query fields. This addresses

A union type may also be defined for an empty set of member types:

```graphql example
union EmptyUnion = {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@benjie Did we settle on this syntax? I remember a few other options were discussed yesterday, like using a keyword.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not officially, no, that would need WG consensus. If there are others you'd like us to consider, do propose them!

I think {} is a solid option though. {} is already used as an ASCII-only way of representing the empty set (rather than non-ASCII options like ∅) which is what we're representing here. We're also kind of representing an object with no properties, so it kind of makes sense there too. I think it's fairly straightforward, obvious, and we're making breaking changes to the SDL anyway so seems as good a time as any to introduce it.

One option is to just use union EmptyUnion to represent empty unions and allow it to be the "odd duck". But I think this is a cheap solution that enables some level of consistency.

This branch has not been deployed

No deployments
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 💡 Proposal (RFC 1) RFC Stage 1 (See CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The ability to represent empty objects Proposal: Do not require query as a root operation type

6 participants