From 0deb9a6e51566c54234efedc5adb14dec7a92ca3 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Thu, 14 Jan 2021 08:39:14 +1100 Subject: [PATCH] Pass context through on keystone.connect() --- .changeset/nervous-feet-juggle.md | 5 +++++ packages-next/keystone/src/lib/createSystem.ts | 11 +++-------- packages-next/keystone/src/scripts/dev.ts | 2 +- packages-next/keystone/src/scripts/start.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 .changeset/nervous-feet-juggle.md diff --git a/.changeset/nervous-feet-juggle.md b/.changeset/nervous-feet-juggle.md new file mode 100644 index 00000000000..42872a37ee6 --- /dev/null +++ b/.changeset/nervous-feet-juggle.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/keystone': patch +--- + +Updated calls to `keystone.connect()` with a `{ context }` argument to be used by `config.db.onConnect`. diff --git a/packages-next/keystone/src/lib/createSystem.ts b/packages-next/keystone/src/lib/createSystem.ts index 324d6ea6bc8..35413c4d36a 100644 --- a/packages-next/keystone/src/lib/createSystem.ts +++ b/packages-next/keystone/src/lib/createSystem.ts @@ -8,10 +8,7 @@ import type { KeystoneConfig, KeystoneSystem, BaseKeystone } from '@keystone-nex import { createGraphQLSchema } from './createGraphQLSchema'; import { makeCreateContext } from './createContext'; -export function createKeystone( - config: KeystoneConfig, - createContextFactory: () => ReturnType -) { +export function createKeystone(config: KeystoneConfig) { // Note: For backwards compatibility we may want to expose // this as a public API so that users can start their transition process // by using this pattern for creating their Keystone object before using @@ -34,9 +31,7 @@ export function createKeystone( cookieSecret: '123456789', // FIXME: Don't provide a default here. See #2882 queryLimits: graphql?.queryLimits, // @ts-ignore The @types/keystonejs__keystone package has the wrong type for KeystoneOptions - onConnect: () => { - return config.db.onConnect?.(createContextFactory()({ skipAccessControl: true })); - }, + onConnect: (keystone, { context } = {}) => config.db.onConnect?.(context), // FIXME: Unsupported options: Need to work which of these we want to support with backwards // compatibility options. // defaultAccess @@ -79,7 +74,7 @@ export function createKeystone( } export function createSystem(config: KeystoneConfig): KeystoneSystem { - const keystone = createKeystone(config, () => createContext); + const keystone = createKeystone(config); const graphQLSchema = createGraphQLSchema(config, keystone); diff --git a/packages-next/keystone/src/scripts/dev.ts b/packages-next/keystone/src/scripts/dev.ts index aac09707776..174b7248fc7 100644 --- a/packages-next/keystone/src/scripts/dev.ts +++ b/packages-next/keystone/src/scripts/dev.ts @@ -48,7 +48,7 @@ export const dev = async () => { ); console.log('✨ Connecting to the Database'); - await system.keystone.connect(); + await system.keystone.connect({ context: system.createContext({ skipAccessControl: true }) }); console.log('✨ Generating Admin UI'); await generateAdminUI(config, system); diff --git a/packages-next/keystone/src/scripts/start.ts b/packages-next/keystone/src/scripts/start.ts index 1ebaa0e4696..40c41b0ae22 100644 --- a/packages-next/keystone/src/scripts/start.ts +++ b/packages-next/keystone/src/scripts/start.ts @@ -16,7 +16,7 @@ export const start = async () => { const system = createSystem(config); console.log('✨ Connecting to the Database'); - await system.keystone.connect(); + await system.keystone.connect({ context: system.createContext({ skipAccessControl: true }) }); const server = await createExpressServer(config, system, false); console.log(`👋 Admin UI Ready`);