Skip to content

feat(plugin-prisma): support async query callbacks in relation fields - #1666

Open
babbarankit wants to merge 1 commit into
hayes:mainfrom
babbarankit:fix/async-prisma-query
Open

feat(plugin-prisma): support async query callbacks in relation fields#1666
babbarankit wants to merge 1 commit into
hayes:mainfrom
babbarankit:fix/async-prisma-query

Conversation

@babbarankit

Copy link
Copy Markdown

Summary

Closes #1397

  • QueryForField return type now accepts MaybePromise, enabling async permission-based filtering:
    query: async (args, ctx) => await ctx.abilities.users.filter("read")
  • relation() fallback path handles async query results via isThenable check
  • relatedConnection() splits sync (selection tree) and async (fallback/resolve) paths — selection tree uses base pagination when query is async

Trade-off

When query is async, the batched selection tree does NOT include the filter (selection building is synchronous). The relation IS included and data IS fetched, but unfiltered from the batch. The resolve fallback path applies the filter correctly by awaiting the async result.

Test plan

  • All 89 existing plugin-prisma tests pass (sync behavior unchanged)
  • Type change is additive — MaybePromise<T> accepts both T and Promise<T>
  • Manual: async query with resolve correctly filters results
  • Manual: async query without resolve — fallback behavior

🤖 Generated with Claude Code

Allow `query` option on `relation()` and `relatedConnection()` to return
a Promise. This enables permission-based filtering via async context:

```ts
query: async (args, ctx) => await ctx.abilities.users.filter("read")
```

Trade-off: when `query` is async, the batched selection tree (sync path)
does NOT include the filter — it falls through to the resolve/fallback
path which correctly awaits the async result.

Changes:
- `QueryForField` type now accepts `MaybePromise` return
- `relation()` fallback uses `isThenable` to handle async query
- `relatedConnection()` splits sync (selection tree) and async (fallback)
  paths — selection tree falls back to base pagination when query is async

Closes hayes#1397

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 6, 2026

Copy link
Copy Markdown

@babbarankit is attempting to deploy a commit to the Michael Hayes' projects Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Sep 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6796698

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant