@@ -351,7 +351,7 @@ selection set. Selection sets may also contain fragment references.
351351
352352## Fields
353353
354- Field : Alias? Name Arguments? Directives? SelectionSet?
354+ Field : Alias? Name Arguments? Nullability? Directives? SelectionSet?
355355
356356A selection set is primarily composed of fields. A field describes one discrete
357357piece of information available to request within a selection set.
@@ -515,6 +515,71 @@ which returns the result:
515515}
516516```
517517
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+
518583## Fragments
519584
520585FragmentSpread : ... FragmentName Directives?
0 commit comments