Skip to content

Allow parsing large schema files #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2022
Merged
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
13 changes: 9 additions & 4 deletions src/main/kotlin/graphql/kickstart/tools/SchemaParserBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package graphql.kickstart.tools

import graphql.language.Definition
import graphql.language.Document
import graphql.parser.MultiSourceReader
import graphql.parser.Parser
import graphql.parser.ParserOptions
import graphql.schema.GraphQLScalarType
Expand Down Expand Up @@ -168,12 +169,16 @@ class SchemaParserBuilder {
val parser = Parser()
val documents = mutableListOf<Document>()
try {
files.forEach { documents.add(parser.parseDocument(readFile(it), it)) }
val options = ParserOptions
.getDefaultParserOptions()
.transform { o -> o.maxTokens(MAX_VALUE) }

files.forEach {
val sourceReader = MultiSourceReader.newMultiSourceReader().string(readFile(it), it).trackData(true).build()
documents.add(parser.parseDocument(sourceReader, options))
}

if (schemaString.isNotEmpty()) {
val options = ParserOptions
.getDefaultParserOptions()
.transform { o -> o.maxTokens(MAX_VALUE) }
documents.add(parser.parseDocument(schemaString.toString(), options))
}
} catch (pce: ParseCancellationException) {
Expand Down