@@ -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,11 @@ export class Parser {
774752 * - ListType
775753 * - NonNullType
776754 */
777- parseTypeReference ( ) : TypeNode | SemanticNonNullTypeNode {
755+ parseTypeReference ( allowSemanticNonNull : boolean ) : TypeNode | SemanticNonNullTypeNode {
778756 const start = this . _lexer . token ;
779757 let type ;
780758 if ( this . expectOptionalToken ( TokenKind . BRACKET_L ) ) {
781- const innerType = this . parseTypeReference ( ) ;
759+ const innerType = this . parseTypeReference ( allowSemanticNonNull ) ;
782760 this . expectToken ( TokenKind . BRACKET_R ) ;
783761 type = this . node < ListTypeNode > ( start , {
784762 kind : Kind . LIST_TYPE ,
@@ -788,27 +766,16 @@ export class Parser {
788766 type = this . parseNamedType ( ) ;
789767 }
790768
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-
807769 if ( this . expectOptionalToken ( TokenKind . BANG ) ) {
808770 return this . node < NonNullTypeNode > ( start , {
809771 kind : Kind . NON_NULL_TYPE ,
810772 type,
811773 } ) ;
774+ } else if ( allowSemanticNonNull && this . expectOptionalToken ( TokenKind . STAR ) ) {
775+ return this . node < SemanticNonNullTypeNode > ( start , {
776+ kind : Kind . SEMANTIC_NON_NULL_TYPE ,
777+ type,
778+ } ) ;
812779 }
813780
814781 return type ;
@@ -951,7 +918,7 @@ export class Parser {
951918 const name = this . parseName ( ) ;
952919 const args = this . parseArgumentDefs ( ) ;
953920 this . expectToken ( TokenKind . COLON ) ;
954- const type = this . parseTypeReference ( ) ;
921+ const type = this . parseTypeReference ( true ) ;
955922 const directives = this . parseConstDirectives ( ) ;
956923 return this . node < FieldDefinitionNode > ( start , {
957924 kind : Kind . FIELD_DEFINITION ,
@@ -983,7 +950,7 @@ export class Parser {
983950 const description = this . parseDescription ( ) ;
984951 const name = this . parseName ( ) ;
985952 this . expectToken ( TokenKind . COLON ) ;
986- const type = this . parseTypeReference ( ) ;
953+ const type = this . parseTypeReference ( false ) ;
987954 let defaultValue ;
988955 if ( this . expectOptionalToken ( TokenKind . EQUALS ) ) {
989956 defaultValue = this . parseConstValueLiteral ( ) ;
0 commit comments