From 250204b056f0b04e84d4df33841e8671070247db Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Tue, 20 Oct 2026 21:20:43 +0300 Subject: [PATCH] fix: pass parser options through buildSchema --- .../__tests__/buildASTSchema-test.ts | 41 +++++++++++++++++++ src/utilities/buildASTSchema.ts | 5 +-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/utilities/__tests__/buildASTSchema-test.ts b/src/utilities/__tests__/buildASTSchema-test.ts index 15ff4c098d..517521e320 100644 --- a/src/utilities/__tests__/buildASTSchema-test.ts +++ b/src/utilities/__tests__/buildASTSchema-test.ts @@ -98,6 +98,47 @@ describe('Schema Builder', () => { }); }); + it('forwards the maximum lexical token limit', () => { + const source = 'type Query { field: String }'; + + expect(() => buildSchema(source, { maxLexicalTokens: 7 })).to.not.throw(); + expect(() => buildSchema(source, { maxLexicalTokens: 6 })).to.throw( + 'Syntax Error: Document contains more than 6 tokens. Parsing aborted.', + ); + }); + + it('forwards the deprecated maxTokens alias', () => { + const source = 'type Query { field: Int }'; + expect(() => buildSchema(source, { maxTokens: 7 })).not.to.throw(); + expect(() => buildSchema(source, { maxTokens: 6 })).to.throw( + 'Document contains more than 6 tokens. Parsing aborted.', + ); + expect(() => buildSchema(source, { maxTokens: 0 })).to.throw( + 'Document contains more than 0 tokens. Parsing aborted.', + ); + }); + + it('forwards the maximum source length to the parser', () => { + const source = 'type Query'; + expect(() => + buildSchema(source, { maxSourceLength: source.length }), + ).to.not.throw(); + + const maxSourceLength = source.length - 1; + expect(() => buildSchema(source, { maxSourceLength })).to.throw( + `Syntax Error: Source contains more than ${maxSourceLength} UTF-16 code units. Parsing aborted.`, + ); + }); + + it('forwards the maximum comment limit', () => { + const source = '# comment\ntype Query'; + + expect(() => buildSchema(source, { maxComments: 1 })).to.not.throw(); + expect(() => buildSchema(source, { maxComments: 0 })).to.throw( + 'Syntax Error: Document contains more than 0 comments. Parsing aborted.', + ); + }); + it('Ignores non-type system definitions', () => { const sdl = ` type Query { diff --git a/src/utilities/buildASTSchema.ts b/src/utilities/buildASTSchema.ts index fd63bdd715..9c05418190 100644 --- a/src/utilities/buildASTSchema.ts +++ b/src/utilities/buildASTSchema.ts @@ -151,10 +151,7 @@ export function buildSchema( source: string | Source, options?: BuildSchemaOptions & ParseOptions, ): GraphQLSchema { - const document = parse(source, { - noLocation: options?.noLocation, - experimentalFragmentArguments: options?.experimentalFragmentArguments, - }); + const document = parse(source, options); return buildASTSchema(document, { assumeValidSDL: options?.assumeValidSDL,