Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Unable to find Prisma Client in GraphQL context. Please provide it under the context[\"prisma\"] key. #810

Closed
bmccorm2 opened this issue Aug 26, 2022 · 1 comment

Comments

@bmccorm2
Copy link

bmccorm2 commented Aug 26, 2022

Hi - I'm using some various packages to try and get a graphql server up and running: type-graphql to generate my schema, and prisma to connect to my database. Everything is working fine but it seems express doesn't have access to the prisma client. Do you know what i am doing wrong?

Error: Unable to find Prisma Client in GraphQL context. Please provide it under the context[\"prisma\"] key

import express from "express";
import "reflect-metadata";
import { PrismaClient } from "@prisma/client";
import { resolvers } from "@generated/type-graphql";
import { buildSchema } from "type-graphql";
import { graphqlHTTP } from "express-graphql";

(async () => {
	const prisma = new PrismaClient();
	const schema = await buildSchema({
		resolvers,
		validate: false,
	});

	const app = express();
	app.use(
		"/graphql",
		graphqlHTTP({
			schema,
			context: () => ({ prisma }),
			graphiql: true,
		})
	);

	app.listen(3000, () => {
		console.log(`Example app listening on port 3000`);
	});
})();
@bmccorm2
Copy link
Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant