Skip to content

Commit 04cd832

Browse files
authored
Comments on InputUnion RFC (#817)
* Comments on the proposal Hi, thanks for this extensive and in-depth work. I will try to keep my comments concise (which might make them sound agressive, apologies if that's the case, it's definitely not the intent) This PR touches one of the most challengeable founding philosophical choices of GraphQL: having 2 different type systems for input and output. I understand that the sender -> receiver relation is an unbalanced one: the sender has obligations, the receiver has options. However: - ALL GraphQL users use programming languages (Javascript, Java, C#, Python...) which make no difference between input and output types - I actually don't know any other protocol that does that (is there one?) - having 2 different type systems for input and output solves (does it?) an implementer problem, not a user problem The lack of polymorphism on input is only a side-effect of the aformentioned original choice. In an unreal world, rather than tweak GraphQL to fix that, it would be time for GraphQL2, unifying input and output types (amongst other improvements). That's very unlikely to happen, but saying so helps forming an opinion on the various proposals: - adding yet another polymorphic construct only available on input 'smells' like increasing confusion - it would increase the gap between input and output type systems, rather than reduce it From there, I think proposal #5 @OneOf is the most useful one: - it acts as a constraint on existing type constructs rather than yet another type construct - it expresses the required behavior much better than proposal #7 * Comments on the proposal Hi, thanks for this extensive and in-depth work. I will try to keep my comments concise (which might make them sound agressive, apologies if that's the case, it's definitely not the intent) This PR touches one of the most challengeable founding philosophical choices of GraphQL: having 2 different type systems for input and output. I understand that the sender -> receiver relation is an unbalanced one: the sender has obligations, the receiver has options. However: - ALL GraphQL users use programming languages (Javascript, Java, C#, Python...) which make no difference between input and output types - I actually don't know any other protocol that does that (is there one?) - having 2 different type systems for input and output solves (does it?) an implementer problem, not a user problem The lack of polymorphism on input is only a side-effect of the aformentioned original choice. In an unreal world, rather than tweak GraphQL to fix that, it would be time for GraphQL2, unifying input and output types (amongst other improvements). That's very unlikely to happen, but saying so helps forming an opinion on the various proposals: - adding yet another polymorphic construct only available on input 'smells' like increasing confusion - it would increase the gap between input and output type systems, rather than reduce it From there, I think proposal #5 @OneOf is the most useful one: - it acts as a constraint on existing type constructs rather than yet another type construct - it expresses the required behavior much better than proposal #7 * Update InputUnion.md * clean up merge dirt
1 parent 8db7763 commit 04cd832

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

rfcs/InputUnion.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,17 @@ When an invalid schema or invalid query are used, it should be obvious what went
438438

439439
Criteria score: 🥉
440440

441+
## 🎯 Q. No new polymorphic type construct should be introduced
442+
443+
The lack of polymorphism on input is only a side-effect of having 2 different type systems for input and output, a somewhat confusing GraphQL specificity (all mainstream programming language and API protocol use the same types for input and output).
444+
Adding a new construct for polymorphism support on input 'smells' like increasing confusion, and would increase the gap between input and output type systems, rather than reduce it.
445+
446+
| [1][solution-1] | [2][solution-2] | [3][solution-3] | [4][solution-4] | [5][solution-5] | [6][solution-6] | [7][solution-7]
447+
|----|----|----|----|----|----|----|
448+
| 🚫️ | 🚫️ || 🚫️ ||| 🚫️ |
449+
450+
Criteria score: 🥇
451+
441452
# 🚧 Possible Solutions
442453

443454
The community has imagined a variety of possible solutions, synthesized here.
@@ -522,6 +533,8 @@ type Mutation {
522533
* ✅ Adding or removing an input type to a union has no extraneous effects on schema design
523534
* [P. Error states and messages should be clear and helpful][criteria-p]
524535
* ✅
536+
* [Q. No new polymorphic type construct should be introduced][criteria-q]
537+
* 🚫️ ``ìnputunion```is a new type construct
525538

526539
## 💡 2. Explicit configurable Discriminator field
527540

@@ -636,6 +649,8 @@ inputunion AnimalInput @discriminator(field: "species") =
636649
* Reusing input types in multiple input unions can become unwieldy
637650
* [P. Error states and messages should be clear and helpful][criteria-p]
638651
*
652+
* [Q. No new polymorphic type construct should be introduced][criteria-q]
653+
* 🚫️ ``ìnputunion```is a new type construct
639654

640655
## 💡 3. Order based discrimination
641656

@@ -727,6 +742,8 @@ type Mutation {
727742
* ❔ Not evaluated
728743
* [P. Error states and messages should be clear and helpful][criteria-p]
729744
* ⚠️ Order-based discrimination can lead to some subtle issues based on when one type is chosen over another.
745+
* [Q. No new polymorphic type construct should be introduced][criteria-q]
746+
* ✅ No new construct
730747

731748
## 💡 4. Structural uniqueness
732749

@@ -822,6 +839,8 @@ input DogInput {
822839
* 🚫 Input types with similar fields may not be able to be combined without breaking changes
823840
* [P. Error states and messages should be clear and helpful][criteria-p]
824841
* 🚫 Structural uniqueness checks are very complex and have many hard-to-describe failure states.
842+
* [Q. No new polymorphic type construct should be introduced][criteria-q]
843+
* 🚫️ ``ìnputunion```is a new type construct
825844

826845
## 💡 5. One Of (Tagged Union)
827846

@@ -904,6 +923,8 @@ type Mutation {
904923
* ✅ Adding or removing input types to a tagged union requires no extraneous effort
905924
* [P. Error states and messages should be clear and helpful][criteria-p]
906925
* ✅
926+
* [Q. No new polymorphic type construct should be introduced][criteria-q]
927+
* ✅
907928

908929
### Summary of spec changes
909930

@@ -1026,6 +1047,8 @@ https://github.com/graphql/graphql-spec/pull/733
10261047
* ✅ Adding or removing member fields to a tagged type requires no extraneous effort and has no non-local consequences
10271048
* [P. Error states and messages should be clear and helpful][criteria-p]
10281049
* ✅
1050+
* [Q. No new polymorphic type construct should be introduced][criteria-q]
1051+
* 🚫️ ``tagged```is a new type construct
10291052

10301053
### Summary of spec changes
10311054

@@ -1063,6 +1086,7 @@ A quick glance at the evaluation results. Remember that passing or failing a spe
10631086
| [N][criteria-n] 🥈 | ✅⚠️ | ✅⚠️ | ✅⚠️ | ✅⚠️ | ✅ | ? | ✅⚠️ |
10641087
| [O][criteria-o] 🥈 | ✅️ | 🚫️ | ❔ | 🚫 | ✅ | ? | ✅ |
10651088
| [P][criteria-p] 🥉 | ✅️ | ✅️ | ⚠️ | 🚫 | ✅ | ❔ | ✅ |
1089+
| [Q][criteria-q] 🥉 | 🚫 | 🚫 | ✅️ | 🚫 | ✅ | ❔ | 🚫 |
10661090

10671091
[criteria-a]: #-a-graphql-should-contain-a-polymorphic-input-type
10681092
[criteria-b]: #-b-input-polymorphism-matches-output-polymorphism
@@ -1080,6 +1104,7 @@ A quick glance at the evaluation results. Remember that passing or failing a spe
10801104
[criteria-n]: #-n-existing-code-generated-tooling-is-backwards-compatible-with-introspection-additions
10811105
[criteria-o]: #-o-unconstrained-combination-of-input-types-to-unions
10821106
[criteria-p]: #-p-error-states-and-messages-should-be-clear-and-helpful
1107+
[criteria-q]: #-q-no-new-polymorphic-type-construct-should-be-introduced
10831108

10841109
[solution-1]: #-1-explicit-__typename-discriminator-field
10851110
[solution-2]: #-2-explicit-configurable-discriminator-field
@@ -1100,3 +1125,4 @@ proposed as an evolution of Solution 5, and is currently the leading solution.
11001125
* ~~[1][solution-1]~~
11011126
* ~~[2][solution-2]~~
11021127
* ~~[3][solution-3] / [4][solution-4]~~
1128+

0 commit comments

Comments
 (0)