Ben
07/13/2020, 1:20 AMRyan
07/13/2020, 7:55 AMRichard Ward
07/13/2020, 11:42 AMRichard Ward
07/13/2020, 11:42 AMRichard Ward
07/13/2020, 11:43 AMRichard Ward
07/13/2020, 11:45 AMtype 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,
});Richard Ward
07/13/2020, 11:45 AMApiContext is key here..Richard Ward
07/13/2020, 11:46 AMgetUsers: async (parent: any, args: any, ctx: ApiContext, info: any): Promise<User[]> => {
...Ben
07/14/2020, 1:34 AMRichard Ward
07/14/2020, 8:13 AMconst server = new GraphQLServer({
typeDefs,
resolvers,
});
Can you paste the snippet where you are instantiating the graphqlServer?Ben
07/17/2020, 11:27 PMconst { 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!Ben
07/17/2020, 11:57 PMRichard Ward
07/18/2020, 7:57 AMRichard Ward
07/18/2020, 7:57 AMRichard Ward
07/18/2020, 7:58 AM@typedef line int he comments that does it.