At a glance
- Identifier: #948
- Stage: RFC X / Rejected
- Champion: @benjie
- Latest activity: Added to WG agenda on 2022-06-02
- 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
- Added to WG agenda on 2022-06-02
- Mentioned in WG notes on 2022-06-02
- Commit pushed on 2022-05-24 by benjie: Typo
- 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"
- Commit pushed on 2022-05-06 by benjie: Remove out of date example
- 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"
- Commit pushed on 2022-01-04 by benjie: Update spec/Section 3 -- Type System.md
- Commit pushed on 2021-12-23 by benjie: Apply suggestions from code review
- 2 commits pushed on 2021-04-08:
- benjie committed "graphgl -> graphql"
- benjie committed "Apply suggestions from @eapache's review"
- 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"
- Commit pushed on 2021-02-26 by benjie: Fix typos (thanks @eapache!)
- 3 commits pushed on 2021-02-19:
- benjie committed "Renumber list items"
- benjie committed "@oneOf input objects"
- benjie committed "@oneOf fields"