-
Notifications
You must be signed in to change notification settings - Fork 276
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
chore(docs): update tutorial testing chapter #709
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #709 +/- ##
===========================================
- Coverage 93.62% 93.62% -0.01%
===========================================
Files 44 46 +2
Lines 2887 2900 +13
Branches 678 679 +1
===========================================
+ Hits 2703 2715 +12
- Misses 182 183 +1
Partials 2 2 |
|
||
export interface Context { | ||
db: PrismaClient | ||
} | ||
|
||
export function createContext(): Context { | ||
return { | ||
db: new PrismaClient(), | ||
db, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this to match https://github.com/graphql-nexus/tutorial/blob/master/api/context.ts
I don't think we need a db modular just to instantiate a Prisma client :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need db to modular, but we do need to store the instance of the Prisma Client in either an object or variable which is exported so that it can be accessed in tests/__helpers.ts
. The same Prisma Client used in the context of Nexus should be accessible in __helpers.ts
as a new connection is created for every instance of Prisma Client.
There are two options, one is keep it as I've updated it.
Another is, to export an object from 'context.ts' and disconnect the connection of that
export const context: Context = {
db: new PrismaClient()
}
and in __helpers.ts
import { context } from '../api/context.ts'
...
function graphqlTestContext() {
...
return {
async before() {
...
serverInstance.server.on('close', async () => {
await context.db.$disconnect()
})
},
...
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep good point. then a singleton db module is a simple solution indeed. If you're inclined update the tutorial repo otherwise we'll try to do it soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already done graphql-nexus/tutorial#13 🙂 !
Awesome! Just one thing |
db.ts
in the API Contexta9ca189
using a workaround by passing the--forceExit
flag to Jest.This PR adds a proper fix for #678