graphql.schema.StaticDataFetcher Java Examples

The following examples show how to use graphql.schema.StaticDataFetcher. 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: GraphQLConfigurationProvider.java    From samples with MIT License 5 votes vote down vote up
private GraphQLSchema createSchema() {
  TypeDefinitionRegistry typeRegistry = new SchemaParser().parse(loadSchemaFile());

  RuntimeWiring runtimeWiring = newRuntimeWiring()
      .type(newTypeWiring("Query").dataFetcher("hello", new StaticDataFetcher("world")))
      .type(newTypeWiring("Subscription").dataFetcher("ping", pingFetcher()))
      .build();

  SchemaGenerator schemaGenerator = new SchemaGenerator();
  return schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
}