-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
index.ts
236 lines (210 loc) · 7.74 KB
/
index.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import type { Config } from 'apollo-server-express';
import { CorsOptions } from 'cors';
import express from 'express';
import type { GraphQLSchema } from 'graphql';
import type { AssetMode, CreateRequestContext, KeystoneContext } from '..';
import { SessionStrategy } from '../session';
import type { MaybePromise } from '../utils';
import type {
ListSchemaConfig,
ListConfig,
MaybeSessionFunction,
MaybeItemFunction,
IdFieldConfig,
} from './lists';
import type { BaseFields } from './fields';
import type { ListAccessControl, FieldAccessControl } from './access-control';
import type { ListHooks } from './hooks';
export type KeystoneConfig = {
lists: ListSchemaConfig;
db: DatabaseConfig;
ui?: AdminUIConfig;
server?: ServerConfig;
session?: SessionStrategy<any>;
graphql?: GraphQLConfig;
extendGraphqlSchema?: ExtendGraphqlSchema;
files?: FilesConfig;
images?: ImagesConfig;
/** Experimental config options */
experimental?: {
/** Enables nextjs graphql api route mode */
enableNextJsGraphqlApiEndpoint?: boolean;
/** Creates a file at `node_modules/.keystone/api` with a `lists` export */
generateNodeAPI?: boolean;
/** Creates a file at `node_modules/.keystone/next/graphql-api` with `default` and `config` exports that can be re-exported in a Next API route */
generateNextGraphqlAPI?: boolean;
/** Config options for Keystone Cloud */
keystoneCloud?: KeystoneCloudConfig;
/** Adds the internal data structure `experimental.initialisedLists` to the context object.
* This is not a stable API and may contain breaking changes in `patch` level releases.
*/
contextInitialisedLists?: boolean;
};
};
// config.lists
export type { ListSchemaConfig, ListConfig, BaseFields, MaybeSessionFunction, MaybeItemFunction };
// config.db
export type DatabaseConfig = {
url: string;
onConnect?: (args: KeystoneContext) => Promise<void>;
useMigrations?: boolean;
enableLogging?: boolean;
idField?: IdFieldConfig;
provider: 'postgresql' | 'sqlite';
prismaPreviewFeatures?: readonly string[]; // https://www.prisma.io/docs/concepts/components/preview-features
};
// config.ui
export type AdminUIConfig = {
/** Completely disables the Admin UI */
isDisabled?: boolean;
/** Enables certain functionality in the Admin UI that expects the session to be an item */
enableSessionItem?: boolean;
/** A function that can be run to validate that the current session should have access to the Admin UI */
isAccessAllowed?: (context: KeystoneContext) => MaybePromise<boolean>;
/** An array of page routes that can be accessed without passing the isAccessAllowed check */
publicPages?: readonly string[];
/** The basePath for the Admin UI App */
// FIXME: currently unused
// path?: string;
getAdditionalFiles?: readonly ((
config: KeystoneConfig
) => MaybePromise<readonly AdminFileToWrite[]>)[];
pageMiddleware?: (args: {
context: KeystoneContext;
isValidSession: boolean;
}) => MaybePromise<{ kind: 'redirect'; to: string } | void>;
};
export type AdminFileToWrite =
| { mode: 'write'; src: string; outputPath: string }
| { mode: 'copy'; inputPath: string; outputPath: string };
// config.server
type HealthCheckConfig = {
path?: string;
data?: Record<string, any> | (() => Record<string, any>);
};
export type ServerConfig = {
/** Configuration options for the cors middleware. Set to `true` to use core Keystone defaults */
cors?: CorsOptions | true;
/** Port number to start the server on. Defaults to process.env.PORT || 3000 */
port?: number;
/** Maximum upload file size allowed (in bytes) */
maxFileSize?: number;
/** Health check configuration. Set to `true` to add a basic `/_healthcheck` route, or specify the path and data explicitly */
healthCheck?: HealthCheckConfig | true;
/** Hook to extend the Express App that Keystone creates */
extendExpressApp?: (app: express.Express, createContext: CreateRequestContext) => void;
};
// config.graphql
export type GraphQLConfig = {
// The path of the GraphQL API endpoint. Default: '/api/graphql'.
path?: string;
// The CORS configuration to use on the GraphQL API endpoint.
// Default: { origin: 'https://studio.apollographql.com', credentials: true }
cors?: CorsOptions;
queryLimits?: {
maxTotalResults?: number;
};
/**
* - `true` - Add `ApolloServerPluginLandingPageGraphQLPlayground` to the Apollo Server plugins
* - `false` - Add `ApolloServerPluginLandingPageDisabled` to the Apollo Server plugins
* - `'apollo'` - Do not add any plugins to the Apollo config, this will use [Apollo Sandbox](https://www.apollographql.com/docs/apollo-server/testing/build-run-queries/#apollo-sandbox)
* @default process.env.NODE_ENV !== 'production'
*/
playground?: boolean | 'apollo';
/**
* Additional options to pass into the ApolloServer constructor.
* @see https://www.apollographql.com/docs/apollo-server/api/apollo-server/#constructor
*/
apolloConfig?: Config;
/**
* When an error is returned from the GraphQL API, Apollo can include a stacktrace
* indicating where the error occurred. When Keystone is processing mutations, it
* will sometimes captures more than one error at a time, and then group these into
* a single error returned from the GraphQL API. Each of these errors will include
* a stacktrace.
*
* In general both categories of stacktrace are useful for debugging while developing,
* but should not be exposed in production, and this is the default behaviour of Keystone.
*
* You can use the `debug` option to change this behaviour. A use case for this
* would be if you need to send the stacktraces to a log, but do not want to return them
* from the API. In this case you could set `debug: true` and use
* `apolloConfig.formatError` to log the stacktraces and then strip them out before
* returning the error.
*
* ```ts
* graphql: {
* debug: true,
* apolloConfig: {
* formatError: err => {
* console.error(err);
* delete err.extensions?.errors;
* delete err.extensions?.exception?.errors;
* delete err.extensions?.exception?.stacktrace;
* return err;
* },
* },
* }
* ```
*
* @default process.env.NODE_ENV !== 'production'
*/
debug?: boolean;
};
// config.extendGraphqlSchema
export type ExtendGraphqlSchema = (schema: GraphQLSchema) => GraphQLSchema;
// config.files
export type FilesConfig = {
upload: AssetMode;
transformFilename?: (str: string) => string;
local?: {
/**
* The path local files are uploaded to.
* @default 'public/files'
*/
storagePath?: string;
/**
* The base of the URL local files will be served from, outside of keystone.
* @default '/files'
*/
baseUrl?: string;
};
};
// config.images
export type ImagesConfig = {
upload: AssetMode;
local?: {
/**
* The path local images are uploaded to.
* @default 'public/images'
*/
storagePath?: string;
/**
* The base of the URL local images will be served from, outside of keystone.
* @default '/images'
*/
baseUrl?: string;
};
};
// config.experimental.keystoneCloud
export type KeystoneCloudConfig = {
apiKey: string;
imagesDomain: string;
graphqlApiEndpoint: string;
restApiEndpoint: string;
};
// Exports from sibling packages
export type { ListHooks, ListAccessControl, FieldAccessControl };
export type {
FieldCreateItemAccessArgs,
FieldReadItemAccessArgs,
FieldUpdateItemAccessArgs,
IndividualFieldAccessControl,
CreateListItemAccessControl,
UpdateListItemAccessControl,
DeleteListItemAccessControl,
ListOperationAccessControl,
ListFilterAccessControl,
} from './access-control';
export type { CommonFieldConfig } from './fields';
export type { CacheHintArgs, IdFieldConfig } from './lists';