@@ -104,18 +104,6 @@ export interface ParseOptions {
104104 * ```
105105 */
106106 allowLegacyFragmentVariables ?: boolean ;
107-
108- /**
109- * When enabled, the parser will understand and parse semantic nullability
110- * annotations. This means that every type suffixed with `!` will remain
111- * non-nullable, every type suffixed with `?` will be the classic nullable, and
112- * types without a suffix will be semantically nullable. Semantic nullability
113- * will be the new default when this is enabled. A semantically nullable type
114- * can only be null when there's an error associated with the field.
115- *
116- * @experimental
117- */
118- allowSemanticNullability ?: boolean ;
119107}
120108
121109/**
@@ -187,7 +175,7 @@ export function parseType(
187175) : TypeNode | SemanticNonNullTypeNode {
188176 const parser = new Parser ( source , options ) ;
189177 parser . expectToken ( TokenKind . SOF ) ;
190- const type = parser . parseTypeReference ( ) ;
178+ const type = parser . parseTypeReference ( true ) ;
191179 parser . expectToken ( TokenKind . EOF ) ;
192180 return type ;
193181}
@@ -271,16 +259,6 @@ export class Parser {
271259 * - InputObjectTypeDefinition
272260 */
273261 parseDefinition ( ) : DefinitionNode {
274- const directives = this . parseDirectives ( false ) ;
275- // If a document-level SemanticNullability directive exists as
276- // the first element in a document, then all parsing will
277- // happen in SemanticNullability mode.
278- for ( const directive of directives ) {
279- if ( directive . name . value === 'SemanticNullability' ) {
280- this . _options . allowSemanticNullability = true ;
281- }
282- }
283-
284262 if ( this . peek ( TokenKind . BRACE_L ) ) {
285263 return this . parseOperationDefinition ( ) ;
286264 }
@@ -404,7 +382,7 @@ export class Parser {
404382 kind : Kind . VARIABLE_DEFINITION ,
405383 variable : this . parseVariable ( ) ,
406384 type : ( this . expectToken ( TokenKind . COLON ) ,
407- this . parseTypeReference ( ) ) as TypeNode ,
385+ this . parseTypeReference ( false ) ) as TypeNode ,
408386 defaultValue : this . expectOptionalToken ( TokenKind . EQUALS )
409387 ? this . parseConstValueLiteral ( )
410388 : undefined ,
@@ -774,11 +752,13 @@ export class Parser {
774752 * - ListType
775753 * - NonNullType
776754 */
777- parseTypeReference ( ) : TypeNode | SemanticNonNullTypeNode {
755+ parseTypeReference (
756+ allowSemanticNonNull : boolean ,
757+ ) : TypeNode | SemanticNonNullTypeNode {
778758 const start = this . _lexer . token ;
779759 let type ;
780760 if ( this . expectOptionalToken ( TokenKind . BRACKET_L ) ) {
781- const innerType = this . parseTypeReference ( ) ;
761+ const innerType = this . parseTypeReference ( allowSemanticNonNull ) ;
782762 this . expectToken ( TokenKind . BRACKET_R ) ;
783763 type = this . node < ListTypeNode > ( start , {
784764 kind : Kind . LIST_TYPE ,
@@ -788,27 +768,19 @@ export class Parser {
788768 type = this . parseNamedType ( ) ;
789769 }
790770
791- if ( this . _options . allowSemanticNullability ) {
792- if ( this . expectOptionalToken ( TokenKind . BANG ) ) {
793- return this . node < NonNullTypeNode > ( start , {
794- kind : Kind . NON_NULL_TYPE ,
795- type,
796- } ) ;
797- } else if ( this . expectOptionalToken ( TokenKind . QUESTION_MARK ) ) {
798- return type ;
799- }
800-
801- return this . node < SemanticNonNullTypeNode > ( start , {
802- kind : Kind . SEMANTIC_NON_NULL_TYPE ,
803- type,
804- } ) ;
805- }
806-
807771 if ( this . expectOptionalToken ( TokenKind . BANG ) ) {
808772 return this . node < NonNullTypeNode > ( start , {
809773 kind : Kind . NON_NULL_TYPE ,
810774 type,
811775 } ) ;
776+ } else if (
777+ allowSemanticNonNull &&
778+ this . expectOptionalToken ( TokenKind . STAR )
779+ ) {
780+ return this . node < SemanticNonNullTypeNode > ( start , {
781+ kind : Kind . SEMANTIC_NON_NULL_TYPE ,
782+ type,
783+ } ) ;
812784 }
813785
814786 return type ;
@@ -951,7 +923,7 @@ export class Parser {
951923 const name = this . parseName ( ) ;
952924 const args = this . parseArgumentDefs ( ) ;
953925 this . expectToken ( TokenKind . COLON ) ;
954- const type = this . parseTypeReference ( ) ;
926+ const type = this . parseTypeReference ( true ) ;
955927 const directives = this . parseConstDirectives ( ) ;
956928 return this . node < FieldDefinitionNode > ( start , {
957929 kind : Kind . FIELD_DEFINITION ,
@@ -983,7 +955,7 @@ export class Parser {
983955 const description = this . parseDescription ( ) ;
984956 const name = this . parseName ( ) ;
985957 this . expectToken ( TokenKind . COLON ) ;
986- const type = this . parseTypeReference ( ) ;
958+ const type = this . parseTypeReference ( false ) ;
987959 let defaultValue ;
988960 if ( this . expectOptionalToken ( TokenKind . EQUALS ) ) {
989961 defaultValue = this . parseConstValueLiteral ( ) ;
0 commit comments