Skip to content

Commit 06614fb

Browse files
authored
Edit: Move "Response Format" subsection above "Serialization Format" (graphql#443)
The structure of the response is more important than its serialization.
1 parent 9368847 commit 06614fb

File tree

1 file changed

+81
-81
lines changed

1 file changed

+81
-81
lines changed

spec/Section 7 -- Response.md

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,87 +6,7 @@ operation if successful, and describes any errors encountered during the
66
request.
77

88
A response may contain both a partial response as well as encountered errors in
9-
the case that a field error occurred on a field which was replaced with null.
10-
11-
12-
## Serialization Format
13-
14-
GraphQL does not require a specific serialization format. However, clients
15-
should use a serialization format that supports the major primitives in the
16-
GraphQL response. In particular, the serialization format must at least support
17-
representations of the following four primitives:
18-
19-
* Map
20-
* List
21-
* String
22-
* Null
23-
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:
27-
28-
* Boolean
29-
* Int
30-
* Float
31-
* Enum Value
32-
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-
38-
39-
### JSON Serialization
40-
41-
JSON is the most common serialization format for GraphQL. Though as mentioned
42-
above, GraphQL does not require a specific serialization format.
43-
44-
When using JSON as a serialization of GraphQL responses, the following JSON
45-
values should be used to encode the related GraphQL values:
46-
47-
| GraphQL Value | JSON Value |
48-
| ------------- | ----------------- |
49-
| Map | Object |
50-
| List | Array |
51-
| Null | {null} |
52-
| String | String |
53-
| Boolean | {true} or {false} |
54-
| Int | Number |
55-
| Float | Number |
56-
| Enum Value | String |
57-
58-
Note: For consistency and ease of notation, examples of responses are given in
59-
JSON format throughout this document.
60-
61-
62-
### Serialized Map Ordering
63-
64-
Since the result of evaluating a selection set is ordered, the serialized Map of
65-
results should preserve this order by writing the map entries in the same order
66-
as those fields were requested as defined by query execution. Producing a
67-
serialized response where fields are represented in the same order in which
68-
they appear in the request improves human readability during debugging and
69-
enables more efficient parsing of responses if the order of properties can
70-
be anticipated.
71-
72-
Serialization formats which represent an ordered map should preserve the
73-
order of requested fields as defined by {CollectFields()} in the Execution
74-
section. Serialization formats which only represent unordered maps but where
75-
order is still implicit in the serialization's textual order (such as JSON)
76-
should preserve the order of requested fields textually.
77-
78-
For example, if the request was `{ name, age }`, a GraphQL service responding in
79-
JSON should respond with `{ "name": "Mark", "age": 30 }` and should not respond
80-
with `{ "age": 30, "name": "Mark" }`.
81-
82-
While JSON Objects are specified as an
83-
[unordered collection of key-value pairs](https://tools.ietf.org/html/rfc7159#section-4)
84-
the pairs are represented in an ordered manner. In other words, while the JSON
85-
strings `{ "name": "Mark", "age": 30 }` and `{ "age": 30, "name": "Mark" }`
86-
encode the same value, they also have observably different property orderings.
87-
88-
Note: This does not violate the JSON spec, as clients may still interpret
89-
objects in the response as unordered Maps and arrive at a valid value.
9+
the case that a field error occurred on a field which was replaced with {null}.
9010

9111

9212
## Response Format
@@ -298,3 +218,83 @@ still discouraged.
298218
]
299219
}
300220
```
221+
222+
223+
## Serialization Format
224+
225+
GraphQL does not require a specific serialization format. However, clients
226+
should use a serialization format that supports the major primitives in the
227+
GraphQL response. In particular, the serialization format must at least support
228+
representations of the following four primitives:
229+
230+
* Map
231+
* List
232+
* String
233+
* Null
234+
235+
A serialization format should also support the following primitives, each
236+
representing one of the common GraphQL scalar types, however a string or simpler
237+
primitive may be used as a substitute if any are not directly supported:
238+
239+
* Boolean
240+
* Int
241+
* Float
242+
* Enum Value
243+
244+
This is not meant to be an exhaustive list of what a serialization format may
245+
encode. For example custom scalars representing a Date, Time, URI, or number
246+
with a different precision may be represented in whichever relevant format a
247+
given serialization format may support.
248+
249+
250+
### JSON Serialization
251+
252+
JSON is the most common serialization format for GraphQL. Though as mentioned
253+
above, GraphQL does not require a specific serialization format.
254+
255+
When using JSON as a serialization of GraphQL responses, the following JSON
256+
values should be used to encode the related GraphQL values:
257+
258+
| GraphQL Value | JSON Value |
259+
| ------------- | ----------------- |
260+
| Map | Object |
261+
| List | Array |
262+
| Null | {null} |
263+
| String | String |
264+
| Boolean | {true} or {false} |
265+
| Int | Number |
266+
| Float | Number |
267+
| Enum Value | String |
268+
269+
Note: For consistency and ease of notation, examples of responses are given in
270+
JSON format throughout this document.
271+
272+
273+
### Serialized Map Ordering
274+
275+
Since the result of evaluating a selection set is ordered, the serialized Map of
276+
results should preserve this order by writing the map entries in the same order
277+
as those fields were requested as defined by query execution. Producing a
278+
serialized response where fields are represented in the same order in which
279+
they appear in the request improves human readability during debugging and
280+
enables more efficient parsing of responses if the order of properties can
281+
be anticipated.
282+
283+
Serialization formats which represent an ordered map should preserve the
284+
order of requested fields as defined by {CollectFields()} in the Execution
285+
section. Serialization formats which only represent unordered maps but where
286+
order is still implicit in the serialization's textual order (such as JSON)
287+
should preserve the order of requested fields textually.
288+
289+
For example, if the request was `{ name, age }`, a GraphQL service responding in
290+
JSON should respond with `{ "name": "Mark", "age": 30 }` and should not respond
291+
with `{ "age": 30, "name": "Mark" }`.
292+
293+
While JSON Objects are specified as an
294+
[unordered collection of key-value pairs](https://tools.ietf.org/html/rfc7159#section-4)
295+
the pairs are represented in an ordered manner. In other words, while the JSON
296+
strings `{ "name": "Mark", "age": 30 }` and `{ "age": 30, "name": "Mark" }`
297+
encode the same value, they also have observably different property orderings.
298+
299+
Note: This does not violate the JSON spec, as clients may still interpret
300+
objects in the response as unordered Maps and arrive at a valid value.

0 commit comments

Comments
 (0)