Created
August 10, 2019 11:18
-
-
Save mbbhalla/94101f74cf8051b21a1da35a10d90ba4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
@Singleton | |
public GraphQL graphQL( | |
final ResourceResolver resourceResolver, | |
final DataFetcherProvider dataFetcherProvider) { | |
val schemaParser = new SchemaParser(); | |
val schemaGenerator = new SchemaGenerator(); | |
// Parse the schema. | |
val typeRegistry = new TypeDefinitionRegistry(); | |
typeRegistry.merge(schemaParser.parse(new BufferedReader(new InputStreamReader( | |
resourceResolver.getResourceAsStream("classpath:schema.graphqls").get() | |
)))); | |
// Create the runtime wiring. | |
val runtimeWiring = RuntimeWiring.newRuntimeWiring() | |
.type(TypeRuntimeWiring | |
.newTypeWiring("Query") | |
.dataFetcher("allLinks", dataFetcherProvider.getAllLinksDataFetcher())) | |
.type(TypeRuntimeWiring | |
.newTypeWiring("Mutation") | |
.dataFetcher("createLink", dataFetcherProvider.createLinkDataFetcher())) | |
.build(); | |
// Create the executable schema. | |
val graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring); | |
// Return the GraphQL bean. | |
return GraphQL.newGraphQL(graphQLSchema).build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment