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C,GAAG,wBAAwB,IAAI,uBAAY,CAAC,SAAS,CAAC;QAC7F,IAAI;YACA,uBAAY,CAAC,oBAAoB;YACjC,uBAAY,CAAC,SAAS;SACvB,CAAC,OAAO,CAAC,iCAAiC,CAAC,KAAK,CAAC,CAAC,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,sEAAsE;gBACpF,oCAAoC,CAAC,CAAC;SACzC;QAED,IAAI,CAAC,WAAW,CACd,iBAAiB,EACjB,IAAI,EACJ,iCAAiC,EACjC,YAAY,CACb,CAAC;IACJ,CAAC;IACH,yBAAC;AAAD,CAAC,AApYD,IAoYC;AApYY,gDAAkB","sourcesContent":["import * as WebSocket from 'ws';\n\nimport MessageTypes from './message-types';\nimport { GRAPHQL_WS, GRAPHQL_SUBSCRIPTIONS } from './protocol';\nimport isObject from './utils/is-object';\nimport {\n parse,\n ExecutionResult,\n GraphQLSchema,\n DocumentNode,\n validate,\n ValidationContext,\n specifiedRules,\n GraphQLFieldResolver,\n} from 'graphql';\nimport { createEmptyIterable } from './utils/empty-iterable';\nimport { createAsyncIterator, forAwaitEach, isAsyncIterable } from 'iterall';\nimport { isASubscriptionOperation } from './utils/is-subscriptions';\nimport { parseLegacyProtocolMessage } from './legacy/parse-legacy-protocol';\nimport { IncomingMessage } from 'http';\n\nexport type ExecutionIterator = AsyncIterator<ExecutionResult>;\n\nexport interface ExecutionParams<TContext = any> {\n query: string | DocumentNode;\n variables: { [key: string]: any };\n operationName: string;\n context: TContext;\n formatResponse?: Function;\n formatError?: Function;\n callback?: Function;\n schema?: GraphQLSchema;\n}\n\nexport type ConnectionContext = {\n initPromise?: Promise<any>,\n isLegacy: boolean,\n socket: WebSocket,\n request: IncomingMessage,\n operations: {\n [opId: string]: ExecutionIterator,\n },\n};\n\nexport interface OperationMessagePayload {\n [key: string]: any; // this will support for example any options sent in init like the auth token\n query?: string;\n variables?: { [key: string]: any };\n operationName?: string;\n}\n\nexport interface OperationMessage {\n payload?: OperationMessagePayload;\n id?: string;\n type: string;\n}\n\nexport type ExecuteFunction = (schema: GraphQLSchema,\n document: DocumentNode,\n rootValue?: any,\n contextValue?: any,\n variableValues?: { [key: string]: any },\n operationName?: string,\n fieldResolver?: GraphQLFieldResolver<any, any>) =>\n ExecutionResult |\n Promise<ExecutionResult> |\n AsyncIterator<ExecutionResult>;\n\nexport type SubscribeFunction = (schema: GraphQLSchema,\n document: DocumentNode,\n rootValue?: any,\n contextValue?: any,\n variableValues?: { [key: string]: any },\n operationName?: string,\n fieldResolver?: GraphQLFieldResolver<any, any>,\n subscribeFieldResolver?: GraphQLFieldResolver<any, any>) =>\n AsyncIterator<ExecutionResult> |\n Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;\n\nexport interface ServerOptions {\n rootValue?: any;\n schema?: GraphQLSchema;\n execute?: ExecuteFunction;\n subscribe?: SubscribeFunction;\n validationRules?:\n Array<(context: ValidationContext) => any> | ReadonlyArray<any>;\n onOperation?: Function;\n onOperationComplete?: Function;\n onConnect?: Function;\n onDisconnect?: Function;\n keepAlive?: number;\n}\n\nconst isWebSocketServer = (socket: any) => socket.on;\n\nexport class SubscriptionServer {\n private onOperation: Function;\n private onOperationComplete: Function;\n private onConnect: Function;\n private onDisconnect: Function;\n\n private wsServer: WebSocket.Server;\n private execute: ExecuteFunction;\n private subscribe: SubscribeFunction;\n private schema: GraphQLSchema;\n private rootValue: any;\n private keepAlive: number;\n private closeHandler: () => void;\n private specifiedRules:\n Array<(context: ValidationContext) => any> |\n ReadonlyArray<any>;\n\n public static create(options: ServerOptions, socketOptionsOrServer: WebSocket.ServerOptions | WebSocket.Server) {\n return new SubscriptionServer(options, socketOptionsOrServer);\n }\n\n constructor(options: ServerOptions, socketOptionsOrServer: WebSocket.ServerOptions | WebSocket.Server) {\n const {\n onOperation, onOperationComplete, onConnect, onDisconnect, keepAlive,\n } = options;\n\n this.specifiedRules = options.validationRules || specifiedRules;\n this.loadExecutor(options);\n\n this.onOperation = onOperation;\n this.onOperationComplete = onOperationComplete;\n this.onConnect = onConnect;\n this.onDisconnect = onDisconnect;\n this.keepAlive = keepAlive;\n\n if (isWebSocketServer(socketOptionsOrServer)) {\n this.wsServer = <WebSocket.Server>socketOptionsOrServer;\n } else {\n // Init and connect WebSocket server to http\n this.wsServer = new WebSocket.Server(socketOptionsOrServer || {});\n }\n\n const connectionHandler = ((socket: WebSocket, request: IncomingMessage) => {\n // Add `upgradeReq` to the socket object to support old API, without creating a memory leak\n // See: https://github.com/websockets/ws/pull/1099\n (socket as any).upgradeReq = request;\n // NOTE: the old GRAPHQL_SUBSCRIPTIONS protocol support should be removed in the future\n if (socket.protocol === undefined ||\n (socket.protocol.indexOf(GRAPHQL_WS) === -1 && socket.protocol.indexOf(GRAPHQL_SUBSCRIPTIONS) === -1)) {\n // Close the connection with an error code, ws v2 ensures that the\n // connection is cleaned up even when the closing handshake fails.\n // 1002: protocol error\n socket.close(1002);\n\n return;\n }\n\n const connectionContext: ConnectionContext = Object.create(null);\n connectionContext.initPromise = Promise.resolve(true);\n connectionContext.isLegacy = false;\n connectionContext.socket = socket;\n connectionContext.request = request;\n connectionContext.operations = {};\n\n const connectionClosedHandler = (error: any) => {\n if (error) {\n this.sendError(\n connectionContext,\n '',\n { message: error.message ? error.message : error },\n MessageTypes.GQL_CONNECTION_ERROR,\n );\n\n setTimeout(() => {\n // 1011 is an unexpected condition prevented the request from being fulfilled\n connectionContext.socket.close(1011);\n }, 10);\n }\n this.onClose(connectionContext);\n\n if (this.onDisconnect) {\n this.onDisconnect(socket, connectionContext);\n }\n };\n\n socket.on('error', connectionClosedHandler);\n socket.on('close', connectionClosedHandler);\n socket.on('message', this.onMessage(connectionContext));\n });\n\n this.wsServer.on('connection', connectionHandler);\n this.closeHandler = () => {\n this.wsServer.removeListener('connection', connectionHandler);\n this.wsServer.close();\n };\n }\n\n public get server(): WebSocket.Server {\n return this.wsServer;\n }\n\n public close(): void {\n this.closeHandler();\n }\n\n private loadExecutor(options: ServerOptions) {\n const { execute, subscribe, schema, rootValue } = options;\n\n if (!execute) {\n throw new Error('Must provide `execute` for websocket server constructor.');\n }\n\n this.schema = schema;\n this.rootValue = rootValue;\n this.execute = execute;\n this.subscribe = subscribe;\n }\n\n private unsubscribe(connectionContext: ConnectionContext, opId: string) {\n if (connectionContext.operations && connectionContext.operations[opId]) {\n if (connectionContext.operations[opId].return) {\n connectionContext.operations[opId].return();\n }\n\n delete connectionContext.operations[opId];\n\n if (this.onOperationComplete) {\n this.onOperationComplete(connectionContext.socket, opId);\n }\n }\n }\n\n private onClose(connectionContext: ConnectionContext) {\n Object.keys(connectionContext.operations).forEach((opId) => {\n this.unsubscribe(connectionContext, opId);\n });\n }\n\n private onMessage(connectionContext: ConnectionContext) {\n return (message: any) => {\n let parsedMessage: OperationMessage;\n try {\n parsedMessage = parseLegacyProtocolMessage(connectionContext, JSON.parse(message));\n } catch (e) {\n this.sendError(connectionContext, null, { message: e.message }, MessageTypes.GQL_CONNECTION_ERROR);\n return;\n }\n\n const opId = parsedMessage.id;\n switch (parsedMessage.type) {\n case MessageTypes.GQL_CONNECTION_INIT:\n if (this.onConnect) {\n connectionContext.initPromise = new Promise((resolve, reject) => {\n try {\n // TODO - this should become a function call with just 2 arguments in the future\n // when we release the breaking change api: parsedMessage.payload and connectionContext\n resolve(this.onConnect(parsedMessage.payload, connectionContext.socket, connectionContext));\n } catch (e) {\n reject(e);\n }\n });\n }\n\n connectionContext.initPromise.then((result) => {\n if (result === false) {\n throw new Error('Prohibited connection!');\n }\n\n this.sendMessage(\n connectionContext,\n undefined,\n MessageTypes.GQL_CONNECTION_ACK,\n undefined,\n );\n\n if (this.keepAlive) {\n this.sendKeepAlive(connectionContext);\n // Regular keep alive messages if keepAlive is set\n const keepAliveTimer = setInterval(() => {\n if (connectionContext.socket.readyState === WebSocket.OPEN) {\n this.sendKeepAlive(connectionContext);\n } else {\n clearInterval(keepAliveTimer);\n }\n }, this.keepAlive);\n }\n }).catch((error: Error) => {\n this.sendError(\n connectionContext,\n opId,\n { message: error.message },\n MessageTypes.GQL_CONNECTION_ERROR,\n );\n\n // Close the connection with an error code, ws v2 ensures that the\n // connection is cleaned up even when the closing handshake fails.\n // 1011: an unexpected condition prevented the operation from being fulfilled\n // We are using setTimeout because we want the message to be flushed before\n // disconnecting the client\n setTimeout(() => {\n connectionContext.socket.close(1011);\n }, 10);\n });\n break;\n\n case MessageTypes.GQL_CONNECTION_TERMINATE:\n connectionContext.socket.close();\n break;\n\n case MessageTypes.GQL_START:\n connectionContext.initPromise.then((initResult) => {\n // if we already have a subscription with this id, unsubscribe from it first\n if (connectionContext.operations && connectionContext.operations[opId]) {\n this.unsubscribe(connectionContext, opId);\n }\n\n const baseParams: ExecutionParams = {\n query: parsedMessage.payload.query,\n variables: parsedMessage.payload.variables,\n operationName: parsedMessage.payload.operationName,\n context: isObject(initResult) ? Object.assign(Object.create(Object.getPrototypeOf(initResult)), initResult) : {},\n formatResponse: <any>undefined,\n formatError: <any>undefined,\n callback: <any>undefined,\n schema: this.schema,\n };\n let promisedParams = Promise.resolve(baseParams);\n\n // set an initial mock subscription to only registering opId\n connectionContext.operations[opId] = createEmptyIterable();\n\n if (this.onOperation) {\n let messageForCallback: any = parsedMessage;\n promisedParams = Promise.resolve(this.onOperation(messageForCallback, baseParams, connectionContext.socket));\n }\n\n return promisedParams.then((params) => {\n if (typeof params !== 'object') {\n const error = `Invalid params returned from onOperation! return values must be an object!`;\n this.sendError(connectionContext, opId, { message: error });\n\n throw new Error(error);\n }\n\n if (!params.schema) {\n const error = 'Missing schema information. The GraphQL schema should be provided either statically in' +\n ' the `SubscriptionServer` constructor or as a property on the object returned from onOperation!';\n this.sendError(connectionContext, opId, { message: error });\n\n throw new Error(error);\n }\n\n const document = typeof baseParams.query !== 'string' ? baseParams.query : parse(baseParams.query);\n let executionPromise: Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;\n const validationErrors = validate(params.schema, document, this.specifiedRules);\n\n if ( validationErrors.length > 0 ) {\n executionPromise = Promise.resolve({ errors: validationErrors });\n } else {\n let executor: SubscribeFunction | ExecuteFunction = this.execute;\n if (this.subscribe && isASubscriptionOperation(document, params.operationName)) {\n executor = this.subscribe;\n }\n executionPromise = Promise.resolve(executor(params.schema,\n document,\n this.rootValue,\n params.context,\n params.variables,\n params.operationName));\n }\n\n return executionPromise.then((executionResult) => ({\n executionIterable: isAsyncIterable(executionResult) ?\n executionResult : createAsyncIterator([ executionResult ]),\n params,\n }));\n }).then(({ executionIterable, params }) => {\n forAwaitEach(\n executionIterable as any,\n (value: ExecutionResult) => {\n let result = value;\n\n if (params.formatResponse) {\n try {\n result = params.formatResponse(value, params);\n } catch (err) {\n console.error('Error in formatResponse function:', err);\n }\n }\n\n this.sendMessage(connectionContext, opId, MessageTypes.GQL_DATA, result);\n })\n .then(() => {\n this.sendMessage(connectionContext, opId, MessageTypes.GQL_COMPLETE, null);\n })\n .catch((e: Error) => {\n let error = e;\n\n if (params.formatError) {\n try {\n error = params.formatError(e, params);\n } catch (err) {\n console.error('Error in formatError function: ', err);\n }\n }\n\n // plain Error object cannot be JSON stringified.\n if (Object.keys(error).length === 0) {\n error = { name: error.name, message: error.message };\n }\n\n this.sendError(connectionContext, opId, error);\n });\n\n return executionIterable;\n }).then((subscription: ExecutionIterator) => {\n connectionContext.operations[opId] = subscription;\n }).then(() => {\n // NOTE: This is a temporary code to support the legacy protocol.\n // As soon as the old protocol has been removed, this coode should also be removed.\n this.sendMessage(connectionContext, opId, MessageTypes.SUBSCRIPTION_SUCCESS, undefined);\n }).catch((e: any) => {\n if (e.errors) {\n this.sendMessage(connectionContext, opId, MessageTypes.GQL_DATA, { errors: e.errors });\n } else {\n this.sendError(connectionContext, opId, { message: e.message });\n }\n\n // Remove the operation on the server side as it will be removed also in the client\n this.unsubscribe(connectionContext, opId);\n return;\n });\n }).catch((error) => {\n // Handle initPromise rejected\n this.sendError(connectionContext, opId, { message: error.message });\n this.unsubscribe(connectionContext, opId);\n });\n break;\n\n case MessageTypes.GQL_STOP:\n // Find subscription id. Call unsubscribe.\n this.unsubscribe(connectionContext, opId);\n break;\n\n default:\n this.sendError(connectionContext, opId, { message: 'Invalid message type!' });\n }\n };\n }\n\n private sendKeepAlive(connectionContext: ConnectionContext): void {\n if (connectionContext.isLegacy) {\n this.sendMessage(connectionContext, undefined, MessageTypes.KEEP_ALIVE, undefined);\n } else {\n this.sendMessage(connectionContext, undefined, MessageTypes.GQL_CONNECTION_KEEP_ALIVE, undefined);\n }\n }\n\n private sendMessage(connectionContext: ConnectionContext, opId: string, type: string, payload: any): void {\n const parsedMessage = parseLegacyProtocolMessage(connectionContext, {\n type,\n id: opId,\n payload,\n });\n\n if (parsedMessage && connectionContext.socket.readyState === WebSocket.OPEN) {\n connectionContext.socket.send(JSON.stringify(parsedMessage));\n }\n }\n\n private sendError(connectionContext: ConnectionContext, opId: string, errorPayload: any,\n overrideDefaultErrorType?: string): void {\n const sanitizedOverrideDefaultErrorType = overrideDefaultErrorType || MessageTypes.GQL_ERROR;\n if ([\n MessageTypes.GQL_CONNECTION_ERROR,\n MessageTypes.GQL_ERROR,\n ].indexOf(sanitizedOverrideDefaultErrorType) === -1) {\n throw new Error('overrideDefaultErrorType should be one of the allowed error messages' +\n ' GQL_CONNECTION_ERROR or GQL_ERROR');\n }\n\n this.sendMessage(\n connectionContext,\n opId,\n sanitizedOverrideDefaultErrorType,\n errorPayload,\n );\n }\n}\n\n"]}