I feel like the docs should tell you to create a i...
# orm-help
m
I feel like the docs should tell you to create a index.ts file in your prima folder that exports the primsa client and then tells tsconfig to alias
prisma
to that folder
r
can't you just do
import { PrismaClient } from "@prisma/client";
? (I'm using prisma2 but prisma1 was similar)
r
Hey @Manthan Mallikarjun 👋 That isn’t required, you can import
@prisma/client
from anywhere as mentioned above by Richard.
m
Oh really?
I didnt know that!
What if I want to configure logging or something
Wait to clarify
Copy code
const prisma = new PrismaClient({});
You need to use this instance of prisma throughout your app right?
r
Yes. Just a single instance across the entire app. To log queries, you can use:
Copy code
const prisma = new PrismaClient({
  log: ['query'],
})
r
@Manthan Mallikarjun - in my
server.ts
I have something along the lines of the following:
Copy code
const prisma = new PrismaClient({
    errorFormat: 'minimal',
    log: ['query']
});

const server = new ApolloServer({
    typeDefs,
    resolvers,
    context: ({ req, res }: { req: any, res: any }): ApiContext => {
        return { prisma, user: req.user, req, res };
    },
});
That creates a single prisma instance and puts it into the contact that get's passed to my endpoints. (I'm using graphql). In a REST api you an put it on the
req
object and then have access to it in your endpoint.
m
@Ryan right so to share that single instance you can map it to an alias in typescript so instead of
import Prisma from "../../../../prisma"
you can do
import prisma from 'prisma'
Ah the Apollo trick is pretty cool!
I might start doing that but I also need to access it inside of jobs and stuff