graphql.nadel.util.SchemaUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nadel Show documentation
Show all versions of nadel Show documentation
Nadel is a Java library that combines multiple GrahpQL services together into one API.
package graphql.nadel.util
import graphql.language.SDLDefinition
import graphql.parser.Parser
import graphql.parser.ParserEnvironment
import graphql.parser.ParserOptions
import graphql.schema.idl.SchemaParser
import graphql.schema.idl.TypeDefinitionRegistry
import java.io.Reader
internal object SchemaUtil {
private val parser = Parser()
private val schemaParser = SchemaParser()
fun parseSchemaDefinitions(
schema: Reader,
maxTokens: Int = Int.MAX_VALUE,
captureSourceLocation: Boolean = false,
): List {
return parser
.parseDocument(
ParserEnvironment.newParserEnvironment()
.document(schema)
.parserOptions(
ParserOptions.getDefaultSdlParserOptions()
.transform {
it
.maxTokens(maxTokens)
.captureSourceLocation(captureSourceLocation)
}
)
.build(),
)
.getDefinitionsOfType(SDLDefinition::class.java)
}
fun parseTypeDefinitionRegistry(
schema: Reader,
maxTokens: Int = Int.MAX_VALUE,
captureSourceLocation: Boolean = false,
): TypeDefinitionRegistry {
return schemaParser.parse(
schema,
ParserOptions.getDefaultSdlParserOptions()
.transform {
it
.maxTokens(maxTokens)
.captureSourceLocation(captureSourceLocation)
}
)
}
}