UNPKG

@cortexql/core

Version:

A RESTful API framework for your apps based on GraphQL type system.

90 lines (89 loc) 4.38 kB
/// <reference types="node" /> import { EventEmitter } from 'events'; import { GraphQLResolveInfo } from 'graphql'; import { IDebugger } from '@cortexql/core'; import { Request } from 'express'; import * as WebSocket from 'ws'; import { OperationMessage, ExecutionParams } from 'subscriptions-transport-ws'; import { GraphQLSchema, DocumentNode, ExecutionResult } from 'graphql'; export interface ContextExecute { (document: DocumentNode, variableValues?: { [key: string]: any; }, operationName?: string): Promise<ExecutionResult>; } export interface ContextSubscribe { (document: DocumentNode, variableValues?: { [key: string]: any; }, operationName?: string): Promise<ExecutionResult | AsyncIterator<ExecutionResult>>; } export interface ContextParams { [key: string]: any; } export declare function createContextId(context: BaseContext): any; export declare function createExecutionContextId(context: BaseContext, info?: GraphQLResolveInfo): any; export declare function createContextNamespace(context: BaseContext, info?: GraphQLResolveInfo, id?: any): string; export declare class BaseContext { params: ContextParams; operationName: string | undefined; operationType: string | undefined; id: any; schema: GraphQLSchema; event: EventEmitter; executionEvent?: EventEmitter; execute: ContextExecute; subscribe: ContextSubscribe; context?: this; completed: boolean; completionError?: Error; completionReason?: string; isExecution: false; destroy(handler: (...args: any[]) => void): EventEmitter; on(event: string, handler: (...args: any[]) => void): EventEmitter; once(event: string, handler: (...args: any[]) => void): EventEmitter; removeListener(event: string, handler: (...args: any[]) => void): EventEmitter; removeAllListeners(event: string): EventEmitter; emit(event: string, ...args: any[]): boolean; constructor(params: ContextParams, operationName?: string | undefined, operationType?: string | undefined, id?: any); debug: IDebugger; execution(info?: GraphQLResolveInfo): Promise<ExecutionContext<this>>; endAll(): void; endAll(error: Error | null | undefined, reason?: string): void; endAll(handler: (error?: Error | null | undefined, reason?: string) => void): Promise<void>; end(): void; end(error: Error | null | undefined, reason?: string): void; end(handler: (error?: Error | null | undefined, reason?: string) => void): Promise<void>; } export declare class BaseExecutionContext<T extends BaseContext> { context: T; info: GraphQLResolveInfo | undefined; executionEvent: EventEmitter; isExecution: boolean; id: any; debug: IDebugger; completed: boolean; completionError?: Error; completionReason?: string; execution(info?: GraphQLResolveInfo | undefined): Promise<ExecutionContext<T>>; constructor(context: T, info?: GraphQLResolveInfo | undefined); destroy(handler: (...args: any[]) => void): EventEmitter; on(event: string, handler: (...args: any[]) => void): EventEmitter; once(event: string, handler: (...args: any[]) => void): EventEmitter; removeListener(event: string, handler: (...args: any[]) => void): EventEmitter; removeAllListeners(event: string): EventEmitter; emit(event: string, ...args: any[]): boolean; end(): void; end(error: Error | null | undefined, reason?: string): void; end(handler: (error?: Error | null | undefined, reason?: string) => void): Promise<void>; } export declare type ExecutionContext<T extends BaseContext> = T & BaseExecutionContext<T>; export declare function createContext(params: ContextParams, operationName?: string, operationType?: string, executionId?: any): Promise<BaseContext>; export declare function createExecutionContext<T extends BaseContext>(context: T, info?: GraphQLResolveInfo): Promise<ExecutionContext<T>>; export declare function getOperationFromQuery(query: string): { operationName: string; operationType: string; } | { operationName: undefined; operationType: undefined; }; export declare function createContextFromExpressRequest(req: Request, params?: ContextParams): Promise<BaseContext>; export declare function createContextFromWebSocketTransport(webSocket: WebSocket, message: OperationMessage, params: ExecutionParams): Promise<BaseContext>;