Search in sources :

Example 1 with VertxDataFetcher

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

the class VertxDataFetcherTest method graphQL.

@Override
protected GraphQL graphQL() {
    String schema = vertx.fileSystem().readFileBlocking("links.graphqls").toString();
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> {
        VertxDataFetcher<Object> dataFetcher = VertxDataFetcher.create((env, fut) -> fut.complete(getAllLinks(env)));
        return builder.dataFetcher("allLinks", dataFetcher);
    }).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    return GraphQL.newGraphQL(graphQLSchema).build();
}
Also used : VertxDataFetcher(io.vertx.ext.web.handler.graphql.schema.VertxDataFetcher) GraphQL(graphql.GraphQL) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) GraphQLSchema(graphql.schema.GraphQLSchema) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Test(org.junit.Test) SchemaGenerator(graphql.schema.idl.SchemaGenerator) GET(io.vertx.core.http.HttpMethod.GET) RuntimeWiring(graphql.schema.idl.RuntimeWiring) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) VertxDataFetcher(io.vertx.ext.web.handler.graphql.schema.VertxDataFetcher) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 2 with VertxDataFetcher

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

the class GraphQLExamples method futureDataFetcher.

public void futureDataFetcher() {
    VertxDataFetcher<List<Link>> dataFetcher = VertxDataFetcher.create(environment -> {
        Future<List<Link>> future = retrieveLinksFromBackend(environment);
        return future;
    });
    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().type("Query", builder -> builder.dataFetcher("allLinks", dataFetcher)).build();
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQL(graphql.GraphQL) io.vertx.core(io.vertx.core) GraphQLWSHandler(io.vertx.ext.web.handler.graphql.ws.GraphQLWSHandler) FieldWiringEnvironment(graphql.schema.idl.FieldWiringEnvironment) Router(io.vertx.ext.web.Router) io.vertx.ext.web.handler.graphql(io.vertx.ext.web.handler.graphql) org.dataloader(org.dataloader) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) FileUpload(io.vertx.ext.web.FileUpload) VertxPropertyDataFetcher(io.vertx.ext.web.handler.graphql.schema.VertxPropertyDataFetcher) WiringFactory(graphql.schema.idl.WiringFactory) List(java.util.List) VertxDataFetcher(io.vertx.ext.web.handler.graphql.schema.VertxDataFetcher) CompletionStage(java.util.concurrent.CompletionStage) RuntimeWiring(graphql.schema.idl.RuntimeWiring) VertxBatchLoader(io.vertx.ext.web.handler.graphql.dataloader.VertxBatchLoader) DataFetcher(graphql.schema.DataFetcher) HttpServerOptions(io.vertx.core.http.HttpServerOptions) RuntimeWiring(graphql.schema.idl.RuntimeWiring) List(java.util.List)

Example 3 with VertxDataFetcher

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

the class GraphQLExamples method callbackDataFetcher.

public void callbackDataFetcher() {
    VertxDataFetcher<List<Link>> dataFetcher = VertxDataFetcher.create((env, promise) -> {
        retrieveLinksFromBackend(env, promise);
    });
    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().type("Query", builder -> builder.dataFetcher("allLinks", dataFetcher)).build();
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQL(graphql.GraphQL) io.vertx.core(io.vertx.core) GraphQLWSHandler(io.vertx.ext.web.handler.graphql.ws.GraphQLWSHandler) FieldWiringEnvironment(graphql.schema.idl.FieldWiringEnvironment) Router(io.vertx.ext.web.Router) io.vertx.ext.web.handler.graphql(io.vertx.ext.web.handler.graphql) org.dataloader(org.dataloader) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) FileUpload(io.vertx.ext.web.FileUpload) VertxPropertyDataFetcher(io.vertx.ext.web.handler.graphql.schema.VertxPropertyDataFetcher) WiringFactory(graphql.schema.idl.WiringFactory) List(java.util.List) VertxDataFetcher(io.vertx.ext.web.handler.graphql.schema.VertxDataFetcher) CompletionStage(java.util.concurrent.CompletionStage) RuntimeWiring(graphql.schema.idl.RuntimeWiring) VertxBatchLoader(io.vertx.ext.web.handler.graphql.dataloader.VertxBatchLoader) DataFetcher(graphql.schema.DataFetcher) HttpServerOptions(io.vertx.core.http.HttpServerOptions) RuntimeWiring(graphql.schema.idl.RuntimeWiring) List(java.util.List)

Aggregations

GraphQL (graphql.GraphQL)3 RuntimeWiring (graphql.schema.idl.RuntimeWiring)3 VertxDataFetcher (io.vertx.ext.web.handler.graphql.schema.VertxDataFetcher)3 DataFetcher (graphql.schema.DataFetcher)2 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)2 FieldWiringEnvironment (graphql.schema.idl.FieldWiringEnvironment)2 WiringFactory (graphql.schema.idl.WiringFactory)2 io.vertx.core (io.vertx.core)2 HttpServerOptions (io.vertx.core.http.HttpServerOptions)2 FileUpload (io.vertx.ext.web.FileUpload)2 Router (io.vertx.ext.web.Router)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 BodyHandler (io.vertx.ext.web.handler.BodyHandler)2 io.vertx.ext.web.handler.graphql (io.vertx.ext.web.handler.graphql)2 VertxBatchLoader (io.vertx.ext.web.handler.graphql.dataloader.VertxBatchLoader)2 VertxPropertyDataFetcher (io.vertx.ext.web.handler.graphql.schema.VertxPropertyDataFetcher)2 GraphQLWSHandler (io.vertx.ext.web.handler.graphql.ws.GraphQLWSHandler)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionStage (java.util.concurrent.CompletionStage)2