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