@@ -13,34 +13,28 @@ the case that a field error occurred on a field which was replaced with null.
1313
1414GraphQL does not require a specific serialization format. However, clients
1515should use a serialization format that supports the major primitives in the
16- GraphQL response. In particular, the serialization format must support
16+ GraphQL response. In particular, the serialization format must at least support
1717representations of the following four primitives:
1818
1919 * Map
2020 * List
2121 * String
2222 * Null
2323
24- Serialization formats which can represent an ordered map should preserve the
25- order of requested fields as defined by {CollectFields()} in the Execution
26- section. Serialization formats which can only represent unordered maps
27- (such as JSON) should retain this order textually. That is, if two fields
28- ` {foo, bar} ` were queried in that order, the resulting JSON serialization
29- should contain ` {"foo": "...", "bar": "..."} ` in the same order.
30-
31- Producing a response where fields are represented in the same order in which
32- they appear in the request improves human readability during debugging and
33- enables more efficient parsing of responses if the order of properties can
34- be anticipated.
35-
36- A serialization format may support the following primitives, however, strings
37- may be used as a substitute for those primitives.
24+ A serialization format should also support the following primitives, each
25+ representing one of the common GraphQL scalar types, however a string or simpler
26+ primitive may be used as a substitute if any are not directly supported:
3827
3928 * Boolean
4029 * Int
4130 * Float
4231 * Enum Value
4332
33+ This is not meant to be an exhaustive list of what a serialization format may
34+ encode. For example custom scalars representing a Date, Time, URI, or number
35+ with a different precision may be represented in whichever relevant format a
36+ given serialization format may support.
37+
4438
4539### JSON Serialization
4640
@@ -61,23 +55,34 @@ the following JSON concepts:
6155| Float | Number |
6256| Enum Value | String |
6357
64- ** Object Property Ordering**
58+
59+ ### Serialized Map Ordering
60+
61+ Since the result of evaluating a selection set is ordered, the serialized Map of
62+ results should preserve this order by writing the map entries in the same order
63+ as those fields were requested as defined by query execution. Producing a
64+ serialized response where fields are represented in the same order in which
65+ they appear in the request improves human readability during debugging and
66+ enables more efficient parsing of responses if the order of properties can
67+ be anticipated.
68+
69+ Serialization formats which represent an ordered map should preserve the
70+ order of requested fields as defined by {CollectFields()} in the Execution
71+ section. Serialization formats which only represent unordered maps but where
72+ order is still implicit in the serialization's textual order (such as JSON)
73+ should preserve the order of requested fields textually.
74+
75+ For example, if the request was ` { name, age } ` , a GraphQL service responding in
76+ JSON should respond with ` { "name": "Mark", "age": 30 } ` and should not respond
77+ with ` { "age": 30, "name": "Mark" } ` .
6578
6679While JSON Objects are specified as an
6780[ unordered collection of key-value pairs] ( https://tools.ietf.org/html/rfc7159#section-4 )
6881the pairs are represented in an ordered manner. In other words, while the JSON
6982strings ` { "name": "Mark", "age": 30 } ` and ` { "age": 30, "name": "Mark" } `
7083encode the same value, they also have observably different property orderings.
7184
72- Since the result of evaluating a selection set is ordered, the JSON object
73- serialized should preserve this order by writing the object properties in the
74- same order as those fields were requested as defined by query execution.
75-
76- For example, if the query was ` { name, age } ` , a GraphQL server responding in
77- JSON should respond with ` { "name": "Mark", "age": 30 } ` and should not respond
78- with ` { "age": 30, "name": "Mark" } ` .
79-
80- NOTE: This does not violate the JSON spec, as clients may still interpret
85+ Note: This does not violate the JSON spec, as clients may still interpret
8186objects in the response as unordered Maps and arrive at a valid value.
8287
8388
0 commit comments