PrismaP
Prisma14mo ago
2 replies
Arturs

Prisma and Pothos integration using Raw SQL

I have a use case where a “prismaField” implements resolve which is based on Raw SQL because of full-text search usage. Let's say we are searching for users by name through full-text search.

The key problem starts when I use Prisma Pothos.js integration to solve N+1 through relations.

Code example from pothos.js prisma docs

builder.queryType({
  fields: (t) => ({
    me: t.prismaField({
      type: 'User',
      resolve: async (query, root, args, ctx, info) =>
        prisma.user.findUniqueOrThrow({
          ...query,
          where: { id: ctx.userId },
        }),
    }),
  }),
});
 
builder.prismaObject('User', {
  fields: (t) => ({
    id: t.exposeID('id'),
    email: t.exposeString('email'),
    posts: t.relation('posts'),
  }),
});
 
builder.prismaObject('Post', {
  fields: (t) => ({
    id: t.exposeID('id'),
    title: t.exposeString('title'),
    author: t.relation('author'),
  }),
});


Because based on their example, I need to pass down the query object to prisma, so the whole preloading would work out of the box. But how can I do it together with using raw SQL? Is there a util that converts prisma POJO to raw SQL that I could add as a fragment?
Was this page helpful?