@@ -70,7 +70,11 @@ import type {
70
70
import { Location , OperationTypeNode } from './ast.js' ;
71
71
import { DirectiveLocation } from './directiveLocation.js' ;
72
72
import { Kind } from './kinds.js' ;
73
- import { isPunctuatorTokenKind , Lexer } from './lexer.js' ;
73
+ import {
74
+ isPunctuatorTokenKind ,
75
+ Lexer ,
76
+ SchemaCoordinateLexer ,
77
+ } from './lexer.js' ;
74
78
import { isSource , Source } from './source.js' ;
75
79
import { TokenKind } from './tokenKind.js' ;
76
80
@@ -114,6 +118,24 @@ export interface ParseOptions {
114
118
* ```
115
119
*/
116
120
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 ;
117
139
}
118
140
119
141
/**
@@ -199,9 +221,13 @@ export function parseType(
199
221
*/
200
222
export function parseSchemaCoordinate (
201
223
source : string | Source ,
202
- options ?: ParseOptions ,
224
+ options ?: ParseSchemaCoordinateOptions ,
203
225
) : 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
+ } ) ;
205
231
parser . expectToken ( TokenKind . SOF ) ;
206
232
const coordinate = parser . parseSchemaCoordinate ( ) ;
207
233
parser . expectToken ( TokenKind . EOF ) ;
@@ -227,7 +253,8 @@ export class Parser {
227
253
constructor ( source : string | Source , options : ParseOptions = { } ) {
228
254
const sourceObj = isSource ( source ) ? source : new Source ( source ) ;
229
255
230
- this . _lexer = new Lexer ( sourceObj ) ;
256
+ const LexerClass = options . Lexer ?? Lexer ;
257
+ this . _lexer = new LexerClass ( sourceObj ) ;
231
258
this . _options = options ;
232
259
this . _tokenCounter = 0 ;
233
260
}
0 commit comments