io.vertx.ext.web.handler.graphql.GraphQLHandler Java Examples

The following examples show how to use io.vertx.ext.web.handler.graphql.GraphQLHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VertxGraphqlResource.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public void setupRouter(@Observes Router router) {
    String schema = "type Query{hello: String}";

    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);

    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
            .type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world")))
            .build();

    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);

    GraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build();

    router.route("/graphql").handler(ApolloWSHandler.create(graphQL));
    router.route("/graphql").handler(GraphQLHandler.create(graphQL));
}
 
Example #2
Source File: GraphQLResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public void setupRouter(@Observes Router router) {
    SchemaParser schemaParser = new SchemaParser();
    final TypeDefinitionRegistry typeDefinitionRegistry;
    try (Reader r = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("graphql/schema.graphql"),
            StandardCharsets.UTF_8)) {
        typeDefinitionRegistry = schemaParser.parse(r);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    DataFetcher<CompletionStage<Book>> dataFetcher = environment -> {
        CompletableFuture<Book> completableFuture = new CompletableFuture<>();
        Book book = getBookById(environment);
        completableFuture.complete(book);
        return completableFuture;
    };

    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
            .type("Query", builder -> builder.dataFetcher("bookById", dataFetcher))
            .build();

    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);

    GraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build();

    router.route("/graphql/server").handler(GraphQLHandler.create(graphQL));
}
 
Example #3
Source File: GraphQLHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized GraphQLHandler queryContext(Function<RoutingContext, Object> factory) {
  queryContextFactory = factory != null ? factory : DEFAULT_QUERY_CONTEXT_FACTORY;
  return this;
}
 
Example #4
Source File: GraphQLHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized GraphQLHandler dataLoaderRegistry(Function<RoutingContext, DataLoaderRegistry> factory) {
  dataLoaderRegistryFactory = factory != null ? factory : DEFAULT_DATA_LOADER_REGISTRY_FACTORY;
  return this;
}
 
Example #5
Source File: GraphQLHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized GraphQLHandler locale(Function<RoutingContext, Locale> factory) {
  localeFactory = factory != null ? factory : DEFAULT_LOCALE_FACTORY;
  return this;
}