Skip to content

Allow empty input object types - #1249

Open
DaleSeo wants to merge 5 commits into
graphql:empty-object-typesfrom
DaleSeo:empty-input-objects
Open

DaleSeo wants to merge 5 commits into
graphql:empty-object-typesfrom
DaleSeo:empty-input-objects

Conversation

@DaleSeo

@DaleSeo DaleSeo commented Oct 28, 2026 •

Copy link
Copy Markdown

Follow up to:

Today, an input object type must define at least one input field. This proposal removes that requirement, making input Filter {} a valid definition. It follows the approach the Nov 5 Working Group agreed for #1228: {} defines an empty type, and a bare input Filter stays incomplete until an extension completes it.

The motivation comes from the Schema Search RFC (graphql/ai-wg#187). It describes a service that returns a valid subset of its schema as SDL in response to a natural language query. A slice may omit optional arguments and optional input fields, but it must keep the required ones. Take this excerpt of a full schema:

type Query {
  issues(filter: IssueFilter!): [Issue!]!
}
input IssueFilter {
  state: IssueState
  assignee: ID
  labels: [String!]
}
type Issue {
  title: String!
  body: String
  state: IssueState!
  assignee: User
  labels: [Label!]!
  createdAt: DateTime!
}

For a question like "list the issue titles", the slice must keep filter because it is required, so it must also define IssueFilter. All of its fields are optional and none matter to the question, so the slice leaves it empty:

type Query {
  issues(filter: IssueFilter!): [Issue!]!
}
input IssueFilter {}
type Issue {
  title: String!
}

The model can then send issues(filter: {}), which is also valid against the full schema.

Under the current rule, this slice is invalid. The slicer has to either drop the issues field, hiding the entry point, or keep an input field the question does not need. Keeping one also pulls in its type:

input IssueFilter {
  state: IssueState
}
enum IssueState {
  OPEN
  CLOSED
}

If that field were another input object, its fields would follow too. This change lets the slice keep the reference with an empty definition, and the model can request IssueFilter later if it needs to filter.

It also removes one more reason a schema with all deprecated elements removed can become invalid, as mentioned in #1228 (comment).

GraphQL.js implementation: graphql/graphql-js#4934

@netlify

netlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit 4a971fe
🔍 Latest deploy log https://app.netlify.com/projects/graphql-spec-draft/deploys/6aede2cd9f97f3ac1275435e
😎 Deploy Preview https://deploy-preview-1249--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.

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

benjie commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

When thinking about what can be left out of an input type, all required fields must be retained. Consider:

input Foo {
  a: Int
  b: Int!
  c: Int = 1
  d: Int! = 1
  e: [Int!]
  f: [Int!]! = []
}

this could compress down to:

input Foo {
  b: Int!
}

but representing it as an empty input object would be invalid, a value could not be fed to that argument that the underlying schema (with all the input fields) would accept.


(Solved: feedback on PR description)

Incidentally the argument around your example:

type Query {
  issues(filter: IssueFilter): [Issue!]!
}

Under the current rule, the slicer has to either drop the issues field, hiding the entry point, or keep an arbitrary input field.

doesn't quite hold because it can be mapped by dropping the filter argument:

type Query {
  issues: [Issue!]!
}

Maybe you meant issues(filter: IssueFilter!): [Issue!]!?

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

benjie commented Oct 29, 2026

Copy link
Copy Markdown
Member

I think something went wrong with GitHub, some of the comments from my review posted but others remained "pending". I've submitted the review again, but now it looks like there might be duplicates... I'm not going to delete them in case that causes more headaches 😅

@DaleSeo

This comment was marked as resolved.

@DaleSeo

DaleSeo commented Nov 5, 2026

Copy link
Copy Markdown
Author

@benjie Updated to the unadorned form only, with no grammar change, to match where #1245 landed for unions. Happy to add {} back if the WG prefers it today. :)

@DaleSeo

DaleSeo commented Nov 6, 2026

Copy link
Copy Markdown
Author

@benjie Following the WG discussion, I switched this back to braces and matched the structure and wording of #1228: input Empty {} defines an empty input object, and a bare input Fieldless is incomplete until an extension completes it. OneOf input objects still need at least one field.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants