feat(plugin-prisma): support async query callbacks in relation fields - #1666
Open
babbarankit wants to merge 1 commit into
Open
feat(plugin-prisma): support async query callbacks in relation fields#1666babbarankit wants to merge 1 commit into
babbarankit wants to merge 1 commit into
Conversation
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>
|
@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. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1397
QueryForFieldreturn type now acceptsMaybePromise, enabling async permission-based filtering:relation()fallback path handles async query results viaisThenablecheckrelatedConnection()splits sync (selection tree) and async (fallback/resolve) paths — selection tree uses base pagination when query is asyncTrade-off
When
queryis 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. Theresolvefallback path applies the filter correctly by awaiting the async result.Test plan
MaybePromise<T>accepts bothTandPromise<T>querywithresolvecorrectly filters resultsquerywithoutresolve— fallback behavior🤖 Generated with Claude Code