Not sure if this has been addressed yet, but I tho...
# orm-help
b
Not sure if this has been addressed yet, but I thought it would be worth bringing up: VSCode intellisense is not working properly when trying to access “prisma” from the context. For instance, when I type “ctx.” prisma is not an option. I, an intellectual, know that it should be an option so I type it anyway. Once, the full line has been typed out, if you go to the next line and start to type it again, “prisma” will be there. So it seems it can’t find it at first until you type it manually, but once you type it manually then who cares if it shows up later. My guess is this is a VSCode issue, but I wanted to post it here in case anyone else ran into it or knows how to fix it.
r
Hey @Ben 👋 Are you using Nexus?
r
Hi Ben, is prisma on your context and have you typed it correctly?
in your second screenshot, your prisma is only being displayed as you have typed it above and you get the "abc" to the left of it. I've got mine setup correctly and my autocomplete shows the "box shape" which for vscode means it sees it as a property on the object.
I'm using apollo server and have my typing setup as follows:
Copy code
type ApiContext = {
    req: Request,
    res: Response,
    prisma: PrismaClient,
    user: Broker
}

const prisma = new PrismaClient({
    errorFormat: 'minimal',
    log: ['query']
});

const server = new ApolloServer({
    typeDefs,
    resolvers,
    schemaDirectives: {
        auth: AuthDirective,
    },
    engine: {
        apiKey: process.env.ENGINE_API_KEY,
        rewriteError(err: any) {
            console.log("Got ApolloServer Error: ", err);
            return err;
        }
    },
    context: ({ req, res }: { req: any, res: any }): ApiContext => {
        return { prisma, user: req.user, req, res };
    },

    playground: true,
    introspection: true,
    tracing: false,
});
the
ApiContext
is key here..
then in my resolvers I have:
Copy code
getUsers: async (parent: any, args: any, ctx: ApiContext, info: any): Promise<User[]> => {
...
b
Hey thanks for the response. @Ryan I am not using Nexus. Been out of the webdev game for a while so I don’t believe I have even heard of it. On a quick glance, it seems to be a prisma replacement? I’ll look into it. @Richard Ward My implementation looks quite a bit different, though I am passing prisma to my context when I create my server. I’m using graphql-yoga for my server. I have been following the howtographql.com tutorial to refresh myself on graphql/prisma. Just keep running into different issues.
r
Hi @Ben To me it seems that the context isn't typed correctly so it's not picking up that prisma is on the context. If I go by the example on the graphql-yoga github then at some stage you should have something similar to
Copy code
const server = new GraphQLServer({ 
typeDefs, 
resolvers, 
});
Can you paste the snippet where you are instantiating the graphqlServer?
b
Hey @Richard Ward For some reason I never saw the notification that you had responded. Sorry about that. I have been messing with this some more and this is where I am:
Copy code
const { GraphQLServer } = require("graphql-yoga");
const { PrismaClient } = require("@prisma/client");
const Mutation = require("./resolvers/Mutation");
const Query = require("./resolvers/Query");

const prisma = new PrismaClient();

const server = new GraphQLServer({
  typeDefs: "./src/schema.graphql",
  resolvers: {
    Mutation,
    Query,
  },
  context: {
    prisma
  }
});
Can’t seem to figure out where the difference is. Thanks!
You know what… I just did some digging and I found that Yoga isn’t being maintained anymore and the team switched over to Nexus. I’m wondering if some of my dependencies aren’t in sync with Yoga and thats why I’m having issue. I’m going to switch over to Nexus and see if I have better luck. Thanks for taking some time on this for me!
r
@Ben - are you using Typescript? Also, if you're using javascript only then check the link I'm about to paste.. (I just need to find it quick)
I think it's the
@typedef
line int he comments that does it.