Search in sources :

Example 16 with Response

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

the class DynamicClientErrorTest method convertToGraphQLClientException.

/**
 * Test the `ResponseImpl.throwExceptionIfErrors` method that should throw a `GraphQLClientException` if the Response
 * contains any errors.
 */
@Test
public void convertToGraphQLClientException() throws ExecutionException, InterruptedException {
    Response response = client.executeSync(document(operation(field("dummy", field("foo"), field("bar")))));
    try {
        ((ResponseImpl) response).throwExceptionIfErrors();
        fail("`throwExceptionIfErrors` call should throw a GraphQLClientException");
    } catch (GraphQLClientException e) {
        assertArrayEquals(new Object[] { "dummy", "bar" }, e.getErrors().get(0).getPath());
    }
}
Also used : Response(io.smallrye.graphql.client.Response) GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.Test)

Example 17 with Response

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

the class AbstractDynamicClientSubscriptionTest method testFailingImmediately.

@Test
public void testFailingImmediately() throws InterruptedException {
    Document document = document(operation(OperationType.SUBSCRIPTION, field("failingImmediately")));
    AtomicReference<Response> response = new AtomicReference<>();
    CountDownLatch finished = new CountDownLatch(1);
    client.subscription(document).subscribe().with(item -> {
        response.set(item);
    }, throwable -> {
    // nothing
    }, () -> {
        finished.countDown();
    });
    finished.await(10, TimeUnit.SECONDS);
    Response actualResponse = response.get();
    assertNotNull("One response was expected to arrive", actualResponse);
    Assert.assertEquals(JsonValue.NULL, actualResponse.getData().get("failingImmediately"));
// FIXME: add an assertion about the contained error message
// right now, there is no error message present, which is a bug
}
Also used : Response(io.smallrye.graphql.client.Response) AtomicReference(java.util.concurrent.atomic.AtomicReference) Document(io.smallrye.graphql.client.core.Document) CountDownLatch(java.util.concurrent.CountDownLatch) 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