@@ -649,47 +649,6 @@ and invalid.
649
649
* {arguments} must be the set containing only {argument}.
650
650
651
651
652
- ### Argument Values Type Correctness
653
-
654
- #### Compatible Values
655
-
656
- ** Formal Specification**
657
-
658
- * For each {argument} in the document
659
- * Let {value} be the Value of {argument}
660
- * If {value} is not a Variable
661
- * Let {argumentName} be the Name of {argument}.
662
- * Let {argumentDefinition} be the argument definition provided by the parent field or definition named {argumentName}.
663
- * Let {type} be the type expected by {argumentDefinition}.
664
- * The type of {literalArgument} must be coercible to {type}.
665
-
666
- ** Explanatory Text**
667
-
668
- Literal values must be compatible with the type defined by the argument they are
669
- being provided to, as per the coercion rules defined in the Type System chapter.
670
-
671
- For example, an Int can be coerced into a Float.
672
-
673
- ``` graphql example
674
- fragment goodBooleanArg on Arguments {
675
- booleanArgField (booleanArg : true )
676
- }
677
-
678
- fragment coercedIntIntoFloatArg on Arguments {
679
- floatArgField (floatArg : 1 )
680
- }
681
- ```
682
-
683
- An incoercible conversion, is string to int. Therefore, the
684
- following example is invalid.
685
-
686
- ``` graphql counter-example
687
- fragment stringIntoInt on Arguments {
688
- intArgField (intArg : " 3" )
689
- }
690
- ```
691
-
692
-
693
652
#### Required Non-Null Arguments
694
653
695
654
* For each Field or Directive in the document.
@@ -1233,6 +1192,87 @@ and {Sentient}.
1233
1192
## Values
1234
1193
1235
1194
1195
+ ### Values of Correct Type
1196
+
1197
+ ** Format Specification**
1198
+
1199
+ * For each input Value {value} in the document.
1200
+ * Let {type} be the type expected in the position {value} is found.
1201
+ * {value} must be coercible to {type}.
1202
+
1203
+ ** Explanatory Text**
1204
+
1205
+ Literal values must be compatible with the type expected in the position they
1206
+ are found as per the coercion rules defined in the Type System chapter.
1207
+
1208
+ The type expected in a position include the type defined by the argument a value
1209
+ is provided for, the type defined by an input object field a value is provided
1210
+ for, and the type of a variable definition a default value is provided for.
1211
+
1212
+ The following examples are valid use of value literals:
1213
+
1214
+ ``` graphql example
1215
+ fragment goodBooleanArg on Arguments {
1216
+ booleanArgField (booleanArg : true )
1217
+ }
1218
+
1219
+ fragment coercedIntIntoFloatArg on Arguments {
1220
+ # Note: The input coercion rules for Float allow Int literals.
1221
+ floatArgField (floatArg : 123 )
1222
+ }
1223
+
1224
+ query goodComplexDefaultValue ($search : ComplexInput = { name : " Fido" }) {
1225
+ findDog (complex : $search )
1226
+ }
1227
+ ```
1228
+
1229
+ Non-coercible values (such as a String into an Int) are invalid. The
1230
+ following examples are invalid:
1231
+
1232
+ ``` graphql counter-example
1233
+ fragment stringIntoInt on Arguments {
1234
+ intArgField (intArg : " 123" )
1235
+ }
1236
+
1237
+ query badComplexValue {
1238
+ findDog (complex : { name : 123 })
1239
+ }
1240
+ ```
1241
+
1242
+
1243
+ ### Input Object Field Names
1244
+
1245
+ ** Formal Specification**
1246
+
1247
+ * For each Input Object Field {inputField} in the document
1248
+ * Let {inputFieldName} be the Name of {inputField}.
1249
+ * Let {inputFieldDefinition} be the input field definition provided by the
1250
+ parent input object type named {inputFieldName}.
1251
+ * {inputFieldDefinition} must exist.
1252
+
1253
+ ** Explanatory Text**
1254
+
1255
+ Every input field provided in an input object value must be defined in the set
1256
+ of possible fields of that input object's expected type.
1257
+
1258
+ For example the following example input object is valid:
1259
+
1260
+ ``` graphql example
1261
+ {
1262
+ findDog (complex : { name : " Fido" })
1263
+ }
1264
+ ```
1265
+
1266
+ While the following example input-object uses a field "favoriteCookieFlavor"
1267
+ which is not defined on the expected type:
1268
+
1269
+ ``` graphql counter-example
1270
+ {
1271
+ findDog (complex : { favoriteCookieFlavor : " Bacon" })
1272
+ }
1273
+ ```
1274
+
1275
+
1236
1276
### Input Object Field Uniqueness
1237
1277
1238
1278
** Formal Specification**
@@ -1393,16 +1433,15 @@ fragment HouseTrainedFragment {
1393
1433
```
1394
1434
1395
1435
1396
- ### Variable Default Values Are Correctly Typed
1436
+ ### Variable Default Value Is Allowed
1397
1437
1398
1438
** Formal Specification**
1399
1439
1400
- * For every {operation} in a document
1401
- * For every {variable} on each {operation}
1402
- * Let {variableType} be the type of {variable}
1403
- * If {variableType} is non-null it cannot have a default value
1404
- * If {variable} has a default value it must be of the same type
1405
- or able to be coerced to {variableType}
1440
+ * For every Variable Definition {variableDefinition} in a document
1441
+ * Let {variableType} be the type of {variableDefinition}
1442
+ * Let {defaultValue} be the default value of {variableDefinition}
1443
+ * If {variableType} is Non-null:
1444
+ * {defaultValue} must be undefined.
1406
1445
1407
1446
** Explanatory Text**
1408
1447
@@ -1431,31 +1470,6 @@ query houseTrainedQuery($atOtherHomes: Boolean! = true) {
1431
1470
}
1432
1471
```
1433
1472
1434
- Default values must be compatible with the types of variables.
1435
- Types must match or they must be coercible to the type.
1436
-
1437
- Non-matching types fail, such as in the following example:
1438
-
1439
- ``` graphql counter-example
1440
- query houseTrainedQuery ($atOtherHomes : Boolean = " true" ) {
1441
- dog {
1442
- isHousetrained (atOtherHomes : $atOtherHomes )
1443
- }
1444
- }
1445
- ```
1446
-
1447
- However if a type is coercible the query will pass validation.
1448
-
1449
- For example:
1450
-
1451
- ``` graphql example
1452
- query intToFloatQuery ($floatVar : Float = 1 ) {
1453
- arguments {
1454
- floatArgField (floatArg : $floatVar )
1455
- }
1456
- }
1457
- ```
1458
-
1459
1473
1460
1474
### Variables Are Input Types
1461
1475
0 commit comments