Skip to content

Commit

Permalink
Pass context through on keystone.connect()
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Jan 14, 2021
1 parent b762416 commit 0deb9a6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-feet-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Updated calls to `keystone.connect()` with a `{ context }` argument to be used by `config.db.onConnect`.
11 changes: 3 additions & 8 deletions packages-next/keystone/src/lib/createSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof makeCreateContext>
) {
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
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages-next/keystone/src/scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages-next/keystone/src/scripts/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down

0 comments on commit 0deb9a6

Please sign in to comment.