@@ -231,7 +231,7 @@ Adding a new member type to an Input Union or doing any non-breaking change to e
231
231
232
232
| [ 1] [ solution-1 ] | [ 2] [ solution-2 ] | [ 3] [ solution-3 ] | [ 4] [ solution-4 ] | [ 5] [ solution-5 ] |
233
233
| ----| ----| ----| ----| ----|
234
- | ✅ | ✅ | 🚫 | ⚠️ | ✅ |
234
+ | ✅ | ⚠ | 🚫 | ⚠️ | ✅ |
235
235
236
236
Criteria score: 🥇
237
237
@@ -390,6 +390,17 @@ For example, GraphiQL should successfully render when pointed at a schema which
390
390
391
391
Criteria score: 🥈
392
392
393
+ ## 🎯 O. Unconstrained combination of input types to unions
394
+
395
+ It should be possible to combine existing or new input types to unions freely and with ease.
396
+ Adding an input to one or more unions should not require extraneous changes, constrain or be constrained by schema design.
397
+
398
+ | [ 1] [ solution-1 ] | [ 2] [ solution-2 ] | [ 3] [ solution-3 ] | [ 4] [ solution-4 ] | [ 5] [ solution-5 ] |
399
+ | ----| ----| ----| ----| ----|
400
+ | ✅️ | 🚫️ | ❔ | 🚫 | ✅ |
401
+
402
+ Criteria score: 🥇
403
+
393
404
# 🚧 Possible Solutions
394
405
395
406
The community has imagined a variety of possible solutions, synthesized here.
@@ -469,6 +480,8 @@ type Mutation {
469
480
* 🚫 Parsers will not recognize the `inputunion` keyword
470
481
* [N. Existing code generated tooling is backwards compatible with Introspection additions][criteria-n]
471
482
* ❔ Not evaluated
483
+ * [O. Unconstrained combination of input types to unions][criteria-o]
484
+ * ✅ Adding or removing an input type to a union has no extraneous effects on schema design
472
485
473
486
## 💡 2. Explicit configurable Discriminator field
474
487
@@ -555,6 +568,7 @@ inputunion AnimalInput @discriminator(field: "species") =
555
568
* ✅ Data structures can mirror eachother.
556
569
* [ C. Doesn't inhibit schema evolution] [ criteria-c ]
557
570
* ✅ Discriminator is explicit.
571
+ * ⚠️ Adding an existing input type to an input union requires it to add the non-null discriminator field
558
572
* [ D. Any member type restrictions are validated in schema] [ criteria-d ]
559
573
* ✅ Schema validation can check that all members of the input union have the discriminator field
560
574
* [ E. A member type may be a Leaf type] [ criteria-e ]
@@ -576,6 +590,10 @@ inputunion AnimalInput @discriminator(field: "species") =
576
590
* 🚫 Parsers will not recognize the ` inputunion ` keyword
577
591
* [ N. Existing code generated tooling is backwards compatible with Introspection additions] [ criteria-n ]
578
592
* ❔ Not evaluated
593
+ * [ O. Unconstrained combination of input types to unions] [ criteria-o ]
594
+ * 🚫 Adding an input type to a union requires that it has the non-null discriminator field
595
+ * The input might already have a field with the same name, but a different type
596
+ * Reusing input types in multiple input unions can become unwieldy
579
597
580
598
## 💡 3. Order based discrimination
581
599
@@ -663,6 +681,8 @@ type Mutation {
663
681
* 🚫 Parsers will not recognize the `inputunion` keyword
664
682
* [N. Existing code generated tooling is backwards compatible with Introspection additions][criteria-n]
665
683
* ❔ Not evaluated
684
+ * [O. Unconstrained combination of input types to unions][criteria-o]
685
+ * ❔ Not evaluated
666
686
667
687
## 💡 4. Structural uniqueness
668
688
@@ -733,6 +753,7 @@ input DogInput {
733
753
* ⚠️ Restrictions on required fields may prevent matching output types
734
754
* [C . Doesn 't inhibit schema evolution][criteria-c]
735
755
* ⚠️ Inputs may be forced to include extraneous fields to ensure uniqueness.
756
+ * ⚠️ Making a field nullable may be impossible without losing uniqueness
736
757
* [D. Any member type restrictions are validated in schema][criteria-d]
737
758
* ✅ A "uniqueness" algorithm must be applied during schema validation
738
759
* [E. A member type may be a Leaf type][criteria-e]
@@ -753,6 +774,8 @@ input DogInput {
753
774
* 🚫 Parsers will not recognize the `inputunion` keyword
754
775
* [N. Existing code generated tooling is backwards compatible with Introspection additions][criteria-n]
755
776
* ❔ Not evaluated
777
+ * [O. Unconstrained combination of input types to unions][criteria-o]
778
+ * 🚫 Input types with similar fields may not be able to be combined without breaking changes
756
779
757
780
## 💡 5. One Of (Tagged Union)
758
781
@@ -827,6 +850,8 @@ type Mutation {
827
850
* ✅ Proposal uses a simple directive ; directive parsing is widely supported
828
851
* [N . Existing code generated tooling is backwards compatible with Introspection additions ][criteria -n ]
829
852
* ✅ Existing code generation tools will degrade gracefully to a regular input object
853
+ * [O . Unconstrained combination of input types to unions ][criteria -o ]
854
+ * ✅ Adding or removing input types to a tagged union requires no extraneous effort
830
855
831
856
### Summary of spec changes
832
857
@@ -857,6 +882,7 @@ A quick glance at the evaluation results. Remember that passing or failing a spe
857
882
| [L ][criteria -l ] 🥉 | ❔ | ❔ | ❔ | ❔ | ✅ |
858
883
| [M ][criteria -m ] 🥈 | 🚫 | 🚫 | 🚫 | 🚫 | ✅ |
859
884
| [N ][criteria -n ] 🥈 | ❔ | ❔ | ❔ | ❔ | ✅ |
885
+ | [O ][criteria -o ] 🥈 | ✅️ | 🚫️ | ❔ | 🚫 | ✅ |
860
886
861
887
[criteria -a ]: #-a-graphql-should-contain-a-polymorphic-input-type
862
888
[criteria -b ]: #-b-input-polymorphism-matches-output-polymorphism
@@ -872,6 +898,7 @@ A quick glance at the evaluation results. Remember that passing or failing a spe
872
898
[criteria -l ]: #-l-input-unions-should-be-performant-for-servers
873
899
[criteria -m ]: #-m-existing-sdl-parsers-are-backwards-compatible-with-sdl-additions
874
900
[criteria -n ]: #-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions
901
+ [criteria -o ]: #-o-unconstrained-combination-of-input-types-to-unions
875
902
876
903
[solution -1]: #-1-explicit-__typename-discriminator-field
877
904
[solution -2]: #-2-explicit-configurable-discriminator-field
0 commit comments