Skip to content

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

@m1212e

Description

@m1212e

Following up on this discussion: #1395 (reply in thread)

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"),
    }),
  }),
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions