Search in sources :

Example 1 with Response

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

the class RecordAsInputToDynamicClientTest method testSimpleRecord.

@Test
public void testSimpleRecord() throws Exception {
    try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().url(testingURL.toString() + "graphql").build()) {
        Response response = client.executeSync("query { simple {a b} }");
        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 2 with Response

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

the class MyClientUsageString method execute.

public void execute() throws ExecutionException, InterruptedException {
    // <1>
    String queryWithInlineVariables = "query {" + "  allHeroesIn(location: \"Outer Space\") {" + "    name" + "    superPowers" + "  }" + "}";
    Response response = client.executeSync(queryWithInlineVariables);
    // <2>
    String queryWithExtractedVariables = "query($loc: String) {" + "  allHeroesIn(location: $loc) {" + "    name" + "    superPowers" + "  }" + "}";
    // <3>
    Map<String, Object> variables = new HashMap<>();
    variables.put("loc", "Outer Space");
    Response response2 = client.executeSync(queryWithExtractedVariables, variables);
}
Also used : Response(io.smallrye.graphql.client.Response) HashMap(java.util.HashMap)

Example 3 with Response

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

the class DynamicClientSingleOperationsTestBase method testRenamedField.

/**
 * Parsing the response into a model class that contains a renamed field (using @Name)
 */
@Test
public void testRenamedField() throws ExecutionException, InterruptedException {
    Document document = document(operation(field("withRenamedField", field("renamedField:specialName"), field("string"))));
    Response response = client.executeSync(document);
    Dummy ret = response.getObject(Dummy.class, "withRenamedField");
    assertEquals("foo", ret.getRenamedField());
}
Also used : Response(io.smallrye.graphql.client.Response) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Example 4 with Response

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

the class DynamicClientSingleOperationsTestBase method testListWithRenamedField.

@Test
public void testListWithRenamedField() throws ExecutionException, InterruptedException {
    Document document = document(operation(field("listWithRenamedField", field("renamedField:specialName"), field("string"))));
    Response response = client.executeSync(document);
    List<Dummy> ret = response.getList(Dummy.class, "listWithRenamedField");
    assertEquals("foo", ret.get(0).getRenamedField());
    assertEquals("foo2", ret.get(1).getRenamedField());
}
Also used : Response(io.smallrye.graphql.client.Response) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Example 5 with Response

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

the class AbstractDynamicClientSubscriptionTest method testCounting.

@Test
public void testCounting() {
    Document document = document(operation(OperationType.SUBSCRIPTION, field("countToFive")));
    List<Response> responses = client.subscription(document).subscribe().asStream().collect(Collectors.toList());
    for (int i = 0; i < 5; i++) {
        Response response = responses.get(i);
        assertEquals(i, response.getData().getInt("countToFive"));
        assertNoErrors(response.getErrors());
    }
}
Also used : Response(io.smallrye.graphql.client.Response) 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