1 |
|
2 | import { GraphQLError, GraphQLSchema, SourceLocation, DocumentNode } from 'graphql';
|
3 | import { IncomingMessage, ServerResponse } from 'http';
|
4 | import { PluginHookFn } from './postgraphile/pluginHook';
|
5 | import { Pool } from 'pg';
|
6 | import { Plugin, PostGraphileCoreOptions } from 'postgraphile-core';
|
7 | import jwt = require('jsonwebtoken');
|
8 | import { EventEmitter } from 'events';
|
9 | import { PostGraphileResponse } from './postgraphile/http/frameworks';
|
10 | import { ShutdownActions } from './postgraphile/shutdownActions';
|
11 | import { KeyObject } from 'crypto';
|
12 | declare type PromiseOrDirect<T> = T | Promise<T>;
|
13 | declare type DirectOrCallback<Request, T> = T | ((req: Request) => PromiseOrDirect<T>);
|
14 | /**
|
15 | * A narrower type than `any` that won’t 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 shouldn’t be used unless you know what you’re
|
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 | */
|
31 | export declare type mixed = Record<string, any> | string | number | boolean | undefined | null;
|
32 | export declare type Middleware<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse> = (req: Request, res: Response, next: (errOrEscape?: any) => void) => void;
|
33 | export 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 | }
|
93 | export interface CreateRequestHandlerOptions extends PostGraphileOptions {
|
94 | getGqlSchema: () => Promise<GraphQLSchema>;
|
95 | pgPool: Pool;
|
96 | _emitter: EventEmitter;
|
97 | shutdownActions: ShutdownActions;
|
98 | }
|
99 | export interface GraphQLFormattedErrorExtended {
|
100 | message: string;
|
101 | locations: ReadonlyArray<SourceLocation> | void;
|
102 | path: ReadonlyArray<string | number> | void;
|
103 | extensions?: {
|
104 | [s: string]: any;
|
105 | };
|
106 | }
|
107 | export declare type GraphQLErrorExtended = GraphQLError & {
|
108 | extensions: {
|
109 | exception: {
|
110 | hint?: string;
|
111 | detail?: string;
|
112 | code: string;
|
113 | };
|
114 | };
|
115 | };
|
116 |
|
117 |
|
118 |
|
119 | export 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 |
|
143 |
|
144 | export 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 | }
|
163 | export {};
|