At a glance
- Identifier: #948
- Stage: RFC X / Rejected
- Champion: @benjie
- Latest activity: Spec PR closed on 2025-07-03
- Spec PR: https://github.com/graphql/graphql-spec/pull/948
Spec PR 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
- Spec PR closed on 2025-07-03
- Marked as Rejected on 2025-07-03 by benjie
June 2022
- Advanced to RFC 0 on 2022-06-02 by leebyron
- Added to WG agenda on 2022-06-02
- Mentioned in WG notes on 2022-06-02
May 2022
- Top comment edited on 2022-05-24 by benjie
- @benjie committed "Typo" on 2022-05-24
- Top comment edited on 2022-05-23 by benjie
- Spec PR created on 2022-05-23 by benjie
- 2 commits pushed on 2022-05-23
- @benjie committed "Spec edits for oneOf on output"
- @benjie committed "Fix resolution of __typename"
- @benjie committed "Remove out of date example" on 2022-05-06
March 2022
- 4 commits pushed on 2022-03-22
- @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 2022-01-04
December 2021
- @benjie committed "Apply suggestions from code review" on 2021-12-23
April 2021
- 2 commits pushed on 2021-04-08
- @benjie committed "graphgl -> graphql"
- @benjie committed "Apply suggestions from @eapache's review"
March 2021
- 7 commits pushed on 2021-03-06
- @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 2021-02-26
- 3 commits pushed on 2021-02-19
- @benjie committed "Renumber list items"
- @benjie committed "@oneOf input objects"
- @benjie committed "@oneOf fields"