I want to know if is better or there is any difference in use prisma client directly in resolvers or pass it through context.
In the official documentation it is passed through context:
const { prisma } = require('./generated/prisma-client');
const resolvers = {
Query: {
feed: (parent, args, context) => {
return context.prisma.posts({ where: { published: true } })
}
}
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: {
prisma,
},
})
My question is: why prisma client is not used directly in resolvers.
const { prisma } = require('./generated/prisma-client');
const resolvers = {
Query: {
feed: (parent, args, context) => {
return prisma.posts({ where: { published: true } })
}
}
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
})
Is there anything wrong in this solution?