src/index.js
/**
 * Derive a server-side GraphQL operation message from an object.
 * @param {object} message - Message received from server
 * @throws {TypeError} Throws a type error if the provided message is of an unknown type.
 * @returns {ConnectionErrorMessage|ConnectionAckMessage|DataMessage|ErrorMessage|CompleteMessage} GraphQL operation message
 */
Derive a server-side GraphQL operation message from an object.
@param {object} message - Message received from server
@throws {TypeError} Throws a type error if the provided message is of an unknown type.
Derive a server - side GraphQL operation message from an object . @param { object } message - Message received from server @throws { TypeError } Throws a type error if the provided message is of an unknown type .
function receive(message) {
    switch (message.type) {
    case "connection_error":
        return new ConnectionErrorMessage(message.payload);
    case "connection_ack":
        return new ConnectionAckMessage();
    case "data":
        return new DataMessage(message.id, message.payload);
    case "error":
        return new ErrorMessage(message.id, message.payload);
    case "complete":
        return new CompleteMessage(message.id);
    default:
        throw TypeError(
            "Received message of unknown type\n" + JSON.stringify(message, null, 2)
        );
    }
}
function receive ( message ) { switch ( message . type ) { case "connection_error" : return new ConnectionErrorMessage ( message . payload ) ; case "connection_ack" : return new ConnectionAckMessage ( ) ; case "data" : return new DataMessage ( message . id , message . payload ) ; case "error" : return new ErrorMessage ( message . id , message . payload ) ; case "complete" : return new CompleteMessage ( message . id ) ; default : throw TypeError ( "Received message of unknown type\n" + JSON . stringify ( message , null , 2 ) ) ; } }
Derive a server-side GraphQL operation message from an object.
Derive a server - side GraphQL operation message from an object .