-
Notifications
You must be signed in to change notification settings - Fork 2k
/
graphqlOptions.ts
76 lines (71 loc) 路 2.49 KB
/
graphqlOptions.ts
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
import {
GraphQLSchema,
ValidationContext,
GraphQLFieldResolver,
DocumentNode,
} from 'graphql';
import { GraphQLExtension } from 'graphql-extensions';
import { CacheControlExtensionOptions } from 'apollo-cache-control';
import { KeyValueCache } from 'apollo-server-caching';
import { DataSource } from 'apollo-datasource';
/*
* GraphQLServerOptions
*
* - schema: an executable GraphQL schema used to fulfill requests.
* - (optional) formatError: Formatting function applied to all errors before response is sent
* - (optional) rootValue: rootValue passed to GraphQL execution, or a function to resolving the rootValue from the DocumentNode
* - (optional) context: the context passed to GraphQL execution
* - (optional) validationRules: extra validation rules applied to requests
* - (optional) formatResponse: a function applied to each graphQL execution result
* - (optional) fieldResolver: a custom default field resolver
* - (optional) debug: a boolean that will print additional debug logging if execution errors occur
* - (optional) extensions: an array of functions which create GraphQLExtensions (each GraphQLExtension object is used for one request)
*
*/
export interface GraphQLServerOptions<
TContext =
| (() => Promise<Record<string, any>> | Record<string, any>)
| Record<string, any>,
TRootVal = ((parsedQuery: DocumentNode) => any) | any
> {
schema: GraphQLSchema;
formatError?: Function;
rootValue?: TRootVal;
context?: TContext;
validationRules?: Array<(context: ValidationContext) => any>;
formatResponse?: Function;
fieldResolver?: GraphQLFieldResolver<any, TContext>;
debug?: boolean;
tracing?: boolean;
cacheControl?:
| boolean
| (CacheControlExtensionOptions & {
calculateHttpHeaders?: boolean;
stripFormattedExtensions?: boolean;
});
extensions?: Array<() => GraphQLExtension>;
dataSources?: () => DataSources<TContext>;
cache?: KeyValueCache;
persistedQueries?: PersistedQueryOptions;
}
export type DataSources<TContext> = {
[name: string]: DataSource<TContext>;
};
export interface PersistedQueryOptions {
cache: KeyValueCache;
}
export default GraphQLServerOptions;
export async function resolveGraphqlOptions(
options:
| GraphQLServerOptions
| ((
...args: Array<any>
) => Promise<GraphQLServerOptions> | GraphQLServerOptions),
...args: Array<any>
): Promise<GraphQLServerOptions> {
if (typeof options === 'function') {
return await options(...args);
} else {
return options;
}
}