Search in sources :

Example 1 with StaticDataFetcher

use of graphql.schema.StaticDataFetcher in project graphql-java by graphql-java.

the class HelloWorld method main.

public static void main(String[] args) {
    String schema = "type Query{hello: String}";
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world"))).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    GraphQL build = GraphQL.newGraphQL(graphQLSchema).build();
    ExecutionResult executionResult = build.execute("{hello}");
    System.out.println(executionResult.getData().toString());
// Prints: {hello=world}
}
Also used : ExecutionResult(graphql.ExecutionResult) StaticDataFetcher(graphql.schema.StaticDataFetcher) 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) SchemaGenerator(graphql.schema.idl.SchemaGenerator) RuntimeWiring(graphql.schema.idl.RuntimeWiring) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) GraphQL(graphql.GraphQL) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) StaticDataFetcher(graphql.schema.StaticDataFetcher) ExecutionResult(graphql.ExecutionResult) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 2 with StaticDataFetcher

use of graphql.schema.StaticDataFetcher in project nextprot-api by calipho-sib.

the class GraphQLTest method main.

public static void main(String[] args) {
    String schema = "type Query{hello: String} schema{query: Query}";
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world"))).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    GraphQL build = GraphQL.newGraphQL(graphQLSchema).build();
    ExecutionResult executionResult = build.execute("{hello}");
    System.out.println(executionResult.getData().toString());
// Prints: {hello=world}
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) StaticDataFetcher(graphql.schema.StaticDataFetcher) Arrays(java.util.Arrays) GraphQL(graphql.GraphQL) Entry(org.nextprot.api.core.domain.Entry) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Autowired(org.springframework.beans.factory.annotation.Autowired) GraphQLQueryResolver(com.coxautodev.graphql.tools.GraphQLQueryResolver) ExecutionResult(graphql.ExecutionResult) Component(org.springframework.stereotype.Component) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema) SchemaGenerator(graphql.schema.idl.SchemaGenerator) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) RuntimeWiring(graphql.schema.idl.RuntimeWiring) GraphQL(graphql.GraphQL) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) StaticDataFetcher(graphql.schema.StaticDataFetcher) ExecutionResult(graphql.ExecutionResult) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema)

Aggregations

ExecutionResult (graphql.ExecutionResult)2 GraphQL (graphql.GraphQL)2 GraphQLSchema (graphql.schema.GraphQLSchema)2 StaticDataFetcher (graphql.schema.StaticDataFetcher)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 GraphQLQueryResolver (com.coxautodev.graphql.tools.GraphQLQueryResolver)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 Arrays (java.util.Arrays)1 Entry (org.nextprot.api.core.domain.Entry)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1