@@ -351,7 +351,7 @@ selection set. Selection sets may also contain fragment references.
351
351
352
352
## Fields
353
353
354
- Field : Alias? Name Arguments? Directives? SelectionSet?
354
+ Field : Alias? Name Arguments? Nullability? Directives? SelectionSet?
355
355
356
356
A selection set is primarily composed of fields. A field describes one discrete
357
357
piece of information available to request within a selection set.
@@ -515,6 +515,71 @@ which returns the result:
515
515
}
516
516
```
517
517
518
+ ## Nullability
519
+
520
+ Name Nullability?
521
+
522
+ Fields can have their nullability designated with either a ` ! ` to indicate that a
523
+ field should be ` Non-Nullable ` or a ` ? ` to indicate that a field should be
524
+ ` Nullable ` . These designators override the nullability set on a field by the schema
525
+ for the operation where they're being used.
526
+
527
+ In this example, we can indicate that a ` user ` 's ` name ` that could possibly be
528
+ ` null ` , should not be ` null ` :
529
+
530
+ ``` graphql example
531
+ {
532
+ user (id : 4 ) {
533
+ id
534
+ name !
535
+ }
536
+ }
537
+ ```
538
+
539
+ If ` name ` comes back non-` null ` , then the return value is the same as if the
540
+ nullability designator was not used:
541
+
542
+ ``` json example
543
+ {
544
+ "user" : {
545
+ "id" : 4 ,
546
+ "name" : " Mark Zuckerberg"
547
+ }
548
+ }
549
+ ```
550
+
551
+ In the event that ` name ` is ` null ` , the field's parent selection set becomes ` null `
552
+ in the result and an error is returned, just as if ` name ` was marked ` Non-Nullable `
553
+ in the schema:
554
+
555
+ ``` json example
556
+ {
557
+ "data" : {
558
+ "user" : null
559
+ },
560
+ "errors" : [
561
+ {
562
+ "locations" : [{ "column" : 13 , "line" : 4 }],
563
+ "message" : " Cannot return null for non-nullable field User.name." ,
564
+ "path" : [" user" , " name" ],
565
+ },
566
+ ]
567
+ }
568
+ ```
569
+
570
+ If ` user ` was ` Non-Nullable ` in the schema, but we don't want ` null ` s bubbling past
571
+ that point, then we can use ` ? ` as an error boundary. ` User ` will be treated as
572
+ ` Nullable ` for this operation:
573
+
574
+ ``` graphql example
575
+ {
576
+ user (id : 4 )? {
577
+ id
578
+ name !
579
+ }
580
+ }
581
+ ```
582
+
518
583
## Fragments
519
584
520
585
FragmentSpread : ... FragmentName Directives?
0 commit comments