Search in sources :

Example 31 with SchemaParser

use of graphql.schema.idl.SchemaParser in project vertx-web by vert-x3.

the class VertxBatchLoaderTest method graphQL.

@Override
protected GraphQL graphQL() {
    String schema = vertx.fileSystem().readFileBlocking("links.graphqls").toString();
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("allLinks", this::getAllLinks)).type("Link", builder -> builder.dataFetcher("postedBy", this::getLinkPostedBy)).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    DataLoaderDispatcherInstrumentation dispatcherInstrumentation = new DataLoaderDispatcherInstrumentation();
    return GraphQL.newGraphQL(graphQLSchema).instrumentation(dispatcherInstrumentation).build();
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) DataLoaderRegistry(org.dataloader.DataLoaderRegistry) GraphQL(graphql.GraphQL) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) DataLoader(org.dataloader.DataLoader) DataLoaderDispatcherInstrumentation(graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation) Collectors.toList(java.util.stream.Collectors.toList) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) VertxBatchLoader(io.vertx.ext.web.handler.graphql.dataloader.VertxBatchLoader) GraphQLSchema(graphql.schema.GraphQLSchema) SchemaGenerator(graphql.schema.idl.SchemaGenerator) BatchLoaderWithContext(org.dataloader.BatchLoaderWithContext) DataLoaderFactory(org.dataloader.DataLoaderFactory) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) RuntimeWiring(graphql.schema.idl.RuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) DataLoaderDispatcherInstrumentation(graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 32 with SchemaParser

use of graphql.schema.idl.SchemaParser in project vertx-web by vert-x3.

the class VertxMappedBatchLoaderTest method graphQL.

@Override
protected GraphQL graphQL() {
    String schema = vertx.fileSystem().readFileBlocking("links.graphqls").toString();
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("allLinks", this::getAllLinks)).type("Link", builder -> builder.dataFetcher("postedBy", this::getLinkPostedBy)).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    DataLoaderDispatcherInstrumentation dispatcherInstrumentation = new DataLoaderDispatcherInstrumentation();
    return GraphQL.newGraphQL(graphQLSchema).instrumentation(dispatcherInstrumentation).build();
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) DataLoaderRegistry(org.dataloader.DataLoaderRegistry) GraphQL(graphql.GraphQL) MappedBatchLoaderWithContext(org.dataloader.MappedBatchLoaderWithContext) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VertxMappedBatchLoader(io.vertx.ext.web.handler.graphql.dataloader.VertxMappedBatchLoader) Test(org.junit.Test) DataLoader(org.dataloader.DataLoader) Function(java.util.function.Function) DataLoaderDispatcherInstrumentation(graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation) Collectors.toMap(java.util.stream.Collectors.toMap) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema) SchemaGenerator(graphql.schema.idl.SchemaGenerator) DataLoaderFactory(org.dataloader.DataLoaderFactory) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) RuntimeWiring(graphql.schema.idl.RuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) DataLoaderDispatcherInstrumentation(graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 33 with SchemaParser

use of graphql.schema.idl.SchemaParser in project vertx-web by vert-x3.

the class ApolloWSHandlerTest method graphQL.

protected GraphQL graphQL() {
    String schema = vertx.fileSystem().readFileBlocking("counter.graphqls").toString();
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("staticCounter", this::getStaticCounter)).type("Subscription", builder -> builder.dataFetcher("counter", this::getCounter)).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    return GraphQL.newGraphQL(graphQLSchema).build();
}
Also used : IntStream(java.util.stream.IntStream) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQL(graphql.GraphQL) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) SchemaParser(graphql.schema.idl.SchemaParser) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) GraphQLSchema(graphql.schema.GraphQLSchema) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) WebTestBase(io.vertx.ext.web.WebTestBase) Publisher(org.reactivestreams.Publisher) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Test(org.junit.Test) WebSocket(io.vertx.core.http.WebSocket) NetClientOptions(io.vertx.core.net.NetClientOptions) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) RuntimeWiring(graphql.schema.idl.RuntimeWiring) NetServer(io.vertx.core.net.NetServer) Subscription(org.reactivestreams.Subscription) SchemaGenerator(graphql.schema.idl.SchemaGenerator) ApolloWSMessageType(io.vertx.ext.web.handler.graphql.ApolloWSMessageType) Handler(io.vertx.core.Handler) WebSocketFrame(io.vertx.core.http.WebSocketFrame) GET(io.vertx.core.http.HttpMethod.GET) NetSocket(io.vertx.core.net.NetSocket) 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) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 34 with SchemaParser

use of graphql.schema.idl.SchemaParser in project vertx-web by vert-x3.

the class MultipartRequestTest method graphQL.

private GraphQL graphQL() {
    final String schema = vertx.fileSystem().readFileBlocking("upload.graphqls").toString();
    final String emptyQueryschema = vertx.fileSystem().readFileBlocking("emptyQuery.graphqls").toString();
    final SchemaParser schemaParser = new SchemaParser();
    final TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema).merge(schemaParser.parse(emptyQueryschema));
    final RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().scalar(UploadScalar.build()).type("Mutation", builder -> {
        builder.dataFetcher("singleUpload", this::singleUpload);
        builder.dataFetcher("multipleUpload", this::multipleUpload);
        return builder;
    }).build();
    final SchemaGenerator schemaGenerator = new SchemaGenerator();
    final GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    return GraphQL.newGraphQL(graphQLSchema).build();
}
Also used : GraphQL(graphql.GraphQL) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) RequestOptions(io.vertx.core.http.RequestOptions) Test(org.junit.Test) BodyHandler(io.vertx.ext.web.handler.BodyHandler) FileUpload(io.vertx.ext.web.FileUpload) HttpClientResponse(io.vertx.core.http.HttpClientResponse) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) HttpMethod(io.vertx.core.http.HttpMethod) graphql.schema(graphql.schema) JsonObject(io.vertx.core.json.JsonObject) SchemaGenerator(graphql.schema.idl.SchemaGenerator) WebTestBase(io.vertx.ext.web.WebTestBase) HttpClient(io.vertx.core.http.HttpClient) RuntimeWiring(graphql.schema.idl.RuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) SchemaParser(graphql.schema.idl.SchemaParser)

Example 35 with SchemaParser

use of graphql.schema.idl.SchemaParser in project vertx-web by vert-x3.

the class ApolloTestsServer method setupWsGraphQL.

private GraphQL setupWsGraphQL() {
    String schema = vertx.fileSystem().readFileBlocking("counter.graphqls").toString();
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
    RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("staticCounter", this::staticCounter)).type("Subscription", builder -> builder.dataFetcher("counter", this::counter)).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
    return GraphQL.newGraphQL(graphQLSchema).build();
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQL(graphql.GraphQL) RuntimeWiring.newRuntimeWiring(graphql.schema.idl.RuntimeWiring.newRuntimeWiring) Promise(io.vertx.core.Promise) Publisher(org.reactivestreams.Publisher) POST(io.vertx.core.http.HttpMethod.POST) Vertx(io.vertx.core.Vertx) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Router(io.vertx.ext.web.Router) HashMap(java.util.HashMap) BodyHandler(io.vertx.ext.web.handler.BodyHandler) FileUpload(io.vertx.ext.web.FileUpload) Collectors.toList(java.util.stream.Collectors.toList) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) AbstractVerticle(io.vertx.core.AbstractVerticle) Map(java.util.Map) GraphQLSchema(graphql.schema.GraphQLSchema) HttpServerOptions(io.vertx.core.http.HttpServerOptions) JsonObject(io.vertx.core.json.JsonObject) SchemaGenerator(graphql.schema.idl.SchemaGenerator) CorsHandler(io.vertx.ext.web.handler.CorsHandler) GET(io.vertx.core.http.HttpMethod.GET) 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) GraphQLSchema(graphql.schema.GraphQLSchema)

Aggregations

SchemaParser (graphql.schema.idl.SchemaParser)36 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)35 GraphQLSchema (graphql.schema.GraphQLSchema)27 SchemaGenerator (graphql.schema.idl.SchemaGenerator)21 RuntimeWiring (graphql.schema.idl.RuntimeWiring)20 GraphQL (graphql.GraphQL)16 RuntimeWiring.newRuntimeWiring (graphql.schema.idl.RuntimeWiring.newRuntimeWiring)14 Test (org.junit.Test)14 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)11 GraphQLSchemaDTO (org.wso2.carbon.apimgt.api.gateway.GraphQLSchemaDTO)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 GET (io.vertx.core.http.HttpMethod.GET)6 ArrayList (java.util.ArrayList)6 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 AbstractVerticle (io.vertx.core.AbstractVerticle)5 Router (io.vertx.ext.web.Router)5 VerbInfoDTO (org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO)5