@@ -461,11 +461,35 @@ yielded a value may be cancelled to avoid unnecessary work.
461
461
462
462
Additionally, the path of each {asyncRecord} in {subsequentPayloads} must be
463
463
compared with the path of the field that ultimately resolved to {null}. If the
464
- path of any {asyncRecord} starts with, but is not equal to, the path of the
465
- resolved {null}, the {asyncRecord} must be removed from {subsequentPayloads} and
466
- its result must not be sent to clients. If these async records have not yet
467
- executed or have not yet yielded a value they may also be cancelled to avoid
468
- unnecessary work.
464
+ path of any {asyncRecord} starts with the path of the resolved {null}, the
465
+ {asyncRecord} must be removed from {subsequentPayloads} and its result must not
466
+ be sent to clients. If these async records have not yet executed or have not yet
467
+ yielded a value they may also be cancelled to avoid unnecessary work.
468
+
469
+ For example, assume the field ` alwaysThrows ` is a ` Non-Null ` type that always
470
+ raises a field error:
471
+
472
+ ``` graphql example
473
+ {
474
+ myObject {
475
+ ... @defer {
476
+ name
477
+ }
478
+ alwaysThrows
479
+ }
480
+ }
481
+ ```
482
+
483
+ In this case, only one response should be sent. The async payload record
484
+ associated with the ` @defer ` directive should be removed and it's execution may
485
+ be cancelled.
486
+
487
+ ``` json example
488
+ {
489
+ "data" : { "myObject" : null },
490
+ "hasNext" : false
491
+ }
492
+ ```
469
493
470
494
Note: See [ Handling Field Errors] ( #sec-Handling-Field-Errors ) for more about
471
495
this behavior.
@@ -757,7 +781,7 @@ variableValues, parentRecord, subsequentPayloads):
757
781
- If {errors} is not empty:
758
782
- Add an entry to {payload} named ` errors ` with the value {errors}.
759
783
- If a field error was raised, causing a {null} to be propagated to
760
- {responseValue}, and {objectType} is a Non-Nullable type :
784
+ {responseValue}:
761
785
- Add an entry to {payload} named ` data ` with the value {null}.
762
786
- Otherwise:
763
787
- Add an entry to {payload} named ` data ` with the value {resultMap}.
@@ -1121,16 +1145,121 @@ When a field error is raised inside `ExecuteDeferredFragment` or
1121
1145
That is, the null resulting from a ` Non-Null ` type cannot propagate outside of
1122
1146
the boundary of the defer or stream payload.
1123
1147
1124
- If a fragment with the ` defer ` directive is spread on a Non-Nullable object
1125
- type, and a field error has caused a {null} to propagate to the associated
1126
- object, the {null} should not propagate any further, and the associated Defer
1127
- Payload's ` data ` field must be set to {null}.
1148
+ If a field error is raised while executing the selection set of a fragment with
1149
+ the ` defer ` directive, causing a {null} to propagate to the object containing
1150
+ this fragment, the {null} should not propagate any further. In this case, the
1151
+ associated Defer Payload's ` data ` field must be set to {null}.
1152
+
1153
+ For example, assume the ` month ` field is a ` Non-Null ` type that raises a field
1154
+ error:
1155
+
1156
+ ``` graphql example
1157
+ {
1158
+ birthday {
1159
+ ... @defer {
1160
+ month
1161
+ }
1162
+ }
1163
+ }
1164
+ ```
1165
+
1166
+ Response 1, the initial response is sent:
1167
+
1168
+ ``` json example
1169
+ {
1170
+ "data" : { "birthday" : {} },
1171
+ "hasNext" : true
1172
+ }
1173
+ ```
1174
+
1175
+ Response 2, the defer payload is sent. The {data} entry has been set to {null},
1176
+ as this {null} as propagated as high as the error boundary will allow.
1177
+
1178
+ ``` json example
1179
+ {
1180
+ "incremental" : [
1181
+ {
1182
+ "path" : [" birthday" ],
1183
+ "data" : null
1184
+ }
1185
+ ],
1186
+ "hasNext" : false
1187
+ }
1188
+ ```
1128
1189
1129
1190
If the ` stream ` directive is present on a list field with a Non-Nullable inner
1130
1191
type, and a field error has caused a {null} to propagate to the list item, the
1131
1192
{null} should not propagate any further, and the associated Stream Payload's
1132
1193
` item ` field must be set to {null}.
1133
1194
1195
+ For example, assume the ` films ` field is a ` List ` type with an ` Non-Null ` inner
1196
+ type. In this case, the second list item raises a field error:
1197
+
1198
+ ``` graphql example
1199
+ {
1200
+ films @stream (initialCount : 1 )
1201
+ }
1202
+ ```
1203
+
1204
+ Response 1, the initial response is sent:
1205
+
1206
+ ``` json example
1207
+ {
1208
+ "data" : { "films" : [" A New Hope" ] },
1209
+ "hasNext" : true
1210
+ }
1211
+ ```
1212
+
1213
+ Response 2, the first stream payload is sent. The {items} entry has been set to
1214
+ {null}, as this {null} as propagated as high as the error boundary will allow.
1215
+
1216
+ ``` json example
1217
+ {
1218
+ "incremental" : [
1219
+ {
1220
+ "path" : [" films" , 1 ],
1221
+ "items" : null
1222
+ }
1223
+ ],
1224
+ "hasNext" : false
1225
+ }
1226
+ ```
1227
+
1228
+ In this alternative example, assume the ` films ` field is a ` List ` type without a
1229
+ ` Non-Null ` inner type. In this case, the second list item also raises a field
1230
+ error:
1231
+
1232
+ ``` graphql example
1233
+ {
1234
+ films @stream (initialCount : 1 )
1235
+ }
1236
+ ```
1237
+
1238
+ Response 1, the initial response is sent:
1239
+
1240
+ ``` json example
1241
+ {
1242
+ "data" : { "films" : [" A New Hope" ] },
1243
+ "hasNext" : true
1244
+ }
1245
+ ```
1246
+
1247
+ Response 2, the first stream payload is sent. The {items} entry has been set to
1248
+ a list containing {null}, as this {null} has only propagated as high as the list
1249
+ item.
1250
+
1251
+ ``` json example
1252
+ {
1253
+ "incremental" : [
1254
+ {
1255
+ "path" : [" films" , 1 ],
1256
+ "items" : [null ]
1257
+ }
1258
+ ],
1259
+ "hasNext" : false
1260
+ }
1261
+ ```
1262
+
1134
1263
If all fields from the root of the request to the source of the field error
1135
1264
return ` Non-Null ` types, then the {"data"} entry in the response should be
1136
1265
{null}.
0 commit comments