Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass context through on keystone.connect() #4656

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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