@@ -327,18 +327,14 @@ represent additional fields a GraphQL client only accesses locally.
327
327
ScalarTypeDefinition : Description? scalar Name Directives[ Const] ?
328
328
329
329
Scalar types represent primitive leaf values in a GraphQL type system. GraphQL
330
- responses take the form of a hierarchical tree; the leaves on these trees are
331
- GraphQL scalars.
332
-
333
- All GraphQL scalars are representable as strings, though depending on the
334
- response format being used, there may be a more appropriate primitive for the
335
- given scalar type, and server should use those types when appropriate.
336
-
337
- GraphQL provides a number of built-in scalars, but type systems can add
338
- additional scalars with semantic meaning. For example, a GraphQL system could
339
- define a scalar called ` Time ` which, while serialized as a string, promises to
340
- conform to ISO-8601. When querying a field of type ` Time ` , you can then rely on
341
- the ability to parse the result with an ISO-8601 parser and use a
330
+ responses take the form of a hierarchical tree; the leaves of this tree are
331
+ typically GraphQL Scalar types (but may also be Enum types or {null} values).
332
+
333
+ GraphQL provides a number of built-in scalars (see below), but type systems can
334
+ add additional scalars with semantic meaning. For example, a GraphQL system
335
+ could define a scalar called ` Time ` which, while serialized as a string,
336
+ promises to conform to ISO-8601. When querying a field of type ` Time ` , you can
337
+ then rely on the ability to parse the result with an ISO-8601 parser and use a
342
338
client-specific primitive for time. Another example of a potentially useful
343
339
custom scalar is ` Url ` , which serializes as a string, but is guaranteed by
344
340
the server to be a valid URL.
@@ -348,34 +344,48 @@ scalar Time
348
344
scalar Url
349
345
```
350
346
351
- A server may omit any of the built-in scalars from its schema, for example if a
352
- schema does not refer to a floating-point number, then it may omit the
353
- ` Float ` type. However, if a schema includes a type with the name of one of the
354
- types described here, it must adhere to the behavior described. As an example,
355
- a server must not include a type called ` Int ` and use it to represent
356
- 128-bit numbers, internationalization information, or anything other than what
357
- is defined in this document.
347
+ ** Built-in Scalars**
348
+
349
+ GraphQL specifies a basic set of well-defined Scalar types: {Int}, {Float},
350
+ {String}, {Boolean}, and {ID}. A GraphQL framework should support all of these
351
+ types, and a GraphQL service which provides a type by these names must adhere to
352
+ the behavior described for them in this document. As an example, a service must
353
+ not include a type called {Int} and use it to represent 64-bit numbers,
354
+ internationalization information, or anything other than what is defined in
355
+ this document.
356
+
357
+ When returning the set of types from the ` __Schema ` introspection type, all
358
+ referenced built-in scalars must be included. If a built-in scalar type is not
359
+ referenced anywhere in a schema (there is no field, argument, or input field of
360
+ that type) then it must not be included.
358
361
359
362
When representing a GraphQL schema using the type system definition language,
360
- the built-in scalar types should be omitted for brevity.
363
+ all built-in scalars must be omitted for brevity.
361
364
362
- ** Result Coercion**
365
+ ** Result Coercion and Serialization **
363
366
364
367
A GraphQL server, when preparing a field of a given scalar type, must uphold the
365
368
contract the scalar type describes, either by coercing the value or producing a
366
369
field error if a value cannot be coerced or if coercion may result in data loss.
367
370
368
371
A GraphQL service may decide to allow coercing different internal types to the
369
- expected return type. For example when coercing a field of type ` Int ` a boolean
370
- ` true ` value may produce ` 1 ` or a string value ` "123" ` may be parsed as base-10
371
- ` 123 ` . However if internal type coercion cannot be reasonably performed without
372
+ expected return type. For example when coercing a field of type { Int} a boolean
373
+ { true} value may produce {1} or a string value { "123"} may be parsed as base-10
374
+ { 123} . However if internal type coercion cannot be reasonably performed without
372
375
losing information, then it must raise a field error.
373
376
374
377
Since this coercion behavior is not observable to clients of the GraphQL server,
375
378
the precise rules of coercion are left to the implementation. The only
376
379
requirement is that the server must yield values which adhere to the expected
377
380
Scalar type.
378
381
382
+ GraphQL scalars are serialized according to the serialization format being used.
383
+ There may be a most appropriate serialized primitive for each given scalar type,
384
+ and the server should produce each primitive where appropriate.
385
+
386
+ See [ Serialization Format] ( #sec-Serialization-Format ) for more detailed
387
+ information on the serialization of scalars in common JSON and other formats.
388
+
379
389
** Input Coercion**
380
390
381
391
If a GraphQL server expects a scalar type as input to an argument, coercion
@@ -394,12 +404,6 @@ input value.
394
404
For all types below, with the exception of Non-Null, if the explicit value
395
405
{null} is provided, then the result of input coercion is {null}.
396
406
397
- ** Built-in Scalars**
398
-
399
- GraphQL provides a basic set of well-defined Scalar types. A GraphQL server
400
- should support all of these types, and a GraphQL server which provide a type by
401
- these names must adhere to the behavior described below.
402
-
403
407
404
408
### Int
405
409
@@ -409,7 +413,7 @@ that type to represent this scalar.
409
413
410
414
** Result Coercion**
411
415
412
- Fields returning the type ` Int ` expect to encounter 32-bit integer
416
+ Fields returning the type { Int} expect to encounter 32-bit integer
413
417
internal values.
414
418
415
419
GraphQL servers may coerce non-integer internal values to integers when
@@ -444,10 +448,10 @@ should use that type to represent this scalar.
444
448
445
449
** Result Coercion**
446
450
447
- Fields returning the type ` Float ` expect to encounter double-precision
451
+ Fields returning the type { Float} expect to encounter double-precision
448
452
floating-point internal values.
449
453
450
- GraphQL servers may coerce non-floating-point internal values to ` Float ` when
454
+ GraphQL servers may coerce non-floating-point internal values to { Float} when
451
455
reasonable without losing information, otherwise they must raise a field error.
452
456
Examples of this may include returning ` 1.0 ` for the integer number ` 1 ` , or
453
457
` 123.0 ` for the string ` "123" ` .
@@ -471,9 +475,9 @@ and that representation must be used here.
471
475
472
476
** Result Coercion**
473
477
474
- Fields returning the type ` String ` expect to encounter UTF-8 string internal values.
478
+ Fields returning the type { String} expect to encounter UTF-8 string internal values.
475
479
476
- GraphQL servers may coerce non-string raw values to ` String ` when reasonable
480
+ GraphQL servers may coerce non-string raw values to { String} when reasonable
477
481
without losing information, otherwise they must raise a field error. Examples of
478
482
this may include returning the string ` "true" ` for a boolean true value, or the
479
483
string ` "1" ` for the integer ` 1 ` .
@@ -493,9 +497,9 @@ representation of the integers `1` and `0`.
493
497
494
498
** Result Coercion**
495
499
496
- Fields returning the type ` Boolean ` expect to encounter boolean internal values.
500
+ Fields returning the type { Boolean} expect to encounter boolean internal values.
497
501
498
- GraphQL servers may coerce non-boolean raw values to ` Boolean ` when reasonable
502
+ GraphQL servers may coerce non-boolean raw values to { Boolean} when reasonable
499
503
without losing information, otherwise they must raise a field error. Examples of
500
504
this may include returning ` true ` for non-zero numbers.
501
505
@@ -509,8 +513,8 @@ other input values must raise a query error indicating an incorrect type.
509
513
510
514
The ID scalar type represents a unique identifier, often used to refetch an
511
515
object or as the key for a cache. The ID type is serialized in the same way as
512
- a ` String ` ; however, it is not intended to be human-readable. While it is
513
- often numeric, it should always serialize as a ` String ` .
516
+ a { String} ; however, it is not intended to be human-readable. While it is
517
+ often numeric, it should always serialize as a { String} .
514
518
515
519
** Result Coercion**
516
520
@@ -583,8 +587,8 @@ type Person {
583
587
}
584
588
```
585
589
586
- Where `name ` is a field that will yield a ` String ` value , and `age ` is a field
587
- that will yield an ` Int ` value , and `picture ` is a field that will yield a
590
+ Where `name ` is a field that will yield a { String } value , and `age ` is a field
591
+ that will yield an { Int } value , and `picture ` is a field that will yield a
588
592
`Url ` value .
589
593
590
594
A query of an object value must select at least one field . This selection of
@@ -1250,7 +1254,7 @@ EnumValuesDefinition : { EnumValueDefinition+ }
1250
1254
1251
1255
EnumValueDefinition : Description? EnumValue Directives[ Const] ?
1252
1256
1253
- GraphQL Enum types, like scalar types, also represent leaf values in a GraphQL
1257
+ GraphQL Enum types, like Scalar types, also represent leaf values in a GraphQL
1254
1258
type system. However Enum types describe the set of possible values.
1255
1259
1256
1260
Enums are not references for a numeric value, but are unique values in their own
0 commit comments