Search in sources :

Example 1 with RuntimeWiring

use of graphql.schema.idl.RuntimeWiring in project graphql-java by graphql-java.

the class ReadmeExamples method parsedSchemaExample.

void parsedSchemaExample() {
    SchemaParser schemaParser = new SchemaParser();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    File schemaFile = loadSchema("starWarsSchema.graphqls");
    TypeDefinitionRegistry typeRegistry = schemaParser.parse(schemaFile);
    RuntimeWiring wiring = buildRuntimeWiring();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, wiring);
}
Also used : RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaGenerator(graphql.schema.idl.SchemaGenerator) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaParser(graphql.schema.idl.SchemaParser) File(java.io.File) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 2 with RuntimeWiring

use of graphql.schema.idl.RuntimeWiring in project graphql-java by graphql-java.

the class BatchCompare method buildBatchedSchema.

GraphQLSchema buildBatchedSchema() {
    Reader streamReader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("storesanddepartments.graphqls"));
    TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(streamReader);
    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().type(TypeRuntimeWiring.newTypeWiring("Query").dataFetcher("shops", BatchCompareDataFetchers.shopsDataFetcher)).type(TypeRuntimeWiring.newTypeWiring("Shop").dataFetcher("departments", BatchCompareDataFetchers.departmentsForShopsBatchedDataFetcher)).type(TypeRuntimeWiring.newTypeWiring("Department").dataFetcher("products", BatchCompareDataFetchers.productsForDepartmentsBatchedDataFetcher)).build();
    return new SchemaGenerator().makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
}
Also used : InputStreamReader(java.io.InputStreamReader) TypeRuntimeWiring(graphql.schema.idl.TypeRuntimeWiring) RuntimeWiring(graphql.schema.idl.RuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SchemaParser(graphql.schema.idl.SchemaParser)

Example 3 with RuntimeWiring

use of graphql.schema.idl.RuntimeWiring 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 4 with RuntimeWiring

use of graphql.schema.idl.RuntimeWiring 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)

Example 5 with RuntimeWiring

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

the class GraphQlExecutorImpl method postConstruct.

@PostConstruct
private void postConstruct() {
    SchemaParser schemaParser = new SchemaParser();
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("swapi.graphqls").getFile());
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(file);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("entry", entryDataFetcher)).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    graphQL = GraphQL.newGraphQL(graphQLSchema).build();
}
Also used : GraphQL(graphql.GraphQL) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) HashMap(java.util.HashMap) File(java.io.File) ExecutionResult(graphql.ExecutionResult) LinkedHashMap(java.util.LinkedHashMap) Component(org.springframework.stereotype.Component) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) GraphQLException(graphql.GraphQLException) SchemaGenerator(graphql.schema.idl.SchemaGenerator) TypeReference(com.fasterxml.jackson.core.type.TypeReference) GraphQlExecutor(org.nextprot.api.web.service.GraphQlExecutor) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) RuntimeWiring(graphql.schema.idl.RuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) SchemaParser(graphql.schema.idl.SchemaParser) File(java.io.File) GraphQLSchema(graphql.schema.GraphQLSchema) PostConstruct(javax.annotation.PostConstruct)

Aggregations

RuntimeWiring (graphql.schema.idl.RuntimeWiring)8 SchemaGenerator (graphql.schema.idl.SchemaGenerator)8 SchemaParser (graphql.schema.idl.SchemaParser)8 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)8 GraphQLSchema (graphql.schema.GraphQLSchema)5 ExecutionResult (graphql.ExecutionResult)4 GraphQL (graphql.GraphQL)4 RuntimeWiring.newRuntimeWiring (graphql.schema.idl.RuntimeWiring.newRuntimeWiring)3 InputStreamReader (java.io.InputStreamReader)3 Reader (java.io.Reader)3 DataFetcher (graphql.schema.DataFetcher)2 StaticDataFetcher (graphql.schema.StaticDataFetcher)2 TypeRuntimeWiring (graphql.schema.idl.TypeRuntimeWiring)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 GraphQLQueryResolver (com.coxautodev.graphql.tools.GraphQLQueryResolver)1