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);
});
}
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);
});
}
Aggregations