From f4f53ed95c2f984d562a3aa1aa9f06e68ecfc23c Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Wed, 29 Aug 2018 12:44:58 -0400 Subject: [PATCH 1/2] Allow singular variables in list locations --- spec/Section 5 -- Validation.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/spec/Section 5 -- Validation.md b/spec/Section 5 -- Validation.md index d16debb79..5236fa210 100644 --- a/spec/Section 5 -- Validation.md +++ b/spec/Section 5 -- Validation.md @@ -1857,7 +1857,10 @@ AreTypesCompatible(variableType, locationType): * Let {nullableVariableType} be the nullable type of {variableType}. * Return {AreTypesCompatible(nullableVariableType, locationType)}. * Otherwise, if {locationType} is a list type: - * If {variableType} is NOT a list type, return {false}. + * If {variableType} is NOT a list type: + * Let {itemLocationType} be the unwrapped item type of {locationType}. + * Let {nullableItemLocationType} be the unwrapped nullable type of {itemLocationType} if {itemLocationType} is non-null, or {itemLocationType} if {itemLocationType} is nullable. + * Return {AreTypesCompatible(variableType, nullableItemLocationType)}. * Let {itemLocationType} be the unwrapped item type of {locationType}. * Let {itemVariableType} be the unwrapped item type of {variableType}. * Return {AreTypesCompatible(itemVariableType, itemLocationType)}. @@ -1884,7 +1887,7 @@ query intCannotGoIntoBoolean($intArg: Int) { ${intArg} typed as {Int} cannot be used as a argument to {booleanArg}, typed as {Boolean}. -List cardinality must also be the same. For example, lists cannot be passed into singular +List cardinality must be compatible. For example, lists cannot be passed into singular values. ```graphql counter-example @@ -1895,6 +1898,17 @@ query booleanListCannotGoIntoBoolean($booleanListArg: [Boolean]) { } ``` +However, for consistency with type coercion, singular values can be passed into lists, +including nullable singular values for nullable lists of non-nullable values. + +```graphql example +query booleanCanGoIntoBooleanList($booleanArg: Boolean!) { + arguments { + booleanListArgField(booleanListArg: $booleanArg) + } +} +``` + Nullability must also be respected. In general a nullable variable cannot be passed to a non-null argument. From 16978d440b8657b443a6fad4983cd8caf692b6d9 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Fri, 31 Aug 2018 20:14:48 -0400 Subject: [PATCH 2/2] Remove CoerceVariableValues --- spec/Section 6 -- Execution.md | 56 ++-------------------------------- 1 file changed, 3 insertions(+), 53 deletions(-) diff --git a/spec/Section 6 -- Execution.md b/spec/Section 6 -- Execution.md index c851d6634..e438e7259 100644 --- a/spec/Section 6 -- Execution.md +++ b/spec/Section 6 -- Execution.md @@ -28,13 +28,12 @@ request is determined by the result of executing this operation according to the ExecuteRequest(schema, document, operationName, variableValues, initialValue): * Let {operation} be the result of {GetOperation(document, operationName)}. - * Let {coercedVariableValues} be the result of {CoerceVariableValues(schema, operation, variableValues)}. * If {operation} is a query operation: - * Return {ExecuteQuery(operation, schema, coercedVariableValues, initialValue)}. + * Return {ExecuteQuery(operation, schema, variableValues, initialValue)}. * Otherwise if {operation} is a mutation operation: - * Return {ExecuteMutation(operation, schema, coercedVariableValues, initialValue)}. + * Return {ExecuteMutation(operation, schema, variableValues, initialValue)}. * Otherwise if {operation} is a subscription operation: - * Return {Subscribe(operation, schema, coercedVariableValues, initialValue)}. + * Return {Subscribe(operation, schema, variableValues, initialValue)}. GetOperation(document, operationName): @@ -67,48 +66,6 @@ not later change, or a service may validate a request once and memoize the result to avoid validating the same request again in the future. -### Coercing Variable Values - -If the operation has defined any variables, then the values for -those variables need to be coerced using the input coercion rules -of variable's declared type. If a query error is encountered during -input coercion of variable values, then the operation fails without -execution. - -CoerceVariableValues(schema, operation, variableValues): - - * Let {coercedValues} be an empty unordered Map. - * Let {variableDefinitions} be the variables defined by {operation}. - * For each {variableDefinition} in {variableDefinitions}: - * 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 {hasValue} be {true} if {variableValues} provides a value for the - name {variableName}. - * Let {value} be the value provided in {variableValues} for the - name {variableName}. - * If {hasValue} is not {true} and {defaultValue} exists (including {null}): - * Add an entry to {coercedValues} named {variableName} with the - value {defaultValue}. - * Otherwise if {variableType} is a Non-Nullable type, and either {hasValue} - is not {true} or {value} is {null}, throw a query error. - * Otherwise if {hasValue} is true: - * If {value} is {null}: - * Add an entry to {coercedValues} named {variableName} with the - value {null}. - * Otherwise: - * If {value} cannot be coerced according to the input coercion - rules of {variableType}, throw a query error. - * Let {coercedValue} be the result of coercing {value} according to the - input coercion rules of {variableType}. - * Add an entry to {coercedValues} named {variableName} with the - value {coercedValue}. - * Return {coercedValues}. - -Note: This algorithm is very similar to {CoerceArgumentValues()}. - - ## Executing Operations The type system, as described in the "Type System" section of the spec, must @@ -591,9 +548,6 @@ CoerceArgumentValues(objectType, field, variableValues): * If {value} is {null}: * Add an entry to {coercedValues} named {argumentName} with the value {null}. - * Otherwise, if {argumentValue} is a {Variable}: - * Add an entry to {coercedValues} named {argumentName} with the - value {value}. * Otherwise: * If {value} cannot be coerced according to the input coercion rules of {variableType}, throw a field error. @@ -603,10 +557,6 @@ CoerceArgumentValues(objectType, field, variableValues): value {coercedValue}. * Return {coercedValues}. -Note: Variable values are not coerced because they are expected to be coerced -before executing the operation in {CoerceVariableValues()}, and valid queries -must only allow usage of variables of appropriate types. - ### Value Resolution