Search in sources :

Example 1 with GET

use of io.vertx.core.http.HttpMethod.GET in project vertx-web by vert-x3.

the class ApolloTestsServer method start.

@Override
public void start(Promise<Void> startPromise) throws Exception {
    Router router = Router.router(vertx);
    router.route().handler(CorsHandler.create("*").allowedMethod(GET).allowedMethod(POST));
    router.route().handler(BodyHandler.create());
    router.route("/graphql").handler(ApolloWSHandler.create(setupWsGraphQL()).connectionInitHandler(connectionInitEvent -> {
        JsonObject payload = connectionInitEvent.message().content().getJsonObject("payload");
        if (payload != null && payload.containsKey("rejectMessage")) {
            connectionInitEvent.fail(payload.getString("rejectMessage"));
            return;
        }
        connectionInitEvent.complete(payload);
    }));
    GraphQLHandlerOptions graphQLHandlerOptions = new GraphQLHandlerOptions().setRequestBatchingEnabled(true).setRequestMultipartEnabled(true);
    router.route("/graphql").handler(GraphQLHandler.create(setupGraphQL(), graphQLHandlerOptions));
    HttpServerOptions httpServerOptions = new HttpServerOptions().addWebSocketSubProtocol("graphql-ws");
    vertx.createHttpServer(httpServerOptions).requestHandler(router).listen(8080).<Void>mapEmpty().onComplete(ar -> {
        if (ar.succeeded()) {
            System.out.println("Apollo tests server started");
        }
        startPromise.handle(ar);
    });
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQL(graphql.GraphQL) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) Promise(io.vertx.core.Promise) Publisher(org.reactivestreams.Publisher) POST(io.vertx.core.http.HttpMethod.POST) Vertx(io.vertx.core.Vertx) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Router(io.vertx.ext.web.Router) HashMap(java.util.HashMap) BodyHandler(io.vertx.ext.web.handler.BodyHandler) FileUpload(io.vertx.ext.web.FileUpload) Collectors.toList(java.util.stream.Collectors.toList) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) AbstractVerticle(io.vertx.core.AbstractVerticle) Map(java.util.Map) GraphQLSchema(graphql.schema.GraphQLSchema) HttpServerOptions(io.vertx.core.http.HttpServerOptions) JsonObject(io.vertx.core.json.JsonObject) SchemaGenerator(graphql.schema.idl.SchemaGenerator) CorsHandler(io.vertx.ext.web.handler.CorsHandler) GET(io.vertx.core.http.HttpMethod.GET) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with GET

use of io.vertx.core.http.HttpMethod.GET in project vertx-web by vert-x3.

the class GraphQLWSTestsServer method start.

@Override
public void start(Promise<Void> startPromise) throws Exception {
    Router router = Router.router(vertx);
    router.route().handler(CorsHandler.create("*").allowedMethod(GET).allowedMethod(POST));
    router.route().handler(BodyHandler.create());
    GraphQL graphQL = setupGraphQL();
    router.route("/graphql").handler(GraphQLWSHandler.create(graphQL).connectionInitHandler(connectionInitEvent -> {
        JsonObject payload = connectionInitEvent.message().message().getJsonObject("payload");
        if (payload != null && payload.containsKey("rejectMessage")) {
            connectionInitEvent.fail(payload.getString("rejectMessage"));
            return;
        }
        connectionInitEvent.complete(payload);
    }));
    HttpServerOptions httpServerOptions = new HttpServerOptions().addWebSocketSubProtocol("graphql-transport-ws");
    vertx.createHttpServer(httpServerOptions).requestHandler(router).listen(8080).<Void>mapEmpty().onComplete(ar -> {
        if (ar.succeeded()) {
            System.out.println("GraphQLWS tests server started");
        }
        startPromise.handle(ar);
    });
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQL(graphql.GraphQL) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) Promise(io.vertx.core.Promise) Publisher(org.reactivestreams.Publisher) POST(io.vertx.core.http.HttpMethod.POST) Vertx(io.vertx.core.Vertx) GraphQLWSHandler(io.vertx.ext.web.handler.graphql.ws.GraphQLWSHandler) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Router(io.vertx.ext.web.Router) BodyHandler(io.vertx.ext.web.handler.BodyHandler) Stream(java.util.stream.Stream) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) AbstractVerticle(io.vertx.core.AbstractVerticle) GraphQLSchema(graphql.schema.GraphQLSchema) HttpServerOptions(io.vertx.core.http.HttpServerOptions) JsonObject(io.vertx.core.json.JsonObject) SchemaGenerator(graphql.schema.idl.SchemaGenerator) CorsHandler(io.vertx.ext.web.handler.CorsHandler) GET(io.vertx.core.http.HttpMethod.GET) GraphQL(graphql.GraphQL) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

GraphQL (graphql.GraphQL)2 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)2 GraphQLSchema (graphql.schema.GraphQLSchema)2 RuntimeWiring (graphql.schema.idl.RuntimeWiring)2 RuntimeWiring.newRuntimeWiring (graphql.schema.idl.RuntimeWiring.newRuntimeWiring)2 SchemaGenerator (graphql.schema.idl.SchemaGenerator)2 SchemaParser (graphql.schema.idl.SchemaParser)2 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)2 AbstractVerticle (io.vertx.core.AbstractVerticle)2 Promise (io.vertx.core.Promise)2 Vertx (io.vertx.core.Vertx)2 GET (io.vertx.core.http.HttpMethod.GET)2 POST (io.vertx.core.http.HttpMethod.POST)2 HttpServerOptions (io.vertx.core.http.HttpServerOptions)2 JsonObject (io.vertx.core.json.JsonObject)2 Router (io.vertx.ext.web.Router)2 BodyHandler (io.vertx.ext.web.handler.BodyHandler)2 CorsHandler (io.vertx.ext.web.handler.CorsHandler)2 Publisher (org.reactivestreams.Publisher)2 FileUpload (io.vertx.ext.web.FileUpload)1