Skip to content

Commit

Permalink
Fix context.prisma undefined in onConnect (#5407)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Apr 9, 2021
1 parent 58a7939 commit 76692d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/silly-numbers-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Fixed a bug where `context.prisma` was `undefined` in the `onConnect()` function.
4 changes: 3 additions & 1 deletion packages-next/keystone/src/lib/createKeystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export function createKeystone(config: KeystoneConfig, prismaClient?: any) {
const keystone: BaseKeystone = new Keystone({
adapter,
queryLimits: graphql?.queryLimits,
// We call context.sudo() here to regenerate the `context` object *after* the keystone.connect()
// step. This ensures that context.prisma is correctly set up.
// @ts-ignore The @types/keystonejs__keystone package has the wrong type for KeystoneOptions
onConnect: (keystone, { context } = {}) => config.db.onConnect?.(context),
onConnect: (keystone, { context } = {}) => config.db.onConnect?.(context?.sudo()),
// FIXME: Unsupported options: Need to work which of these we want to support with backwards
// compatibility options.
// defaultAccess
Expand Down

1 comment on commit 76692d2

@vercel
Copy link

@vercel vercel bot commented on 76692d2 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.