All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.nadel.util.SchemaUtil.kt Maven / Gradle / Ivy

Go to download

Nadel is a Java library that combines multiple GrahpQL services together into one API.

There is a newer version: 2024-11-20T03-31-21-302962b7
Show newest version
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)
                }
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy