Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/utilities/__tests__/buildASTSchema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions src/utilities/buildASTSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading