Skip to content

Commit 9e4918a

Browse files
benjiebinaryseed
authored andcommitted
InputUnion: K, L, M, N evaluations and spec summary for @oneOf (#660)
* @onefield evaluations * Add a 'summary of spec changes' section * Add placeholder evaluations for other solutions
1 parent b55e497 commit 9e4918a

File tree

1 file changed

+56
-8
lines changed

1 file changed

+56
-8
lines changed

rfcs/InputUnion.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ The less typing and fewer bytes transmitted, the better.
301301

302302
| [1](#-1-explicit-__typename-discriminator-field) | [2](#-2-explicit-configurable-discriminator-field) | [3](#-3-order-based-discrimination) | [4](#-4-structural-uniqueness) | [5](#-5-one-of-tagged-union) |
303303
|----|----|----|----|----|
304-
||||| |
304+
||||| |
305305

306306
## 🎯 L. Input unions should be performant for servers
307307

@@ -311,23 +311,23 @@ Ideally a server does not have to do much computation to determine which concret
311311

312312
| [1](#-1-explicit-__typename-discriminator-field) | [2](#-2-explicit-configurable-discriminator-field) | [3](#-3-order-based-discrimination) | [4](#-4-structural-uniqueness) | [5](#-5-one-of-tagged-union) |
313313
|----|----|----|----|----|
314-
||||| |
314+
||||| |
315315

316316
## 🎯 M. Existing SDL parsers are backwards compatible with SDL additions
317317

318318
Common tools that parse GraphQL SDL should not fail when pointed at a schema which supports polymorphic input types.
319319

320320
| [1](#-1-explicit-__typename-discriminator-field) | [2](#-2-explicit-configurable-discriminator-field) | [3](#-3-order-based-discrimination) | [4](#-4-structural-uniqueness) | [5](#-5-one-of-tagged-union) |
321321
|----|----|----|----|----|
322-
||||| |
322+
||||| |
323323

324324
## 🎯 N. Existing code generated tooling is backwards compatible with Introspection additions
325325

326326
For example, GraphiQL should successfully render when pointed at a schema which contains polymorphic input types. It should continue to function even if it can't support the polymorphic input type.
327327

328328
| [1](#-1-explicit-__typename-discriminator-field) | [2](#-2-explicit-configurable-discriminator-field) | [3](#-3-order-based-discrimination) | [4](#-4-structural-uniqueness) | [5](#-5-one-of-tagged-union) |
329329
|----|----|----|----|----|
330-
||||| |
330+
||||| |
331331

332332
# 🚧 Possible Solutions
333333

@@ -398,6 +398,14 @@ type Mutation {
398398
* ✅ Defaulting to the previous input type enables upgrading
399399
* [J. A GraphQL schema that supports input unions can be queried by older GraphQL clients](#-j-a-graphql-schema-that-supports-input-unions-can-be-queried-by-older-graphql-clients)
400400
* ✅ Changes are additive only
401+
* [K. Input unions should be expressed efficiently in the query and on the wire](#-k-input-unions-should-be-expressed-efficiently-in-the-query-and-on-the-wire)
402+
* ❔ Not evaluated
403+
* [L. Input unions should be performant for servers](#-l-input-unions-should-be-performant-for-servers)
404+
* ❔ Not evaluated
405+
* [M. Existing SDL parsers are backwards compatible with SDL additions](#-m-existing-sdl-parsers-are-backwards-compatible-with-sdl-additions)
406+
* ❔ Not evaluated
407+
* [N. Existing code generated tooling is backwards compatible with Introspection additions](#-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions)
408+
* ❔ Not evaluated
401409

402410
## 💡 2. Explicit configurable Discriminator field
403411

@@ -526,6 +534,14 @@ input DogInput {
526534
* ✅ Defaulting to the previous input type enables upgrading
527535
* [J. A GraphQL schema that supports input unions can be queried by older GraphQL clients](#-j-a-graphql-schema-that-supports-input-unions-can-be-queried-by-older-graphql-clients)
528536
* ✅ Changes are additive only
537+
* [K. Input unions should be expressed efficiently in the query and on the wire](#-k-input-unions-should-be-expressed-efficiently-in-the-query-and-on-the-wire)
538+
* ❔ Not evaluated
539+
* [L. Input unions should be performant for servers](#-l-input-unions-should-be-performant-for-servers)
540+
* ❔ Not evaluated
541+
* [M. Existing SDL parsers are backwards compatible with SDL additions](#-m-existing-sdl-parsers-are-backwards-compatible-with-sdl-additions)
542+
* ❔ Not evaluated
543+
* [N. Existing code generated tooling is backwards compatible with Introspection additions](#-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions)
544+
* ❔ Not evaluated
529545

530546
## 💡 3. Order based discrimination
531547

@@ -603,6 +619,14 @@ type Mutation {
603619
* ✅ Listing the old input type first enables enables upgrading
604620
* [J. A GraphQL schema that supports input unions can be queried by older GraphQL clients](#-j-a-graphql-schema-that-supports-input-unions-can-be-queried-by-older-graphql-clients)
605621
* ✅ Changes are additive only
622+
* [K. Input unions should be expressed efficiently in the query and on the wire](#-k-input-unions-should-be-expressed-efficiently-in-the-query-and-on-the-wire)
623+
* ❔ Not evaluated
624+
* [L. Input unions should be performant for servers](#-l-input-unions-should-be-performant-for-servers)
625+
* ❔ Not evaluated
626+
* [M. Existing SDL parsers are backwards compatible with SDL additions](#-m-existing-sdl-parsers-are-backwards-compatible-with-sdl-additions)
627+
* ❔ Not evaluated
628+
* [N. Existing code generated tooling is backwards compatible with Introspection additions](#-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions)
629+
* ❔ Not evaluated
606630

607631
## 💡 4. Structural uniqueness
608632

@@ -685,6 +709,14 @@ input DogInput {
685709
* ⚠️ All new types added to the union must differ structurally from the previous type
686710
* [J. A GraphQL schema that supports input unions can be queried by older GraphQL clients](#-j-a-graphql-schema-that-supports-input-unions-can-be-queried-by-older-graphql-clients)
687711
* ✅ Changes are additive only
712+
* [K. Input unions should be expressed efficiently in the query and on the wire](#-k-input-unions-should-be-expressed-efficiently-in-the-query-and-on-the-wire)
713+
* ❔ Not evaluated
714+
* [L. Input unions should be performant for servers](#-l-input-unions-should-be-performant-for-servers)
715+
* ❔ Not evaluated
716+
* [M. Existing SDL parsers are backwards compatible with SDL additions](#-m-existing-sdl-parsers-are-backwards-compatible-with-sdl-additions)
717+
* ❔ Not evaluated
718+
* [N. Existing code generated tooling is backwards compatible with Introspection additions](#-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions)
719+
* ❔ Not evaluated
688720

689721
## 💡 5. One Of (Tagged Union)
690722

@@ -749,7 +781,23 @@ type Mutation {
749781
* ✅ No migration required, as this pattern is already possible
750782
* [J. A GraphQL schema that supports input unions can be queried by older GraphQL clients](#-j-a-graphql-schema-that-supports-input-unions-can-be-queried-by-older-graphql-clients)
751783
* ✅ Changes are additive only
784+
* [K. Input unions should be expressed efficiently in the query and on the wire](#-k-input-unions-should-be-expressed-efficiently-in-the-query-and-on-the-wire)
785+
* ✅ Indication of the type can be done in 6 additional JSON characters per value (e.g. `{"a":VALUE_HERE}`) and would compress easily.
786+
* [L. Input unions should be performant for servers](#-l-input-unions-should-be-performant-for-servers)
787+
* ✅ Type is easily determined by looking up the specified field name
788+
* [M. Existing SDL parsers are backwards compatible with SDL additions](#-m-existing-sdl-parsers-are-backwards-compatible-with-sdl-additions)
789+
* ✅ Proposal uses a simple directive; directive parsing is widely supported
790+
* [N. Existing code generated tooling is backwards compatible with Introspection additions](#-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions)
791+
* ✅ Existing code generation tools will degrade gracefully to a regular input object
792+
793+
### Summary of spec changes
794+
795+
- **SDL**: enable use of `@oneOf` directive on input object type definitions
796+
- **Introspection**: add `requiresExactlyOneField: Boolean` field to `__Type` type
797+
- **Schema validation**: all fields on a `@oneOf` input type must be nullable, and must not have defaults
798+
- **Operation validation**: when validating a `@oneOf` input object, assert that exactly one field was specified
752799

800+
[The full spec changes can be seen here](https://github.com/graphql/graphql-spec/pull/586/files).
753801

754802
# 🏆 Evaluation Overview
755803

@@ -767,7 +815,7 @@ A quick glance at the evaluation results. Remember that passing or failing a spe
767815
| [H](#-h-input-unions-should-accept-plain-data) | ⚠️ | ⚠️ ||| ⚠️ |
768816
| [I](#-i-input-unions-should-be-easy-to-upgrade-from-existing-solutions) | ✅⚠️ | ✅⚠️ || ⚠️ ||
769817
| [J](#-j-a-graphql-schema-that-supports-input-unions-can-be-queried-by-older-graphql-clients) ||||||
770-
| [K](#-k-input-unions-should-be-expressed-efficiently-in-the-query-and-on-the-wire) ||||| |
771-
| [L](#-l-input-unions-should-be-performant-for-servers) ||||| |
772-
| [M](#-m-existing-sdl-parsers-are-backwards-compatible-with-sdl-additions) ||||| |
773-
| [N](#-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions) ||||| |
818+
| [K](#-k-input-unions-should-be-expressed-efficiently-in-the-query-and-on-the-wire) ||||| |
819+
| [L](#-l-input-unions-should-be-performant-for-servers) ||||| |
820+
| [M](#-m-existing-sdl-parsers-are-backwards-compatible-with-sdl-additions) ||||| |
821+
| [N](#-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions) ||||| |

0 commit comments

Comments
 (0)