pothos icon indicating copy to clipboard operation
pothos copied to clipboard

[Feature request]: Allow async query fields in database plugins

Open m1212e opened this issue 9 months ago • 0 comments

Following up on this discussion: https://github.com/hayes/pothos/discussions/1395#discussioncomment-12569508

it would be helpful to allow async queries in fields. In the below example a hypothetical resource server can be queried to return a database filter based on what the user is allowed to do. That way we could inject permission restrictions at query level.

const PostRef = schemaBuilder.drizzleObject("posts", {
  name: "Post",
  fields: (t) => ({
    id: t.exposeInt("id"),
    content: t.exposeString("content"),
    author: t.relation("author", {
      // filter returns a promise which resolves into a query filter depending on the context
      query: async (_args, ctx) => await ctx.abilities.users.filter("read"),
    }),
  }),
});

m1212e avatar Mar 21 '25 08:03 m1212e