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