Search in sources :

Example 1 with SchemaParser

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

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

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

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

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

SchemaParser (graphql.schema.idl.SchemaParser)24 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)23 GraphQLSchema (graphql.schema.GraphQLSchema)16 SchemaGenerator (graphql.schema.idl.SchemaGenerator)9 RuntimeWiring (graphql.schema.idl.RuntimeWiring)8 Test (org.junit.Test)8 GraphQLSchemaDTO (org.wso2.carbon.apimgt.api.gateway.GraphQLSchemaDTO)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 InboundMessageContext (org.wso2.carbon.apimgt.gateway.inbound.InboundMessageContext)6 InboundProcessorResponseDTO (org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO)6 VerbInfoDTO (org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO)5 ExecutionResult (graphql.ExecutionResult)4 GraphQL (graphql.GraphQL)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 JSONObject (org.json.simple.JSONObject)4 JSONParser (org.json.simple.parser.JSONParser)4 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)3 TypeDefinition (graphql.language.TypeDefinition)3