@@ -70,7 +70,11 @@ import type {
7070import { Location , OperationTypeNode } from './ast.js' ;
7171import { DirectiveLocation } from './directiveLocation.js' ;
7272import { Kind } from './kinds.js' ;
73- import { isPunctuatorTokenKind , Lexer } from './lexer.js' ;
73+ import {
74+ isPunctuatorTokenKind ,
75+ Lexer ,
76+ SchemaCoordinateLexer ,
77+ } from './lexer.js' ;
7478import { isSource , Source } from './source.js' ;
7579import { TokenKind } from './tokenKind.js' ;
7680
@@ -114,6 +118,24 @@ export interface ParseOptions {
114118 * ```
115119 */
116120 experimentalFragmentArguments ?: boolean | undefined ;
121+
122+ /**
123+ * You may override the Lexer class used to lex the source; this is used by
124+ * schema coordinates to introduce a lexer that forbids ignored tokens.
125+ */
126+ Lexer ?: typeof Lexer | undefined ;
127+ }
128+
129+ /**
130+ * Configuration options to control schema coordinate parser behavior
131+ */
132+ export interface ParseSchemaCoordinateOptions {
133+ /**
134+ * By default, the parser creates AST nodes that know the location
135+ * in the source that they correspond to. This configuration flag
136+ * disables that behavior for performance or testing.
137+ */
138+ noLocation ?: boolean | undefined ;
117139}
118140
119141/**
@@ -199,9 +221,13 @@ export function parseType(
199221 */
200222export function parseSchemaCoordinate (
201223 source : string | Source ,
202- options ?: ParseOptions ,
224+ options ?: ParseSchemaCoordinateOptions ,
203225) : SchemaCoordinateNode {
204- const parser = new Parser ( source , options ) ;
226+ // Ignored tokens are excluded syntax for a Schema Coordinate.
227+ const parser = new Parser ( source , {
228+ ...options ,
229+ Lexer : SchemaCoordinateLexer ,
230+ } ) ;
205231 parser . expectToken ( TokenKind . SOF ) ;
206232 const coordinate = parser . parseSchemaCoordinate ( ) ;
207233 parser . expectToken ( TokenKind . EOF ) ;
@@ -227,7 +253,8 @@ export class Parser {
227253 constructor ( source : string | Source , options : ParseOptions = { } ) {
228254 const sourceObj = isSource ( source ) ? source : new Source ( source ) ;
229255
230- this . _lexer = new Lexer ( sourceObj ) ;
256+ const LexerClass = options . Lexer ?? Lexer ;
257+ this . _lexer = new LexerClass ( sourceObj ) ;
231258 this . _options = options ;
232259 this . _tokenCounter = 0 ;
233260 }
0 commit comments