| 201 | } |
| 202 | |
| 203 | export function createSystem (config_: KeystoneConfig) { |
| 204 | const config = resolveDefaults(config_) |
| 205 | const lists = initialiseLists(config) |
| 206 | const adminMeta = createAdminMeta(config, lists) |
| 207 | const graphQLSchema = createGraphQLSchema(config, lists, adminMeta, false) |
| 208 | const graphQLSchemaSudo = getSudoGraphQLSchema(config) |
| 209 | |
| 210 | return { |
| 211 | config, |
| 212 | graphQLSchema, |
| 213 | graphQLSchemaSudo, |
| 214 | adminMeta, |
| 215 | lists, |
| 216 | |
| 217 | getPaths: (cwd: string) => { |
| 218 | return getSystemPaths(cwd, config) |
| 219 | }, |
| 220 | |
| 221 | getKeystone: (PM: any) => { |
| 222 | const prePrismaClient = new PM.PrismaClient({ |
| 223 | datasourceUrl: formatUrl(config.db.provider, config.db.url), |
| 224 | log: config.db.enableLogging |
| 225 | }) |
| 226 | |
| 227 | const prismaClient = config.db.extendPrismaClient(injectNewDefaults(prePrismaClient, lists)) |
| 228 | const context = createContext({ |
| 229 | config, |
| 230 | lists, |
| 231 | graphQLSchema, |
| 232 | graphQLSchemaSudo, |
| 233 | prismaClient, |
| 234 | prismaTypes: { |
| 235 | DbNull: PM.Prisma.DbNull, |
| 236 | JsonNull: PM.Prisma.JsonNull, |
| 237 | }, |
| 238 | }) |
| 239 | |
| 240 | return { |
| 241 | // TODO: replace with server.onStart, remove in breaking change |
| 242 | async connect () { |
| 243 | await (prismaClient as any).$connect() |
| 244 | await config.db.onConnect?.(context) |
| 245 | }, |
| 246 | // TODO: only used by tests, remove in breaking change |
| 247 | async disconnect () { |
| 248 | await (prismaClient as any).$disconnect() |
| 249 | }, |
| 250 | context, |
| 251 | } |
| 252 | }, |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | export type System = ReturnType<typeof createSystem> |