OneOf Objects
At a glance​
- Identifier: #948
- Stage: RFC0: Strawman
- Champion: @benjie
- PR: OneOf Objects
Timeline​
- Added to 2022-06-02 WG agenda
- Mentioned in 2022-06-02 WG notes
- Commit pushed: Typo on 2022-05-24 by @benjie
- Spec PR created on 2022-05-23 by benjie
- 2 commits pushed on 2022-05-23:
- Commit pushed: Remove out of date example on 2022-05-06 by @benjie
- 4 commits pushed on 2022-03-22:
- Commit pushed: Update spec/Section 3 -- Type System.md on 2022-01-04 by @benjie
- Commit pushed: Apply suggestions from code review on 2021-12-23 by @benjie
- 2 commits pushed on 2021-04-08:
- 7 commits pushed on 2021-03-06:
- Much stricter validation for oneof literals (with examples) by @benjie
- Add missing coercion rule by @benjie
- Clearer wording of oneof coercion rule by @benjie
- Add more examples for clarity by @benjie
- Rename introspection fields to oneOf by @benjie
- Oneof's now require exactly one field/argument, and non-nullable vari… by @benjie
- Remove extraneous newline by @benjie
- Commit pushed: Fix typos (thanks @eapache!) on 2021-02-26 by @benjie
- 3 commits pushed on 2021-02-19:
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
@oneOf
selection 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
@oneOf
is 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
@oneOf
on 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
,@skip
and@include
are 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 😆
- The fields on a
@oneOf
don'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.