Hi all,
I have a question concerning the implementation of resolvers in Prisma. I have a project based on the typescript advanced boilerplate.
Moreover, I have defined a query resolver as such:
story(parent, { id, after }, ctx: Context, info) {
return ctx.db.query.story(
{
where: {
id
}
},
info
);
},
Via the info object, a client can query posts on that story. I want to implement a custom resolver on the posts object using the after parameter to only query posts after the “after” id.
I implemented a resolver as such:
export const Story = {
posts: async (parent, args, ctx: Context, info) => {
console.log("Parent: " + JSON.stringify(parent));
console.log("args: " + JSON.stringify(args));
const { after, id } = args;
if (after) {
return ctx.db.query.posts(
{
where: {
story: {
id
}
},
after: after
},
info
);
}
return ctx.db.query.posts(
{
where: {
story: {
id: id
}
}
},
info
);
}
};
The resolver gets called fine, however, when I print the parent object I see that all the posts have already been fetched by prisma. Is there a way to add a resolver before or instead of the resolver automatically called by prisma? I dont want to fetch all the posts associated with a story automatically.
I would be glad for any examples of a clean resolver architecture, or any tips, I am quite new to graphql. I am also a little unclear as to in which order the resolvers implemented in yoga and the prisma generated resolver functions are being called/ related.
THANKS!