diff --git a/spec/Appendix B -- Grammar Summary.md b/spec/Appendix B -- Grammar Summary.md index e75a0f5d4..5a066b82f 100644 --- a/spec/Appendix B -- Grammar Summary.md +++ b/spec/Appendix B -- Grammar Summary.md @@ -172,7 +172,7 @@ Arguments[Const] : ( Argument[?Const]+ ) Argument[Const] : Name : Value[?Const] -FragmentSpread : ... FragmentName Directives? +FragmentSpread : ... FragmentName Arguments? Directives? InlineFragment : ... TypeCondition? Directives? SelectionSet diff --git a/spec/Section 2 -- Language.md b/spec/Section 2 -- Language.md index ab5a2542d..c0d15b355 100644 --- a/spec/Section 2 -- Language.md +++ b/spec/Section 2 -- Language.md @@ -578,10 +578,10 @@ which returns the result: ## Fragments -FragmentSpread : ... FragmentName Directives? +FragmentSpread : ... FragmentName Arguments? Directives? -FragmentDefinition : Description? fragment FragmentName TypeCondition -Directives? SelectionSet +FragmentDefinition : Description? fragment FragmentName VariablesDefinition? +TypeCondition Directives? SelectionSet FragmentName : Name but not `on` @@ -1282,13 +1282,72 @@ size `60`: **Variable Use Within Fragments** -Variables can be used within fragments. Variables have global scope with a given -operation, so a variable used within a fragment must be declared in any -top-level operation that transitively consumes that fragment. If a variable is -referenced in a fragment and is included by an operation that does not define -that variable, that operation is invalid (see +Variables can be used within fragments. Operation-defined variables have global +scope within a given operation. Fragment-defined variables have local scope +within the fragment definition in which they are defined. A variable used within +a fragment must either be declared in each top-level operation that transitively +consumes that fragment, or by that same fragment as a fragment variable +definition. If a variable referenced in a fragment is included by an operation +where neither the fragment nor the operation defines that variable, that +operation is invalid (see [All Variable Uses Defined](#sec-All-Variable-Uses-Defined)). +## Fragment Variable Definitions + +Fragments may define locally scoped variables. This allows fragments to be +reused while enabling the caller to specify the fragment's behavior. + +For example, the profile picture may need to be a different size depending on +the parent context: + +```graphql example +query userAndFriends { + user(id: 4) { + ...dynamicProfilePic(size: 100) + friends(first: 10) { + id + name + ...dynamicProfilePic + } + } +} + +fragment dynamicProfilePic($size: Int! = 50) on User { + profilePic(size: $size) +} +``` + +In this case the `user` will have a larger `profilePic` than those found in the +list of `friends`. + +A fragment-defined variable is scoped to the fragment that defines it. +Fragment-defined variables are allowed to shadow operation-defined variables. + +```graphql example +query withShadowedVariables($size: Int!) { + user(id: 4) { + ...variableProfilePic + } + secondUser: user(id: 5) { + ...dynamicProfilePic(size: 10) + } +} + +fragment variableProfilePic on User { + ...dynamicProfilePic(size: $size) +} + +fragment dynamicProfilePic($size: Int!) on User { + profilePic(size: $size) +} +``` + +The profilePic for `user` will be determined by the variables set by the +operation, while `secondUser` will always have a `profilePic` of size `10`. In +this case, the fragment `variableProfilePic` uses the operation-defined +variable, while `dynamicProfilePic` uses the value passed in via the fragment +spread's `size` argument. + ## Type References Type : diff --git a/spec/Section 5 -- Validation.md b/spec/Section 5 -- Validation.md index 88f1e4048..5a172771d 100644 --- a/spec/Section 5 -- Validation.md +++ b/spec/Section 5 -- Validation.md @@ -534,8 +534,15 @@ fragment directFieldSelectionOnUnion on CatOrDog { FieldsInSetCanMerge(set): -- Let {fieldsForName} be the set of selections with a given _response name_ in - {set} including visiting fragments and inline fragments. +- Let {visitedSelections} be the selections in {set} including visiting fields, + fragment-spreads and inline fragments. +- Let {spreadsForName} be the set of fragment spreads with a given name in + {visitedSelections}. +- For each {spreadsForName} as {name} and {spreads}: + - Each entry in {spreads} must have identical sets of arguments to each other + entry in {spreads}. +- Let {fieldsForName} be the set of field selections with a given response name + in {visitedSelections}. - Given each pair of distinct members {fieldA} and {fieldB} in {fieldsForName}: - {SameResponseShape(fieldA, fieldB)} must be true. - If the parent types of {fieldA} and {fieldB} are equal or if either is not @@ -691,6 +698,58 @@ fragment conflictingDifferingResponses on Pet { } ``` +Fragment spread arguments can also cause fields to fail to merge. + +```graphql counter-example +fragment commandFragment($command: DogCommand!) on Dog { + doesKnowCommand(dogCommand: $command) +} + +fragment potentiallyConflictingArguments( + $commandOne: DogCommand! + $commandTwo: DogCommand! +) on Dog { + ...commandFragment(command: $commandOne) + ...commandFragment(command: $commandTwo) +} + +query { + pet { + ...potentiallyConflictingArguments(commandOne: SIT, commandTwo: DOWN) + } +} +``` + +If two fragment spreads with the same name, and hence the same selection, supply +different argument values, their fields will not be able to merge. In this case, +validation fails because the fragment spread `...commandFragment(command: SIT)` +and `...commandFragment(command: DOWN)` are part of the visited selections that +will be merged. + +If both of these spreads had used the same value for the argument value, it +would be allowed as we can be sure that we would resolve identical fields. +Spreads that use different variables that would always resolve to the same value +are also valid. For example, the following is valid: + +```graphql example +fragment commandFragment($command: DogCommand!) on Dog { + doesKnowCommand(dogCommand: $command) +} + +fragment noConflictWhenPassedOperationCommand( + $fragmentCommand: DogCommand! +) on Dog { + ...commandFragment(command: $operationCommand) + ...commandFragment(command: $fragmentCommand) +} + +query($operationCommand: DogCommand!) { + pet { + ...noConflictWhenPassedOperationCommand(fragmentCommand: $operationCommand) + } +} +``` + ### Leaf Field Selections **Formal Specification** @@ -768,8 +827,8 @@ query directQueryOnObjectWithSubFields { ## Arguments -Arguments are provided to both fields and directives. The following validation -rules apply in both cases. +Arguments are provided to fields, fragment spreads and directives. The following +validation rules apply in each case. ### Argument Names @@ -777,8 +836,9 @@ rules apply in both cases. - For each {argument} in the document: - Let {argumentName} be the Name of {argument}. - - Let {argumentDefinition} be the argument definition provided by the parent - field or definition named {argumentName}. + - Let {argumentDefinition} be the argument or variable definition named + {argumentName} provided by the parent field definition, directive definition + or fragment spread. - {argumentDefinition} must exist. **Explanatory Text** @@ -798,7 +858,22 @@ fragment argOnOptional on Dog { } ``` -the following is invalid since `command` is not defined on `DogCommand`. +The above is also applicable to fragment definitions and fragment spreads, each +variable must be defined by the fragment definition before it can be inserted as +an argument by the fragment spread. + +```graphql example +fragment withFragmentArg($command: DogCommand) on Dog { + doesKnowCommand(dogCommand: $command) +} + +fragment usesFragmentArg on Dog { + ...withFragmentArg(command: DOWN) +} +``` + +The following is invalid since `command` is not defined on +`Dog.doesKnowCommand`. ```graphql counter-example fragment invalidArgName on Dog { @@ -806,6 +881,19 @@ fragment invalidArgName on Dog { } ``` +and this is also invalid as the argument `dogCommand` is not defined on fragment +`withFragmentArg`. + +```graphql counter-example +fragment invalidFragmentArgName on Dog { + ...withFragmentArg(dogCommand: SIT) +} + +fragment withFragmentArg($command: DogCommand) on Dog { + doesKnowCommand(dogCommand: $command) +} +``` + and this is also invalid as `unless` is not defined on `@include`. ```graphql counter-example @@ -848,9 +936,9 @@ fragment multipleArgsReverseOrder on Arguments { ### Argument Uniqueness -Fields and directives treat arguments as a mapping of argument name to value. -More than one argument with the same name in an argument set is ambiguous and -invalid. +Fields, fragment spreads and directives treat arguments as a mapping of argument +name to value. More than one argument with the same name in an argument set is +ambiguous and invalid. **Formal Specification** @@ -862,10 +950,11 @@ invalid. ### Required Arguments -- For each Field or Directive in the document: - - Let {arguments} be the arguments provided by the Field or Directive. +- For each Field, Fragment Spread or Directive in the document: + - Let {arguments} be the arguments provided by the Field, Directive or + Fragment Spread. - Let {argumentDefinitions} be the set of argument definitions of that Field - or Directive. + or Directive, or the variable definitions of that Fragment. - For each {argumentDefinition} in {argumentDefinitions}: - Let {type} be the expected type of {argumentDefinition}. - Let {defaultValue} be the default value of {argumentDefinition}. @@ -1655,18 +1744,19 @@ query ($foo: Boolean = true, $bar: Boolean = false) { **Formal Specification** -- For every {operation} in the document: - - For every {variable} defined on {operation}: +- For every {operation} and {fragment} in the document: + - Let {operationOrFragment} be that {operation} or {fragment}. + - For every {variable} defined on {operationOrFragment}: - Let {variableName} be the name of {variable}. - Let {variables} be the set of all variables named {variableName} on - {operation}. + {operationOrFragment}. - {variables} must be a set of one. **Explanatory Text** -If any operation defines more than one variable with the same name, it is -ambiguous and invalid. It is invalid even if the type of the duplicate variable -is the same. +If any operation or fragment defines more than one variable with the same name, +it is ambiguous and invalid. It is invalid even if the type of the duplicate +variable is the same. ```graphql counter-example query houseTrainedQuery($atOtherHomes: Boolean, $atOtherHomes: Boolean) { @@ -1695,12 +1785,42 @@ fragment HouseTrainedFragment on Query { } ``` +Likewise, it is valid for a fragment to define a variable with a name that is +also defined on an operation: + +```graphql example +query C($atOtherHomes: Boolean) { + ...HouseTrainedFragment + aDog: dog { + ...HouseTrainedDog + } +} + +fragment HouseTrainedFragment on Query { + dog { + isHouseTrained(atOtherHomes: $atOtherHomes) + } +} + +fragment HouseTrainedDog($atOtherHomes: Boolean) on Dog { + isHouseTrained(atOtherHomes: $atOtherHomes) +} +``` + +Fragment-defined variables are scoped locally to the fragment that defines them, +and override any operation-defined variable values, so there is never ambiguity +about which value to use. In this case, the value of the argument `atOtherHomes` +within `HouseTrainedFragment` will be the operation-set value, and within +`HouseTrainedDog` will default to being unset (unless a default-value applies), +as the argument is not set by the fragment spread in the query `C`. + ### Variables Are Input Types **Formal Specification** -- For every {operation} in a {document}: - - For every {variable} on each {operation}: +- For every {operation} and {fragment} in a {document}: + - Let {operationOrFragment} be that {operation} or {fragment}. + - For every {variable} defined on {operationOrFragment}: - Let {variableType} be the type of {variable}. - {IsInputType(variableType)} must be {true}. @@ -1768,13 +1888,14 @@ query takesCatOrDog($catOrDog: CatOrDog) { transitively. - For each {fragment} in {fragments}: - For each {variableUsage} in scope of {fragment}, variable must be in - {operation}'s variable list. + either {fragment}'s or {operation}'s variable list or both. **Explanatory Text** -Variables are scoped on a per-operation basis. That means that any variable used -within the context of an operation must be defined at the top level of that -operation +Operation-defined Variables are scoped on a per-operation basis, while +Fragment-defined Variables are scoped locally to the fragment. That means that +any variable used within the context of an operation must either be defined at +the top level of that operation or on the fragment that uses that variable. For example: @@ -1801,9 +1922,10 @@ query variableIsNotDefined { ${atOtherHomes} is not defined by the operation. Fragments complicate this rule. Any fragment transitively included by an -operation has access to the variables defined by that operation. Fragments can -appear within multiple operations and therefore variable usages must correspond -to variable definitions in all of those operations. +operation has access to the variables defined by that operation and also those +defined on the fragment. Fragments can appear within multiple operations and +therefore variable usages not defined on the fragment must correspond to +variable definitions in all of those operations. For example the following is valid: @@ -1908,7 +2030,12 @@ included in that operation. - Let {variables} be the variables defined by that {operation}. - Each {variable} in {variables} must be used at least once in either the operation scope itself or any fragment transitively referenced by that - operation. + operation, excluding fragments that define the same name as an argument. +- For every {fragment} in the document: + - Let {variables} be the variables defined by that {fragment}. + - Each {variable} in {variables} must be used at least once transitively + within the fragment's selection set excluding traversal of named fragment + spreads. **Explanatory Text** @@ -1960,6 +2087,30 @@ fragment isHouseTrainedWithoutVariableFragment on Dog { } ``` +Fragment arguments can shadow operation variables: fragments that use an +argument are not using the operation-defined variable of the same name. + +As such, it would be invalid if the operation defined a variable and variables +of that name were used exclusively inside fragments that define a variable with +the same name: + +```graphql counter-example +query variableNotUsedWithinFragment($atOtherHomes: Boolean) { + dog { + ...shadowedVariableFragment + } +} + +fragment shadowedVariableFragment($atOtherHomes: Boolean) on Dog { + isHouseTrained(atOtherHomes: $atOtherHomes) +} +``` + +because +{$atOtherHomes} is only referenced in a fragment that defines it as a +locally scoped argument, the operation-defined {$atOtherHomes} +variable is never used. + All operations in a document must use all of their variables. As a result, the following document does not validate. @@ -1985,6 +2136,24 @@ fragment isHouseTrainedFragment on Dog { This document is not valid because {queryWithExtraVar} defines an extraneous variable. +Fragment variables must also be used within their definitions. For example, the +following is invalid: + +```graphql counter-example +query queryWithFragmentArgUnused($atOtherHomes: Boolean) { + dog { + ...fragmentArgUnused(atOtherHomes: $atOtherHomes) + } +} + +fragment fragmentArgUnused($atOtherHomes: Boolean) on Dog { + isHouseTrained +} +``` + +This document is invalid: fragment `fragmentArgUnused` defines a fragment +variable `$atOtherHomes`, but this variable is not used within this fragment. + ### All Variable Usages Are Allowed **Formal Specification** @@ -1993,8 +2162,12 @@ variable. - Let {variableUsages} be all usages transitively included in the {operation}. - For each {variableUsage} in {variableUsages}: - Let {variableName} be the name of {variableUsage}. - - Let {variableDefinition} be the {VariableDefinition} named {variableName} - defined within {operation}. + - If the usage is within a {fragment} that defines a {variableDefinition} + for {variableName}: + - Let {variableDefinition} be the {VariableDefinition} named + {variableName} defined within {fragment}. + - Otherwise, let {variableDefinition} be the {VariableDefinition} named + {variableName} defined within {operation}. - {IsVariableUsageAllowed(variableDefinition, variableUsage)} must be {true}. diff --git a/spec/Section 6 -- Execution.md b/spec/Section 6 -- Execution.md index c615e526e..6ada3f43f 100644 --- a/spec/Section 6 -- Execution.md +++ b/spec/Section 6 -- Execution.md @@ -101,10 +101,8 @@ CoerceVariableValues(schema, operation, variableValues): - Let {coercedValues} be an empty unordered Map. - Let {variablesDefinition} be the variables defined by {operation}. - For each {variableDefinition} in {variablesDefinition}: - - Let {variableName} be the name of {variableDefinition}. - - Let {variableType} be the expected type of {variableDefinition}. - - Assert: {IsInputType(variableType)} must be {true}. - - Let {defaultValue} be the default value for {variableDefinition}. + - Let {variableName}, {variableType}, and {defaultValue} be the result of + {GetVariableSignature(variableDefinition)}. - Let {hasValue} be {true} if {variableValues} provides a value for the name {variableName}. - Let {value} be the value provided in {variableValues} for the name @@ -131,6 +129,14 @@ CoerceVariableValues(schema, operation, variableValues): Note: This algorithm is very similar to {CoerceArgumentValues()}. +GetVariableSignature(variableDefinition): + +- Let {variableName} be the name of {variableDefinition}. +- Let {variableType} be the expected type of {variableDefinition}. +- Assert: {IsInputType(variableType)} must be {true}. +- Let {defaultValue} be the default value for {variableDefinition}. +- Return {variableName}, {variableType}, and {defaultValue}. + ## Executing Operations The type system, as described in the "Type System" section of the spec, must @@ -280,10 +286,10 @@ CreateSourceEventStream(subscription, schema, variableValues, initialValue): selectionSet, variableValues)}. - If {collectedFieldsMap} does not have exactly one entry, raise a _request error_. -- Let {fields} be the value of the first entry in {collectedFieldsMap}. -- Let {fieldName} be the name of the first entry in {fields}. Note: This value - is unaffected if an alias is used. -- Let {field} be the first entry in {fields}. +- Let {fieldInfo} be the value of the first entry in {collectedFieldsMap}. +- Let {field} be the value of the {field} property in {fieldInfo}. +- Let {fieldName} be the name of {field}. Note: This value is unaffected if an + alias is used. - Let {argumentValues} be the result of {CoerceArgumentValues(subscriptionType, field, variableValues)}. - Let {sourceStream} be the result of running @@ -439,7 +445,8 @@ The depth-first-search order of each _field set_ produced by {CollectFields()} is maintained through execution, ensuring that fields appear in the executed response in a stable and predictable order. -CollectFields(objectType, selectionSet, variableValues, visitedFragments): +CollectFields(objectType, selectionSet, variableValues, visitedFragments, +fragmentVariables): - If {visitedFragments} is not provided, initialize it to the empty set. - Initialize {collectedFieldsMap} to an empty ordered map of ordered sets. @@ -460,7 +467,9 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments): - Let {fieldsForResponseName} be the _field set_ value in {collectedFieldsMap} for the key {responseName}; otherwise create the entry with an empty ordered set. - - Add {selection} to the {fieldsForResponseName}. + - Let {fieldDetails} be a new unordered map containing {fragmentVariables}. + - Set the entry for {field} on {fieldDetails} to {selection}. + - Add {fieldDetails} to the {fieldsForResponseName}. - If {selection} is a {FragmentSpread}: - Let {fragmentSpreadName} be the name of {selection}. - If {fragmentSpreadName} is in {visitedFragments}, continue with the next @@ -473,10 +482,20 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments): - Let {fragmentType} be the type condition on {fragment}. - If {DoesFragmentTypeApply(objectType, fragmentType)} is {false}, continue with the next {selection} in {selectionSet}. + - Let {variableDefinitions} be the variable definitions for {fragment}. + - Initialize {signatures} to an empty list. + - For each {variableDefinition} of {variableDefinitions}: + - Append the result of {GetVariableSignature(variableDefinition)} to + {signatures}. + - Let {argumentValues} be the arguments provided in {selection}. + - Let {values} be the result of {CoerceArgumentValues(selection, + variableDefinitions, argumentValues, variableValues, fragmentVariables)}. + - Let {newFragmentVariables} be an unordered map containing {signatures} and + {values}. - Let {fragmentSelectionSet} be the top-level selection set of {fragment}. - Let {fragmentCollectedFieldsMap} be the result of calling {CollectFields(objectType, fragmentSelectionSet, variableValues, - visitedFragments)}. + visitedFragments, newFragmentVariables)}. - For each {responseName} and {fragmentFields} in {fragmentCollectedFieldsMap}: - Let {fieldsForResponseName} be the _field set_ value in @@ -491,7 +510,7 @@ CollectFields(objectType, selectionSet, variableValues, visitedFragments): - Let {fragmentSelectionSet} be the top-level selection set of {selection}. - Let {fragmentCollectedFieldsMap} be the result of calling {CollectFields(objectType, fragmentSelectionSet, variableValues, - visitedFragments)}. + visitedFragments, fragmentVariables)}. - For each {responseName} and {fragmentFields} in {fragmentCollectedFieldsMap}: - Let {fieldsForResponseName} be the _field set_ value in @@ -555,11 +574,11 @@ CollectSubfields(objectType, fields, variableValues): - If {fieldSelectionSet} is null or empty, continue to the next field. - Let {fieldCollectedFieldsMap} be the result of {CollectFields(objectType, fieldSelectionSet, variableValues)}. - - For each {responseName} and {subfields} in {fieldCollectedFieldsMap}: + - For each {responseName} and {subfieldInfos} in {fieldCollectedFieldsMap}: - Let {fieldsForResponseName} be the _field set_ value in {collectedFieldsMap} for the key {responseName}; otherwise create the entry with an empty ordered set. - - Add each fields from {subfields} to {fieldsForResponseName}. + - Add each fieldInfo from {subfieldInfos} to {fieldsForResponseName}. - Return {collectedFieldsMap}. Note: All the {fields} passed to {CollectSubfields()} share the same _response @@ -578,14 +597,18 @@ ExecuteCollectedFields(collectedFieldsMap, objectType, objectValue, variableValues): - Initialize {resultMap} to an empty ordered map. -- For each {responseName} and {fields} in {collectedFieldsMap}: - - Let {fieldName} be the name of the first entry in {fields}. Note: This value - is unaffected if an alias is used. +- For each {responseName} and {fieldInfos} in {collectedFieldsMap}: + - Let {fieldInfo} be the first entry in {fieldInfos}. + - Let {field} be the field property of {fieldInfo}. + - Let {fieldName} be the name of {field}. Note: This value is unaffected if an + alias is used. + - Let {fragmentVariableValues} be the fragmentVariables property of + {fieldInfo}. - Let {fieldType} be the return type defined for the field {fieldName} of {objectType}. - If {fieldType} is defined: - Let {responseValue} be {ExecuteField(objectType, objectValue, fieldType, - fields, variableValues)}. + fieldInfos, variableValues, fragmentVariableValues)}. - Set {responseValue} as the value for {responseName} in {resultMap}. - Return {resultMap}. @@ -719,33 +742,46 @@ first coerces any provided argument values, then resolves a value for the field, and finally completes that value either by recursively executing another selection set or coercing a scalar value. -ExecuteField(objectType, objectValue, fieldType, fields, variableValues): +ExecuteField(objectType, objectValue, fieldType, fieldDetailsList, +variableValues, fragmentVariables): -- Let {field} be the first entry in {fields}. +- Let {fieldDetails} be the first entry in {fieldDetailsList}. +- Let {field} and {fragmentVariables} be the corresponding entries on + {fieldDetails}. - Let {fieldName} be the field name of {field}. -- Let {argumentValues} be the result of {CoerceArgumentValues(objectType, field, - variableValues)}. +- Let {argumentDefinitions} be the arguments defined by {objectType} for the + field named {fieldName}. +- Let {argumentValues} be the result of {CoerceArgumentValues(field, + argumentDefinitions, variableValues, fragmentVariables)}. - Let {resolvedValue} be {ResolveFieldValue(objectType, objectValue, fieldName, - argumentValues)}. -- Return the result of {CompleteValue(fieldType, fields, resolvedValue, - variableValues)}. + argumentValues)}. Return the result of {CompleteValue(fieldType, + fieldDetailsList, resolvedValue, variableValues)}. -### Coercing Field Arguments +### Coercing Arguments -Fields may include arguments which are provided to the underlying runtime in -order to correctly produce a value. These arguments are defined by the field in -the type system to have a specific input type. +Fields, directives, and fragment spreads may include arguments which are +provided to the underlying runtime in order to correctly produce a value. For +fields and directives, these arguments are defined by the field or directive in +the type system to have a specific input type; for fragment spreads, the +fragment definition within the document specifies the input type. At each argument position in an operation may be a literal {Value}, or a {Variable} to be provided at runtime. -CoerceArgumentValues(objectType, field, variableValues): +CoerceFieldArgumentValues(objectType, field, variableValues, +fragmentVariableValues): -- Let {coercedValues} be an empty unordered Map. - Let {argumentValues} be the argument values provided in {field}. - Let {fieldName} be the name of {field}. - Let {argumentDefinitions} be the arguments defined by {objectType} for the field named {fieldName}. +- Return {CoerceArgumentValues(argumentDefinitions, argumentValues, + variableValues, fragmentVariableValues)} + +CoerceArgumentValues(node, argumentDefinitions, argumentValues, variableValues, +fragmentVariableValues): + +- Let {coercedValues} be an empty unordered Map. - For each {argumentDefinition} in {argumentDefinitions}: - Let {argumentName} be the name of {argumentDefinition}. - Let {argumentType} be the expected type of {argumentDefinition}. @@ -756,9 +792,13 @@ CoerceArgumentValues(objectType, field, variableValues): {argumentName}. - If {argumentValue} is a {Variable}: - Let {variableName} be the name of {argumentValue}. - - Let {hasValue} be {true} if {variableValues} provides a value for the name - {variableName}. - - Let {value} be the value provided in {variableValues} for the name + - Let {signatures} and {values} be the corresponding entries on + {fragmentVariables}. + - Let {scopedVariableValues} be {values} if an entry in {signatures} exists + for {variableName}; otherwise, let it be {variableValues}. + - Let {hasValue} be {true} if {scopedVariableValues} provides a value for + the name {variableName}. + - Let {value} be the value provided in {scopedVariableValues} for the name {variableName}. - Otherwise, let {value} be {argumentValue}. - If {hasValue} is not {true} and {defaultValue} exists (including {null}): @@ -825,12 +865,12 @@ the expected return type. If the return type is another Object type, then the field execution process continues recursively by collecting and executing subfields. -CompleteValue(fieldType, fields, result, variableValues): +CompleteValue(fieldType, fieldDetailsList, result, variableValues): - If the {fieldType} is a Non-Null type: - Let {innerType} be the inner type of {fieldType}. - Let {completedResult} be the result of calling {CompleteValue(innerType, - fields, result, variableValues)}. + fieldDetailsList, result, variableValues)}. - If {completedResult} is {null}, raise an _execution error_. - Return {completedResult}. - If {result} is {null} (or another internal value similar to {null} such as @@ -839,8 +879,8 @@ CompleteValue(fieldType, fields, result, variableValues): - If {result} is not a collection of values, raise an _execution error_. - Let {innerType} be the inner type of {fieldType}. - Return a list where each list item is the result of calling - {CompleteValue(innerType, fields, resultItem, variableValues)}, where - {resultItem} is each item in {result}. + {CompleteValue(innerType, fieldDetailsList, resultItem, variableValues)}, + where {resultItem} is each item in {result}. - If {fieldType} is a Scalar or Enum type: - Return the result of {CoerceResult(fieldType, result)}. - If {fieldType} is an Object, Interface, or Union type: @@ -849,7 +889,7 @@ CompleteValue(fieldType, fields, result, variableValues): - Otherwise if {fieldType} is an Interface or Union type. - Let {objectType} be {ResolveAbstractType(fieldType, result)}. - Let {collectedFieldsMap} be the result of calling - {CollectSubfields(objectType, fields, variableValues)}. + {CollectSubfields(objectType, fieldDetailsList, variableValues)}. - Return the result of evaluating {ExecuteCollectedFields(collectedFieldsMap, objectType, result, variableValues)} _normally_ (allowing for parallelization).