Search in sources :

Example 11 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class RecordAsInputToDynamicClientTest method testPartial.

/**
 * Try selecting only a subset of fields supported by the record.
 */
@Test
public void testPartial() throws Exception {
    try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().url(testingURL.toString() + "graphql").build()) {
        Response response = client.executeSync("query { simple {a} }");
        SimpleRecord result = response.getObject(SimpleRecord.class, "simple");
        assertEquals("a", result.a());
        assertNull(result.b());
    }
}
Also used : Response(io.smallrye.graphql.client.Response) VertxDynamicGraphQLClientBuilder(io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) Test(org.junit.Test)

Example 12 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class RecordAsInputToDynamicClientTest method testReversed.

/**
 * Just to be sure that if I reverse the order of fields in the query,
 * they won't get mixed up on the client side.
 */
@Test
public void testReversed() throws Exception {
    try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().url(testingURL.toString() + "graphql").build()) {
        Response response = client.executeSync("query { simple {b a} }");
        SimpleRecord result = response.getObject(SimpleRecord.class, "simple");
        assertEquals("a", result.a());
        assertEquals("b", result.b());
    }
}
Also used : Response(io.smallrye.graphql.client.Response) VertxDynamicGraphQLClientBuilder(io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) Test(org.junit.Test)

Example 13 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class MyClientUsage method execute.

public void execute() throws ExecutionException, InterruptedException {
    Document document = document(operation(field("allHeroesIn", args(arg("location", "Outer Space")), field("name"), field("superPowers"))));
    // <2>
    Response response = client.executeSync(document);
    // <3>
    JsonArray heroesArray = response.getData().getJsonArray("allHeroesIn");
    // <4>
    List<SuperHero> heroes = response.getList(SuperHero.class, "allHeroesIn");
}
Also used : Response(io.smallrye.graphql.client.Response) JsonArray(javax.json.JsonArray) SuperHero(examples.typesafeclient.SuperHero) Document(io.smallrye.graphql.client.core.Document)

Example 14 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class SubscriptionInitializationTimeoutTest method test.

@Test
public void test() throws ExecutionException, InterruptedException, TimeoutException {
    HttpServer server = runMockServer();
    try {
        DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().subprotocols(WebsocketSubprotocol.GRAPHQL_TRANSPORT_WS).websocketInitializationTimeout(100).url("http://localhost:" + server.actualPort()).build();
        Uni<Throwable> testFinish = Uni.createFrom().emitter(emitter -> {
            Multi<Response> subscriptionMulti = client.subscription("{}");
            subscriptionMulti.subscribe().with(item -> {
                emitter.complete(null);
            }, failure -> {
                emitter.complete(failure);
            });
        });
        Throwable testResult = testFinish.await().atMost(Duration.ofSeconds(3));
        Assertions.assertNotNull(testResult);
        Assertions.assertTrue(testResult.getMessage().contains("Server did not send a connection_ack message"), testResult.getMessage());
    } finally {
        server.close();
    }
}
Also used : Response(io.smallrye.graphql.client.Response) HttpServer(io.vertx.core.http.HttpServer) VertxDynamicGraphQLClientBuilder(io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) Test(org.junit.jupiter.api.Test)

Example 15 with Response

use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.

the class DynamicClientSingleOperationsTestBase method testSimpleQueryWithArgument.

@Test
public void testSimpleQueryWithArgument() throws ExecutionException, InterruptedException {
    Document document = document(operation(field("queryWithArgument", args(arg("number", 12)), field("integer"))));
    Response response = client.executeSync(document);
    JsonObject data = response.getData();
    assertEquals(12, data.getJsonObject("queryWithArgument").getInt("integer"));
}
Also used : Response(io.smallrye.graphql.client.Response) JsonObject(javax.json.JsonObject) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Aggregations

Response (io.smallrye.graphql.client.Response)17 Test (org.junit.Test)13 Document (io.smallrye.graphql.client.core.Document)11 DynamicGraphQLClient (io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient)4 VertxDynamicGraphQLClientBuilder (io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder)4 Calendar (java.util.Calendar)2 Date (java.util.Date)2 SuperHero (examples.typesafeclient.SuperHero)1 Blocking (io.smallrye.common.annotation.Blocking)1 GraphQLClientException (io.smallrye.graphql.client.GraphQLClientException)1 ResponseImpl (io.smallrye.graphql.client.impl.ResponseImpl)1 HttpServer (io.vertx.core.http.HttpServer)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1