Search in sources :

Example 1 with ResultBuilder

use of io.smallrye.graphql.client.impl.typesafe.ResultBuilder in project smallrye-graphql by smallrye.

the class VertxTypesafeGraphQLClientProxy method executeSingleResultOperationOverHttpSync.

private Object executeSingleResultOperationOverHttpSync(MethodInvocation method, JsonObject request, MultiMap headers) {
    String response = postSync(request.toString(), headers);
    log.debugf("response graphql: %s", response);
    return new ResultBuilder(method, response).read();
}
Also used : ResultBuilder(io.smallrye.graphql.client.impl.typesafe.ResultBuilder)

Example 2 with ResultBuilder

use of io.smallrye.graphql.client.impl.typesafe.ResultBuilder 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 3 with ResultBuilder

use of io.smallrye.graphql.client.impl.typesafe.ResultBuilder 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

ResultBuilder (io.smallrye.graphql.client.impl.typesafe.ResultBuilder)3 InvalidResponseException (io.smallrye.graphql.client.InvalidResponseException)2 WebSocketSubprotocolHandler (io.smallrye.graphql.client.vertx.websocket.WebSocketSubprotocolHandler)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 JsonObject (javax.json.JsonObject)2