-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix: jest exits after tests run #13
fix: jest exits after tests run #13
Conversation
|
||
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.
Is there a reason we're passing a function as the context instead of just passing a regular Object?
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.
Because a function is what Apollo Server expects. It is called on every request. Usually work is done here to expose request scoped details to resolvers, like current user.
This needs to be explained better in the tutorial.
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.
Usually work is done here to expose request scoped details to resolvers, like current user.
Yup, I've actually done that in an app I'm building.
Because a function is what Apollo Server expects.
Apollo Server actually expects either a function or a plain javascript object. It's not really a big deal, but I thought it might've been simpler just passing a context
object in this case.
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.
Good to know, in the spirit of the tutorial that incrementally builds up on an as-needed basis I would happily accept a PR to make this change!
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.
Done!
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.
ty!
db.ts
in the API Contexta9ca189
using a workaround by passing the
--forceExit
flag to Jest.This PR adds a proper fix for graphql-nexus/nexus#678.