Search in sources :

Example 11 with InvalidResponseException

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

the class NestedBehavior method shouldFailToSetMissingPrimitiveField.

@Test
void shouldFailToSetMissingPrimitiveField() {
    fixture.returnsData("'call':{'foo':'a'}");
    MissingPrimitiveFieldApi api = fixture.build(MissingPrimitiveFieldApi.class);
    InvalidResponseException thrown = catchThrowableOfType(api::call, InvalidResponseException.class);
    then(thrown).hasMessage("missing boolean value for " + MissingPrimitiveFieldApi.class.getName() + "#call.bar");
}
Also used : InvalidResponseException(io.smallrye.graphql.client.InvalidResponseException) Test(org.junit.jupiter.api.Test)

Example 12 with InvalidResponseException

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

the class NestedBehavior method shouldFailToAssignNumberToObjectListQuery.

@Test
void shouldFailToAssignNumberToObjectListQuery() {
    fixture.returnsData("'greetings':[123,456.78]");
    ObjectListApi api = fixture.build(ObjectListApi.class);
    InvalidResponseException thrown = catchThrowableOfType(api::greetings, InvalidResponseException.class);
    then(thrown).hasMessage("invalid " + Greeting.class.getName() + " value for " + ObjectListApi.class.getName() + "#greetings[0]: 123");
}
Also used : InvalidResponseException(io.smallrye.graphql.client.InvalidResponseException) Test(org.junit.jupiter.api.Test)

Example 13 with InvalidResponseException

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

the class NestedBehavior method shouldFailToAssignBooleanToSet.

@Test
void shouldFailToAssignBooleanToSet() {
    fixture.returnsData("'greetings':true");
    StringSetApi api = fixture.build(StringSetApi.class);
    InvalidResponseException thrown = catchThrowableOfType(api::greetings, InvalidResponseException.class);
    then(thrown).hasMessage("invalid java.util.Set<java.lang.String> value for " + StringSetApi.class.getName() + "#greetings: true");
}
Also used : InvalidResponseException(io.smallrye.graphql.client.InvalidResponseException) Test(org.junit.jupiter.api.Test)

Example 14 with InvalidResponseException

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

the class VertxTypesafeGraphQLClientProxy method executeSingleResultOperationOverWebsocket.

private Uni<Object> executeSingleResultOperationOverWebsocket(MethodInvocation method, JsonObject request) {
    AtomicReference<String> operationId = new AtomicReference<>();
    AtomicReference<WebSocketSubprotocolHandler> handlerRef = new AtomicReference<>();
    Uni<String> rawUni = Uni.createFrom().emitter(rawEmitter -> {
        webSocketHandler().subscribe().with((handler) -> {
            handlerRef.set(handler);
            operationId.set(handler.executeUni(request, rawEmitter));
        });
    });
    return rawUni.onCancellation().invoke(() -> {
        String id = operationId.get();
        log.trace("Received onCancellation on operation ID " + id);
        if (id != null) {
            handlerRef.get().cancelMulti(id);
        } else {
            log.trace("Received onCancellation on an operation that does not have an ID yet");
        }
    }).onItem().transform(data -> {
        Object object = new ResultBuilder(method, data).read();
        if (object != null) {
            return object;
        } else {
            throw new InvalidResponseException("Couldn't find neither data nor errors in the response: " + data);
        }
    });
}
Also used : ResultBuilder(io.smallrye.graphql.client.impl.typesafe.ResultBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) JsonObject(javax.json.JsonObject) WebSocketSubprotocolHandler(io.smallrye.graphql.client.vertx.websocket.WebSocketSubprotocolHandler) InvalidResponseException(io.smallrye.graphql.client.InvalidResponseException)

Example 15 with InvalidResponseException

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

the class VertxTypesafeGraphQLClientProxy method executeSubscriptionOverWebsocket.

private Multi<Object> executeSubscriptionOverWebsocket(MethodInvocation method, JsonObject request) {
    AtomicReference<String> operationId = new AtomicReference<>();
    AtomicReference<WebSocketSubprotocolHandler> handlerRef = new AtomicReference<>();
    Multi<String> rawMulti = Multi.createFrom().emitter(rawEmitter -> {
        webSocketHandler().subscribe().with(handler -> {
            handlerRef.set(handler);
            operationId.set(handler.executeMulti(request, rawEmitter));
        });
    });
    return rawMulti.onCancellation().invoke(() -> {
        handlerRef.get().cancelMulti(operationId.get());
    }).onItem().transform(data -> {
        Object object = new ResultBuilder(method, data).read();
        if (object != null) {
            return object;
        } else {
            throw new InvalidResponseException("Couldn't find neither data nor errors in the response: " + data);
        }
    });
}
Also used : ResultBuilder(io.smallrye.graphql.client.impl.typesafe.ResultBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) JsonObject(javax.json.JsonObject) WebSocketSubprotocolHandler(io.smallrye.graphql.client.vertx.websocket.WebSocketSubprotocolHandler) InvalidResponseException(io.smallrye.graphql.client.InvalidResponseException)

Aggregations

InvalidResponseException (io.smallrye.graphql.client.InvalidResponseException)25 Test (org.junit.jupiter.api.Test)15 WebSocketSubprotocolHandler (io.smallrye.graphql.client.vertx.websocket.WebSocketSubprotocolHandler)4 JsonObject (javax.json.JsonObject)4 JsonValue (javax.json.JsonValue)4 Map (java.util.Map)3 JsonString (javax.json.JsonString)3 GraphQLClientException (io.smallrye.graphql.client.GraphQLClientException)2 GraphQLError (io.smallrye.graphql.client.GraphQLError)2 ResponseReader (io.smallrye.graphql.client.impl.ResponseReader)2 ResultBuilder (io.smallrye.graphql.client.impl.typesafe.ResultBuilder)2 IncrementingNumberOperationIDGenerator (io.smallrye.graphql.client.vertx.websocket.opid.IncrementingNumberOperationIDGenerator)2 OperationIDGenerator (io.smallrye.graphql.client.vertx.websocket.opid.OperationIDGenerator)2 Uni (io.smallrye.mutiny.Uni)2 Cancellable (io.smallrye.mutiny.subscription.Cancellable)2 MultiEmitter (io.smallrye.mutiny.subscription.MultiEmitter)2 UniEmitter (io.smallrye.mutiny.subscription.UniEmitter)2 WebSocket (io.vertx.core.http.WebSocket)2 StringReader (java.io.StringReader)2 Duration (java.time.Duration)2