You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### B) Input polymorphism matches output polymorphism
148
150
149
151
Any data structure that can be modeled with output type polymorphism should be able to be mirrored with Input polymorphism. Minimal transformation of outputs should be required to send a data structure back as inputs.
150
152
151
153
* Objection: input types and output types are distinct. Output types support aliases and arguments whereas input types do not. Marking an output field as non-nullable is a non-breaking change, but marking an input field as non-nullable is a breaking change.
### C) Doesn't inhibit [schema evolution](https://graphql.github.io/graphql-spec/draft/#sec-Validation.Type-system-evolution)
154
156
155
157
Adding a new member type to an Input Union or doing any non-breaking change to existing member types does not result in breaking change. For example, adding a new optional field to member type or changing a field from non-nullable to nullable does not break previously valid client operations.
156
158
157
-
### Any member type restrictions are validated in schema
159
+
### D) Any member type restrictions are validated in schema
158
160
159
161
If a solution places any restrictions on member types, compliance with these restrictions should be fully validated during schema building (analagous to how interfaces enforce restrictions on member types).
160
162
161
-
### A member type may be a Leaf type
163
+
### E) A member type may be a Leaf type
162
164
163
165
In addition to containing Input types, member type may also contain Leaf types like `Scalar`s or `Enum`s.
164
166
165
167
* Objection: multiple Leaf types serialize the same way, making it impossible to distinguish the type without additional information. For example, a `String`, `ID` and `Enum`.
166
168
* Potential solution: only allow a single built-in leaf type per input union.
167
169
* Objection: Output polymorphism is restricted to Object types only. Supporting Leaf types in Input polymorphism would create a new inconsistency.
168
170
169
-
### Changing field from an input type to an input union including that type is non-breaking
171
+
### F) Changing field from an input type to a polymorphic type including that type is non-breaking
170
172
171
173
Since the input object type is now a member of the input union, existing input objects being sent through should remain valid.
172
174
173
175
* Objection: achieving this by indicating the default in the union (either explicitly or implicitly via the order) is undesirable as it may require multiple equivalent unions being created where only the default differs.
174
176
* Objection: achieving this by indicating a default type in the input field is verbose/potentially ugly.
175
177
176
-
### Input unions may include other input unions
178
+
### G) Input unions may include other input unions
177
179
178
180
To ease development.
179
181
180
-
### Input unions should accept plain data from clients
182
+
### H) Input unions should accept plain data from clients
181
183
182
184
Clients should be able to pass "natural" input data to unions without
183
185
specially formatting it, adding extra metadata, or otherwise doing work.
184
186
185
-
### Input unions should be easy to upgrade from existing solutions
187
+
### I) Input unions should be easy to upgrade from existing solutions
186
188
187
189
Many people in the wild are solving the need for input unions with validation at run-time (e.g. using the "tagged union" pattern). Formalising support for these existing patterns in a non-breaking way would enable existing schemas to become retroactively more type-safe.
188
190
189
-
### A GraphQL schema that supports input unions can be queried by older GraphQL clients
191
+
### J) A GraphQL schema that supports input unions can be queried by older GraphQL clients
190
192
191
193
Preferably without loss of functionality.
192
194
193
-
### Input unions should be expressed efficiently in the query and on the wire
195
+
### K) Input unions should be expressed efficiently in the query and on the wire
194
196
195
197
The less typing and fewer bytes transmitted, the better.
196
198
197
-
### Input unions should be performant for servers
199
+
### L) Input unions should be performant for servers
198
200
199
201
Ideally a server does not have to do much computation to determine which concrete type is represented by an input.
0 commit comments