src/index.js
/**
 * Construct a GraphQL communication initialization message.
 * @constructor
 * @augments OperationMessageFromClient
 * @param {string} id - Operation identifier
 * @param {string} query - Operation
 * @param {object=} variables - Variables
 * @param {string=} operationName - Operation name
 * @throws {TypeError} Throws a type error if any of the provided arguments are invalid.
 * @returns {StartMessage}
*/
Construct a GraphQL communication initialization message.
Construct a GraphQL communication initialization message .
function StartMessage(id, query, variables, operationName) {
    if (this instanceof StartMessage) {
        if (typeof(id) !== "string" || id === "") {
            throw TypeError("Invalid operation identifier");
        }
        if (typeof(query) !== "string" || query === "") {
            throw TypeError("Invalid query");
        }
        if (variables !== undefined && typeof(variables) !== "object") {
            throw TypeError("Invalid payload");
        }
        if (operationName !== undefined && typeof(operationName) !== "string") {
            throw TypeError("Invalid operation name");
        }
        OperationMessageFromClient.call(this, "start");
        Object.defineProperty(this, "id", {
            enumerable: true,
            configurable: false,
            value: id
        });
        Object.defineProperty(this, "payload", {
            enumerable: true,
            configurable: false,
            value: {
                query: query,
                variables: variables || {},
                operationName: operationName || ""
            }
        });
    } else {
        return new StartMessage(id, query, variables, operationName);
    }
}
function StartMessage ( id , query , variables , operationName ) { if ( this instanceof StartMessage ) { if ( typeof ( id ) !== "string" || id === "" ) { throw TypeError ( "Invalid operation identifier" ) ; } if ( typeof ( query ) !== "string" || query === "" ) { throw TypeError ( "Invalid query" ) ; } if ( variables !== undefined && typeof ( variables ) !== "object" ) { throw TypeError ( "Invalid payload" ) ; } if ( operationName !== undefined && typeof ( operationName ) !== "string" ) { throw TypeError ( "Invalid operation name" ) ; } OperationMessageFromClient . call ( this , "start" ) ; Object . defineProperty ( this , "id" , { enumerable : true , configurable : false , value : id } ) ; Object . defineProperty ( this , "payload" , { enumerable : true , configurable : false , value : { query : query , variables : variables || { } , operationName : operationName || "" } } ) ; } else { return new StartMessage ( id , query , variables , operationName ) ; } }
Construct a GraphQL communication initialization message.
Construct a GraphQL communication initialization message .