Unable to find Prisma Client in GraphQL context. Please provide it under the context.prisma
key.
#111
-
Hello, After Prisma confirmed that RDS Proxy would be useless because of pinning, this means that we can't deploy live. So a Prisma member suggested that we create a client when a request comes and disconnect once it's done. So that's basically what I want to do. I defined a parameter decorator to generate a PrismaInstance:
And in each resolver I do this:
So I have two questions: 1- Is there a better way to achieve the above? 2- Since I'm defining cusotm resolvers that rely on the generated resolvers, how can I fix the error coming from this line
The problem is that I don't add the prisma client on the apollo server anymore since I switched to using the parameter decorator above.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Parameter decorator is not a right solution. It will connect and disconnect for every field resolver, meaning prisma batching won't work. And will be slow as turle 😅 Instead you should initialize prisma client in the However you may need to dig in into Apollo Server docs to find a way to use hooks and plugins in order to disconnect from prisma, as TypeGraphQL is not responsible for the whole GraphQL execution pipeline, it only creates resolver handlers for GraphQL Schema. |
Beta Was this translation helpful? Give feedback.
Parameter decorator is not a right solution. It will connect and disconnect for every field resolver, meaning prisma batching won't work. And will be slow as turle 😅
Instead you should initialize prisma client in the
context
helper, so single graphql request which is handled by separate lambda will use single Prisma Client instance.However you may need to dig in into Apollo Server docs to find a way to use hooks and plugins in order to disconnect from prisma, as TypeGraphQL is not responsible for the whole GraphQL execution pipeline, it only creates resolver handlers for GraphQL Schema.