Search in sources :

Example 1 with Error

use of com.yahoo.elide.graphql.subscriptions.websocket.protocol.Error in project elide by yahoo.

the class SubscriptionWebSocketTestClient method onMessage.

@OnMessage
public void onMessage(String text) throws Exception {
    JsonNode type = mapper.readTree(text).get("type");
    MessageType messageType = MessageType.valueOf(type.textValue().toUpperCase(Locale.ROOT));
    switch(messageType) {
        case CONNECTION_ACK:
            {
                Integer id = 1;
                for (String query : queries) {
                    Subscribe subscribe = Subscribe.builder().id(id.toString()).payload(Subscribe.Payload.builder().query(query).build()).build();
                    session.getBasicRemote().sendText(mapper.writeValueAsString(subscribe));
                    id++;
                }
                break;
            }
        case NEXT:
            {
                Next next = mapper.readValue(text, Next.class);
                results.add(next.getPayload());
                expectedNumberOfMessages--;
                if (expectedNumberOfMessages <= 0) {
                    sessionLatch.countDown();
                }
                break;
            }
        case PING:
            {
                expectedNumberOfSubscribes--;
                if (expectedNumberOfSubscribes <= 0) {
                    subscribeLatch.countDown();
                }
                break;
            }
        case ERROR:
            {
                Error error = mapper.readValue(text, Error.class);
                log.error("ERROR: {}", error.getPayload());
                sessionLatch.countDown();
                break;
            }
        default:
            {
                break;
            }
    }
}
Also used : Next(com.yahoo.elide.graphql.subscriptions.websocket.protocol.Next) OnError(javax.websocket.OnError) Error(com.yahoo.elide.graphql.subscriptions.websocket.protocol.Error) GraphQLError(graphql.GraphQLError) JsonNode(com.fasterxml.jackson.databind.JsonNode) Subscribe(com.yahoo.elide.graphql.subscriptions.websocket.protocol.Subscribe) MessageType(com.yahoo.elide.graphql.subscriptions.websocket.protocol.MessageType) OnMessage(javax.websocket.OnMessage)

Example 2 with Error

use of com.yahoo.elide.graphql.subscriptions.websocket.protocol.Error in project elide by yahoo.

the class RequestHandler method safeSendError.

protected void safeSendError(GraphQLError[] errors) {
    log.debug("Sending Error {}", errors);
    ObjectMapper mapper = elide.getElideSettings().getMapper().getObjectMapper();
    Error error = Error.builder().id(protocolID).payload(errors).build();
    try {
        sendMessage(mapper.writeValueAsString(error));
    } catch (JsonProcessingException e) {
        log.error("UNEXPECTED Json Serialization Error {}", e.getMessage());
        safeClose();
    }
}
Also used : Error(com.yahoo.elide.graphql.subscriptions.websocket.protocol.Error) GraphQLError(graphql.GraphQLError) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Error (com.yahoo.elide.graphql.subscriptions.websocket.protocol.Error)2 GraphQLError (graphql.GraphQLError)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MessageType (com.yahoo.elide.graphql.subscriptions.websocket.protocol.MessageType)1 Next (com.yahoo.elide.graphql.subscriptions.websocket.protocol.Next)1 Subscribe (com.yahoo.elide.graphql.subscriptions.websocket.protocol.Subscribe)1 OnError (javax.websocket.OnError)1 OnMessage (javax.websocket.OnMessage)1