Search in sources :

Example 1 with VertxDataFetcher

use of io.vertx.ext.web.handler.graphql.VertxDataFetcher in project vertx-examples by vert-x3.

the class Server method createGraphQL.

private GraphQL createGraphQL() {
    String schema = vertx.fileSystem().readFileBlocking("links.graphqls").toString();
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> {
        VertxDataFetcher<List<Link>> getAllLinks = new VertxDataFetcher<>(this::getAllLinks);
        return builder.dataFetcher("allLinks", getAllLinks);
    }).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    return GraphQL.newGraphQL(graphQLSchema).build();
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQL(graphql.GraphQL) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) Promise(io.vertx.core.Promise) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Router(io.vertx.ext.web.Router) ArrayList(java.util.ArrayList) GraphQLHandler(io.vertx.ext.web.handler.graphql.GraphQLHandler) Launcher(io.vertx.core.Launcher) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) VertxDataFetcher(io.vertx.ext.web.handler.graphql.VertxDataFetcher) AbstractVerticle(io.vertx.core.AbstractVerticle) GraphQLSchema(graphql.schema.GraphQLSchema) SchemaGenerator(graphql.schema.idl.SchemaGenerator) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) RuntimeWiring(graphql.schema.idl.RuntimeWiring) VertxDataFetcher(io.vertx.ext.web.handler.graphql.VertxDataFetcher) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema)

Aggregations

GraphQL (graphql.GraphQL)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 GraphQLSchema (graphql.schema.GraphQLSchema)1 RuntimeWiring (graphql.schema.idl.RuntimeWiring)1 RuntimeWiring.newRuntimeWiring (graphql.schema.idl.RuntimeWiring.newRuntimeWiring)1 SchemaGenerator (graphql.schema.idl.SchemaGenerator)1 SchemaParser (graphql.schema.idl.SchemaParser)1 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)1 AbstractVerticle (io.vertx.core.AbstractVerticle)1 Launcher (io.vertx.core.Launcher)1 Promise (io.vertx.core.Promise)1 Router (io.vertx.ext.web.Router)1 GraphQLHandler (io.vertx.ext.web.handler.graphql.GraphQLHandler)1 VertxDataFetcher (io.vertx.ext.web.handler.graphql.VertxDataFetcher)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1