UNPKG

6.74 kBTypeScriptView Raw
1/// <reference types="node" />
2import { GraphQLError, GraphQLSchema, SourceLocation, DocumentNode } from 'graphql';
3import { IncomingMessage, ServerResponse } from 'http';
4import { PluginHookFn } from './postgraphile/pluginHook';
5import { Pool } from 'pg';
6import { Plugin, PostGraphileCoreOptions } from 'postgraphile-core';
7import jwt = require('jsonwebtoken');
8import { EventEmitter } from 'events';
9import { PostGraphileResponse } from './postgraphile/http/frameworks';
10import { ShutdownActions } from './postgraphile/shutdownActions';
11import { KeyObject } from 'crypto';
12declare type PromiseOrDirect<T> = T | Promise<T>;
13declare type DirectOrCallback<Request, T> = T | ((req: Request) => PromiseOrDirect<T>);
14/**
15 * A narrower type than `any` that wont swallow errors from assumptions about
16 * code.
17 *
18 * For example `(x as any).anything()` is ok. That function then returns `any`
19 * as well so the problem compounds into `(x as any).anything().else()` and the
20 * problem just goes from there. `any` is a type black hole that swallows any
21 * useful type information and shouldnt be used unless you know what youre
22 * doing.
23 *
24 * With `mixed` you must *prove* the type is what you want to use.
25 *
26 * The `mixed` type is identical to the `mixed` type in Flow.
27 *
28 * @see https://github.com/Microsoft/TypeScript/issues/9999
29 * @see https://flowtype.org/docs/builtins.html#mixed
30 */
31export declare type mixed = Record<string, any> | string | number | boolean | undefined | null;
32export declare type Middleware<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse> = (req: Request, res: Response, next: (errOrEscape?: any) => void) => void;
33export interface PostGraphileOptions<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse> extends PostGraphileCoreOptions {
34 watchPg?: boolean;
35 retryOnInitFail?: boolean | ((error: Error, attempts: number) => boolean | Promise<boolean>);
36 ownerConnectionString?: string;
37 subscriptions?: boolean;
38 live?: boolean;
39 websockets?: ('v0' | 'v1')[];
40 websocketOperations?: 'all' | 'subscriptions';
41 websocketMiddlewares?: Array<Middleware<Request, Response>>;
42 pgDefaultRole?: string;
43 dynamicJson?: boolean;
44 setofFunctionsContainNulls?: boolean;
45 classicIds?: boolean;
46 disableDefaultMutations?: boolean;
47 ignoreRBAC?: boolean;
48 ignoreIndexes?: boolean;
49 includeExtensionResources?: boolean;
50 showErrorStack?: boolean | 'json';
51 extendedErrors?: Array<string>;
52 handleErrors?: (errors: ReadonlyArray<GraphQLError>, req: Request, res: Response) => ReadonlyArray<GraphQLError | GraphQLErrorExtended>;
53 appendPlugins?: Array<Plugin>;
54 prependPlugins?: Array<Plugin>;
55 replaceAllPlugins?: Array<Plugin>;
56 skipPlugins?: Array<Plugin>;
57 readCache?: string | Record<string, any>;
58 writeCache?: string;
59 exportJsonSchemaPath?: string;
60 exportGqlSchemaPath?: string;
61 sortExport?: boolean;
62 graphqlRoute?: string;
63 eventStreamRoute?: string;
64 externalGraphqlRoute?: string;
65 externalEventStreamRoute?: string;
66 graphiqlRoute?: string;
67 externalUrlBase?: string;
68 graphiql?: boolean;
69 graphiqlCredentials?: 'include' | 'omit' | 'same-origin';
70 enhanceGraphiql?: boolean;
71 enableCors?: boolean;
72 bodySizeLimit?: string;
73 enableQueryBatching?: boolean;
74 jwtSecret?: Exclude<jwt.Secret, KeyObject>;
75 jwtPublicKey?: jwt.Secret | jwt.GetPublicKeyOrSecret;
76 jwtVerifyOptions?: jwt.VerifyOptions;
77 jwtSignOptions?: jwt.SignOptions;
78 jwtRole?: Array<string>;
79 jwtPgTypeIdentifier?: string;
80 jwtAudiences?: Array<string>;
81 legacyRelations?: 'only' | 'deprecated' | 'omit';
82 legacyJsonUuid?: boolean;
83 disableQueryLog?: boolean;
84 pgSettings?: DirectOrCallback<Request, {
85 [key: string]: mixed;
86 }>;
87 allowExplain?: DirectOrCallback<Request, boolean>;
88 additionalGraphQLContextFromRequest?: (req: Request, res: Response) => Promise<Record<string, any>>;
89 pluginHook?: PluginHookFn;
90 simpleCollections?: 'omit' | 'both' | 'only';
91 queryCacheMaxSize?: number;
92}
93export interface CreateRequestHandlerOptions extends PostGraphileOptions {
94 getGqlSchema: () => Promise<GraphQLSchema>;
95 pgPool: Pool;
96 _emitter: EventEmitter;
97 shutdownActions: ShutdownActions;
98}
99export interface GraphQLFormattedErrorExtended {
100 message: string;
101 locations: ReadonlyArray<SourceLocation> | void;
102 path: ReadonlyArray<string | number> | void;
103 extensions?: {
104 [s: string]: any;
105 };
106}
107export declare type GraphQLErrorExtended = GraphQLError & {
108 extensions: {
109 exception: {
110 hint?: string;
111 detail?: string;
112 code: string;
113 };
114 };
115};
116/**
117 * A request handler for one of many different `http` frameworks.
118 */
119export interface HttpRequestHandler<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse> {
120 (req: Request, res: Response, next?: (error?: mixed) => void): Promise<void>;
121 (ctx: {
122 req: Request;
123 res: Response;
124 }, next: () => void): Promise<void>;
125 formatError: (e: GraphQLError) => GraphQLFormattedErrorExtended;
126 getGraphQLSchema: () => Promise<GraphQLSchema>;
127 pgPool: Pool;
128 withPostGraphileContextFromReqRes: (req: Request, res: Response, moreOptions: any, fn: (ctx: mixed) => any) => Promise<any>;
129 options: CreateRequestHandlerOptions;
130 handleErrors: (errors: ReadonlyArray<GraphQLError>, req: Request, res: Response) => ReadonlyArray<GraphQLError | GraphQLErrorExtended>;
131 graphqlRoute: string;
132 graphqlRouteHandler: (res: PostGraphileResponse) => Promise<void>;
133 graphiqlRoute: string;
134 graphiqlRouteHandler: ((res: PostGraphileResponse) => Promise<void>) | null;
135 faviconRouteHandler: ((res: PostGraphileResponse) => Promise<void>) | null;
136 eventStreamRoute: string;
137 eventStreamRouteHandler: ((res: PostGraphileResponse) => Promise<void>) | null;
138 /** Experimental! */
139 release: () => Promise<void>;
140}
141/**
142 * Options passed to the `withPostGraphileContext` function
143 */
144export interface WithPostGraphileContextOptions {
145 pgPool: Pool;
146 jwtToken?: string;
147 jwtSecret?: Exclude<jwt.Secret, KeyObject>;
148 jwtPublicKey?: jwt.Secret | jwt.GetPublicKeyOrSecret;
149 jwtAudiences?: Array<string>;
150 jwtRole?: Array<string>;
151 jwtVerifyOptions?: jwt.VerifyOptions;
152 pgDefaultRole?: string;
153 pgSettings?: {
154 [key: string]: mixed;
155 };
156 explain?: boolean;
157 queryDocumentAst?: DocumentNode;
158 operationName?: string;
159 pgForceTransaction?: boolean;
160 singleStatement?: boolean;
161 variables?: any;
162}
163export {};