/
types.ts
125 lines (110 loc) 路 4.06 KB
/
types.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
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
import { GraphQLSchema, DocumentNode } from 'graphql';
import {
SchemaDirectiveVisitor,
IResolvers,
IMocks,
GraphQLParseOptions,
} from 'graphql-tools';
import { ValueOrPromise, GraphQLExecutor } from 'apollo-server-types';
import { ConnectionContext } from 'subscriptions-transport-ws';
// The types for `ws` use `export = WebSocket`, so we'll use the
// matching `import =` to bring in its sole export.
import WebSocket = require('ws');
import { GraphQLExtension } from 'graphql-extensions';
export { GraphQLExtension } from 'graphql-extensions';
import { EngineReportingOptions } from 'apollo-engine-reporting';
import { PlaygroundConfig } from './playground';
export { PlaygroundConfig, PlaygroundRenderPageOptions } from './playground';
import {
GraphQLServerOptions as GraphQLOptions,
PersistedQueryOptions,
} from './graphqlOptions';
import { CacheControlExtensionOptions } from 'apollo-cache-control';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import { GraphQLSchemaModule } from '@apollographql/apollo-tools';
export { GraphQLSchemaModule };
export { KeyValueCache } from 'apollo-server-caching';
export type Context<T = object> = T;
export type ContextFunction<FunctionParams = any, ProducedContext = object> = (
context: FunctionParams,
) => ValueOrPromise<Context<ProducedContext>>;
// A plugin can return an interface that matches `ApolloServerPlugin`, or a
// factory function that returns `ApolloServerPlugin`.
export type PluginDefinition = ApolloServerPlugin | (() => ApolloServerPlugin);
export interface SubscriptionServerOptions {
path: string;
keepAlive?: number;
onConnect?: (
connectionParams: Object,
websocket: WebSocket,
context: ConnectionContext,
) => any;
onDisconnect?: (websocket: WebSocket, context: ConnectionContext) => any;
}
type BaseConfig = Pick<
GraphQLOptions<Context>,
| 'formatError'
| 'debug'
| 'rootValue'
| 'validationRules'
| 'executor'
| 'formatResponse'
| 'fieldResolver'
| 'tracing'
| 'dataSources'
| 'cache'
>;
export type Unsubscriber = () => void;
export type SchemaChangeCallback = (schema: GraphQLSchema) => void;
export type GraphQLServiceConfig = {
schema: GraphQLSchema;
executor: GraphQLExecutor;
};
/**
* This is a restricted view of an engine configuration which only supplies the
* necessary info for accessing things like cloud storage.
*/
export type GraphQLServiceEngineConfig = {
apiKeyHash: string;
graphId: string;
graphVariant?: string;
};
export interface GraphQLService {
load(options: {
engine?: GraphQLServiceEngineConfig;
}): Promise<GraphQLServiceConfig>;
onSchemaChange(callback: SchemaChangeCallback): Unsubscriber;
}
// This configuration is shared between all integrations and should include
// fields that are not specific to a single integration
export interface Config extends BaseConfig {
modules?: GraphQLSchemaModule[];
typeDefs?: DocumentNode | Array<DocumentNode> | string | Array<string>;
parseOptions?: GraphQLParseOptions;
resolvers?: IResolvers | Array<IResolvers>;
schema?: GraphQLSchema;
schemaDirectives?: Record<string, typeof SchemaDirectiveVisitor>;
context?: Context | ContextFunction;
introspection?: boolean;
mocks?: boolean | IMocks;
mockEntireSchema?: boolean;
engine?: boolean | EngineReportingOptions<Context>;
extensions?: Array<() => GraphQLExtension>;
cacheControl?: CacheControlExtensionOptions | boolean;
plugins?: PluginDefinition[];
persistedQueries?: PersistedQueryOptions | false;
subscriptions?: Partial<SubscriptionServerOptions> | string | false;
//https://github.com/jaydenseric/graphql-upload#type-uploadoptions
uploads?: boolean | FileUploadOptions;
playground?: PlaygroundConfig;
gateway?: GraphQLService;
experimental_approximateDocumentStoreMiB?: number;
}
export interface FileUploadOptions {
//Max allowed non-file multipart form field size in bytes; enough for your queries (default: 1 MB).
maxFieldSize?: number;
//Max allowed file size in bytes (default: Infinity).
maxFileSize?: number;
//Max allowed number of files (default: Infinity).
maxFiles?: number;
}