Skip to content

Commit e2a1132

Browse files
authored
Input Union: Tag each criteria with a letter (#643)
* Tag each criteria with a letter * Note letter identy
1 parent 6a155c1 commit e2a1132

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

rfcs/InputUnion.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,61 +140,63 @@ Hypothetical goals that a solution might attempt to fulfill. These goals will be
140140
* Preserve option value
141141
* Understandability is just as important as correctness
142142

143-
### GraphQL should contain a polymorphic Input type
143+
Each criteria is identified with a Letter so they can be referenced in the rest of the document. New criteria must be added to the end of the list.
144+
145+
### A) GraphQL should contain a polymorphic Input type
144146

145147
The premise of this RFC - GraphQL should contain a polymorphic Input type.
146148

147-
### Input polymorphism matches output polymorphism
149+
### B) Input polymorphism matches output polymorphism
148150

149151
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.
150152

151153
* 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.
152154

153-
### Doesn't inhibit [schema evolution](https://graphql.github.io/graphql-spec/draft/#sec-Validation.Type-system-evolution)
155+
### C) Doesn't inhibit [schema evolution](https://graphql.github.io/graphql-spec/draft/#sec-Validation.Type-system-evolution)
154156

155157
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.
156158

157-
### Any member type restrictions are validated in schema
159+
### D) Any member type restrictions are validated in schema
158160

159161
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).
160162

161-
### A member type may be a Leaf type
163+
### E) A member type may be a Leaf type
162164

163165
In addition to containing Input types, member type may also contain Leaf types like `Scalar`s or `Enum`s.
164166

165167
* 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`.
166168
* Potential solution: only allow a single built-in leaf type per input union.
167169
* Objection: Output polymorphism is restricted to Object types only. Supporting Leaf types in Input polymorphism would create a new inconsistency.
168170

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
170172

171173
Since the input object type is now a member of the input union, existing input objects being sent through should remain valid.
172174

173175
* 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.
174176
* Objection: achieving this by indicating a default type in the input field is verbose/potentially ugly.
175177

176-
### Input unions may include other input unions
178+
### G) Input unions may include other input unions
177179

178180
To ease development.
179181

180-
### Input unions should accept plain data from clients
182+
### H) Input unions should accept plain data from clients
181183

182184
Clients should be able to pass "natural" input data to unions without
183185
specially formatting it, adding extra metadata, or otherwise doing work.
184186

185-
### Input unions should be easy to upgrade from existing solutions
187+
### I) Input unions should be easy to upgrade from existing solutions
186188

187189
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.
188190

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
190192

191193
Preferably without loss of functionality.
192194

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
194196

195197
The less typing and fewer bytes transmitted, the better.
196198

197-
### Input unions should be performant for servers
199+
### L) Input unions should be performant for servers
198200

199201
Ideally a server does not have to do much computation to determine which concrete type is represented by an input.
200202

0 commit comments

Comments
 (0)