@@ -286,15 +286,37 @@ FieldsInSetCanMerge(set) :
286
286
* Let {fieldsForName} be the set of selections with a given response name in
287
287
{set} including visiting fragments and inline fragments.
288
288
* Given each pair of members {fieldA} and {fieldB} in {fieldsForName}:
289
+ * {SameResponseShape(fieldA, fieldB)} must be true.
289
290
* If the parent types of {fieldA} and {fieldB} are equal or if either is not
290
291
an Object Type:
291
292
* {fieldA} and {fieldB} must have identical field names.
292
- * {fieldA} and {fieldB} must have identical return type.
293
293
* {fieldA} and {fieldB} must have identical sets of arguments.
294
294
* Let {mergedSet} be the result of adding the selection set of {fieldA}
295
295
and the selection set of {fieldB}.
296
296
* {FieldsInSetCanMerge(mergedSet)} must be true.
297
297
298
+ SameResponseShape(fieldA, fieldB) :
299
+ * Let {typeA} be the return type of {fieldA}.
300
+ * Let {typeB} be the return type of {fieldB}.
301
+ * If {typeA} or {typeB} is Non-Null.
302
+ * {typeA} and {typeB} must both be Non-Null.
303
+ * Let {typeA} be the nullable type of {typeA}
304
+ * Let {typeB} be the nullable type of {typeB}
305
+ * If {typeA} or {typeB} is List.
306
+ * {typeA} and {typeB} must both be List.
307
+ * Let {typeA} be the item type of {typeA}
308
+ * Let {typeB} be the item type of {typeB}
309
+ * Repeat from step 3.
310
+ * If {typeA} or {typeB} is Scalar or Enum.
311
+ * {typeA} and {typeB} must be the same type.
312
+ * Assert: {typeA} and {typeB} are both composite types.
313
+ * Let {mergedSet} be the result of adding the selection set of {fieldA} and
314
+ the selection set of {fieldB}.
315
+ * Let {fieldsForName} be the set of selections with a given response name in
316
+ {mergedSet} including visiting fragments and inline fragments.
317
+ * Given each pair of members {subfieldA} and {subfieldB} in {fieldsForName}:
318
+ * {SameResponseShape(subfieldA, subfieldB)} must be true.
319
+
298
320
** Explanatory Text **
299
321
300
322
If multiple fields selections with the same response names are encountered
@@ -369,16 +391,16 @@ fragment differingArgs on Dog {
369
391
}
370
392
```
371
393
372
- The following would not merge together, however both cannot be encountered
373
- against the same object:
394
+ The following fields would not merge together, however both cannot be
395
+ encountered against the same object, so they are safe :
374
396
375
397
``` graphql
376
398
fragment safeDifferingFields on Pet {
377
399
... on Dog {
378
- name : nickname
400
+ volume : barkVolume
379
401
}
380
402
... on Cat {
381
- name
403
+ volume : meowVolume
382
404
}
383
405
}
384
406
@@ -392,6 +414,21 @@ fragment safeDifferingArgs on Pet {
392
414
}
393
415
```
394
416
417
+ However, the field responses must be shapes which can be merged. For example,
418
+ scalar values must not differ. In this example, ` someValue ` might be a ` String `
419
+ or an ` Int ` :
420
+
421
+ ``` !graphql
422
+ fragment conflictingDifferingResponses on Pet {
423
+ ... on Dog {
424
+ someValue: nickname
425
+ }
426
+ ... on Cat {
427
+ someValue: meowVolume
428
+ }
429
+ }
430
+ ```
431
+
395
432
396
433
### Leaf Field Selections
397
434
0 commit comments