This repository was archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathindex.d.ts
More file actions
196 lines (168 loc) · 5.41 KB
/
index.d.ts
File metadata and controls
196 lines (168 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// TypeScript Version: 3.0
import { IncomingMessage, ServerResponse } from 'http';
import {
Source,
ASTVisitor,
DocumentNode,
ValidationContext,
ExecutionArgs,
ExecutionResult,
GraphQLError,
GraphQLSchema,
GraphQLFieldResolver,
GraphQLTypeResolver,
} from 'graphql';
// TODO: Temporary until we update TS typings for 'graphql' package
import { ValidationRule } from 'graphql/validation/ValidationContext';
export = graphqlHTTP;
type Request = IncomingMessage;
type Response = ServerResponse;
declare namespace graphqlHTTP {
/**
* Used to configure the graphqlHTTP middleware by providing a schema
* and other configuration options.
*
* Options can be provided as an Object, a Promise for an Object, or a Function
* that returns an Object or a Promise for an Object.
*/
type Options =
| ((
request: Request,
response: Response,
params?: GraphQLParams,
) => OptionsResult)
| OptionsResult;
type OptionsResult = OptionsData | Promise<OptionsData>;
interface OptionsData {
/**
* A GraphQL schema from graphql-js.
*/
schema: GraphQLSchema;
/**
* A value to pass as the context to the graphql() function.
*/
context?: unknown;
/**
* An object to pass as the rootValue to the graphql() function.
*/
rootValue?: unknown;
/**
* A boolean to configure whether the output should be pretty-printed.
*/
pretty?: boolean | null;
/**
* An optional array of validation rules that will be applied on the document
* in additional to those defined by the GraphQL spec.
*/
validationRules?: ReadonlyArray<
(ctx: ValidationContext) => ASTVisitor
> | null;
/**
* An optional function which will be used to validate instead of default `validate`
* from `graphql-js`.
*/
customValidateFn?:
| ((
schema: GraphQLSchema,
documentAST: DocumentNode,
rules: ReadonlyArray<ValidationRule>,
) => ReadonlyArray<GraphQLError>)
| null;
/**
* An optional function which will be used to execute instead of default `execute`
* from `graphql-js`.
*/
customExecuteFn?:
| ((args: ExecutionArgs) => Promise<ExecutionResult>)
| null;
/**
* An optional function which will be used to format any errors produced by
* fulfilling a GraphQL operation. If no function is provided, GraphQL's
* default spec-compliant `formatError` function will be used.
*/
customFormatErrorFn?: ((error: GraphQLError) => unknown) | null;
/**
* An optional function which will be used to create a document instead of
* the default `parse` from `graphql-js`.
*/
customParseFn?: (source: Source) => DocumentNode | null;
/**
* `formatError` is deprecated and replaced by `customFormatErrorFn`. It will
* be removed in version 1.0.0.
*/
formatError?: ((error: GraphQLError) => unknown) | null;
/**
* An optional function for adding additional metadata to the GraphQL response
* as a key-value object. The result will be added to "extensions" field in
* the resulting JSON. This is often a useful place to add development time
* info such as the runtime of a query or the amount of resources consumed.
*
* Information about the request is provided to be used.
*
* This function may be async.
*/
extensions?: ((info: RequestInfo) => { [key: string]: unknown }) | null;
/**
* A boolean to optionally enable GraphiQL mode.
*/
graphiql?: boolean | null;
/**
* A resolver function to use when one is not provided by the schema.
* If not provided, the default field resolver is used (which looks for a
* value or method on the source value with the field's name).
*/
fieldResolver?: GraphQLFieldResolver<unknown, unknown> | null;
/**
* A type resolver function to use when none is provided by the schema.
* If not provided, the default type resolver is used (which looks for a
* `__typename` field or alternatively calls the `isTypeOf` method).
*/
typeResolver?: GraphQLTypeResolver<unknown, unknown> | null;
/**
* A optional string which will used to predefined fragments
*/
serverFragments?: string;
}
/**
* All information about a GraphQL request.
*/
interface RequestInfo {
/**
* The parsed GraphQL document.
*/
document: DocumentNode | null | undefined;
/**
* The variable values used at runtime.
*/
variables: { readonly [name: string]: unknown } | null | undefined;
/**
* The (optional) operation name requested.
*/
operationName: string | null | undefined;
/**
* The result of executing the operation.
*/
result: unknown;
/**
* A value to pass as the context to the graphql() function.
*/
context?: unknown;
}
type Middleware = (
request: Request,
response: Response,
) => Promise<undefined>;
interface GraphQLParams {
query: string | null | undefined;
variables: { readonly [name: string]: unknown } | null | undefined;
operationName: string | null | undefined;
raw: boolean | null | undefined;
}
}
/**
* Middleware for express; takes an options object or function as input to
* configure behavior, and returns an express middleware.
*/
declare function graphqlHTTP(
options: graphqlHTTP.Options,
): graphqlHTTP.Middleware;