At a glance
- Project
- GraphQL Spec
- Identifier
- #948
- Stage
- RFC X / Rejected
- Champion
- @benjie
- Updated
- 2025-07-04
- Latest activity
- Pull request closed on
- Source
- Pull request
Pull request description
This is a follow-up to #825 that proposes adding the @oneOf directive to object types (output objects).
This is a draft right now as I've not yet had time to think through it well enough, but it raises a few questions:
- The proposed resolution algorithm is a slight divergence from the status quo, omitting fields from the response rather than setting them null. This makes it align with #825, but is it desired? Should we change #825 to only require one non-null field rather than just one field?
- Should we allow aliases? The current proposed resolution algorithm ensures that every identical field requested on a
@oneOfselection set will get the same value, but it does so in a somewhat awkward way. Forbidding aliases could remove the need for this. - What happens if a
@oneOfis queried as part of a union? The proposed resolution algorithm allows for this by leaving it up to the implementation, I think this is probably best unless anyone has a better idea?
TODO:
- When validating the schema, forbid
@oneOfon operation types. - Tidy up the language around maps/accessing keys.
Note this PR is based off of #825, so this is probably the diff you want:
https://github.com/benjie/graphql-spec/compare/oneof-v2..oneof-output
Other notes:
- Seems like
@stream,@defer,@skipand@includeare all compatible with oneOf. - Aliases don't need to cause a problem; they'll make the client's life harder, but if it's the client requesting it then that's their problem :laughing:
- The fields on a
@oneOfdon't have their own traditional resolvers, instead the parent value must dictate which key/value was returned. This prevents confusion where the same field being requested multiple times ({ a1: a, a2: a, a3: a }) could result in different values - we explicitly prevent this from happening.
Timeline
July 2025
- Pull request closed on
- Marked as Rejected on by benjie
June 2022
- Advanced to RFC 0 on by leebyron
- Discussed in GraphQL WG
@oneOf update (20m, Benjie Gillam) 11. Recent changes: **Type.oneOf -> **Type.isOneOf and forbidding extend input Foo @oneOf 12. Effect on implementations of adding @oneOf directive: is it a breaking change? 13. Added @oneOf objects RFC - main question for input @oneOf is over presence vs non-presence
Meeting notes · GraphQL WG · 2022-06-02Added @oneOf objects RFC - main question for input @oneOf is over presence vs non-presence
Meeting notes · GraphQL WG · 2022-06-02
May 2022
- Top comment edited on by benjie
- @benjie committed "Typo" on
- Top comment edited on by benjie
- Pull request created on by benjie
- 2 commits pushed on
- @benjie committed "Spec edits for oneOf on output"
- @benjie committed "Fix resolution of __typename"
- @benjie committed "Remove out of date example" on
March 2022
- 4 commits pushed on
- @benjie committed "Merge branch 'main' into oneof-v2"
- @benjie committed "Remove Oneof Fields from spec"
- @benjie committed "Oneof -> OneOf"
- @benjie committed "Spellings"
January 2022
- @benjie committed "Update spec/Section 3 -- Type System.md" on
December 2021
- @benjie committed "Apply suggestions from code review" on
April 2021
- 2 commits pushed on
- @benjie committed "graphgl -> graphql"
- @benjie committed "Apply suggestions from @eapache's review"
March 2021
- 7 commits pushed on
- @benjie committed "Much stricter validation for oneof literals (with examples)"
- @benjie committed "Add missing coercion rule"
- @benjie committed "Clearer wording of oneof coercion rule"
- @benjie committed "Add more examples for clarity"
- @benjie committed "Rename introspection fields to oneOf"
- @benjie committed "Oneof's now require exactly one field/argument, and non-nullable vari…"
- @benjie committed "Remove extraneous newline"
February 2021
- @benjie committed "Fix typos (thanks @eapache!)" on
- 3 commits pushed on
- @benjie committed "Renumber list items"
- @benjie committed "@oneOf input objects"
- @benjie committed "@oneOf fields"