From 14c93e8cc713a9075db380565c724f7e9fdb4b2b Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Tue, 5 Apr 2016 19:13:27 -0700 Subject: [PATCH] Expand on validation rule for field selection merging This adds additional spec text to make it clear that field selection merging is a recursive operation. --- spec/Section 5 -- Validation.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/Section 5 -- Validation.md b/spec/Section 5 -- Validation.md index 477f3b42a..c58540d49 100644 --- a/spec/Section 5 -- Validation.md +++ b/spec/Section 5 -- Validation.md @@ -279,7 +279,10 @@ fragment directFieldSelectionOnUnion on CatOrDog { ** Formal Specification ** - * Let {set} be any selection set defined in the GraphQL document + * Let {set} be any selection set defined in the GraphQL document. + * {FieldsInSetCanMerge(set)} must be true. + +FieldsInSetCanMerge(set) : * Let {fieldsForName} be the set of selections with a given response name in {set} including visiting fragments and inline fragments. * Given each pair of members {fieldA} and {fieldB} in {fieldsForName}: @@ -288,13 +291,16 @@ fragment directFieldSelectionOnUnion on CatOrDog { * {fieldA} and {fieldB} must have identical field names. * {fieldA} and {fieldB} must have identical return type. * {fieldA} and {fieldB} must have identical sets of arguments. + * Let {mergedSet} be the result of adding the selection set of {fieldA} + and the selection set of {fieldB}. + * {FieldsInSetCanMerge(mergedSet)} must be true. ** Explanatory Text ** If multiple fields selections with the same response names are encountered -during execution, the result should be unambiguous. Therefore any two field -selections which might both be encountered for the same object are only valid if -they are equivalent. +during execution, the field and arguments to execute and the resulting value +should be unambiguous. Therefore any two field selections which might both be +encountered for the same object are only valid if they are equivalent. For simple hand-written GraphQL, this rule is obviously a clear developer error, however nested fragments can make this difficult to detect manually.