pothos
pothos copied to clipboard
[Feature request]: Allow async query fields in database plugins
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"),
}),
}),
});