Skip to content

Fix virtual fields typed as never when mixed with relation fields in select/include#384

Merged
borisno2 merged 3 commits intomainfrom
fix/virtual-fields-never-in-select
Mar 27, 2026
Merged

Fix virtual fields typed as never when mixed with relation fields in select/include#384
borisno2 merged 3 commits intomainfrom
fix/virtual-fields-never-in-select

Conversation

@borisno2
Copy link
Copy Markdown
Member

Summary

  • Adds a StripVirtualFromArgs<T, VirtualKeys> utility type to the generated .opensaas/types.ts
  • Uses it in each list's GetPayload type to strip virtual field keys from T before passing to Prisma.*GetPayload<>, preventing Prisma from resolving unknown virtual field names as never
  • Adds a regression test covering the exact scenario from the issue (virtual field + relation field in the same select)
  • Updates snapshots

Root cause recap: Prisma.*GetPayload<T> returned never for any field in T['select'] it couldn't find in its schema. Intersecting never with string (from the virtual fields type) still gives never. Stripping virtual keys from T before Prisma sees it breaks the cycle.

Test plan

  • All types generator tests pass (pnpm test src/generator/types.test.ts in packages/cli)
  • New regression test should use StripVirtualFromArgs in GetPayload for lists with virtual + relation fields (regression #383) passes
  • Generated GetPayload for a list with virtual fields contains StripVirtualFromArgs<T, keyof ${List}VirtualFields> instead of bare T
  • Generated GetPayload for a list without virtual fields is unchanged (still uses bare T)

Closes #383

🤖 Generated with Claude Code

… in select/include

Adds a \`StripVirtualFromArgs\` utility type to the generated \`.opensaas/types.ts\`
that strips virtual field keys from the select/include object before passing it to
\`Prisma.*GetPayload<>\`. This prevents Prisma from trying to resolve virtual field
names (which don't exist in its schema), which previously produced \`never\` that
poisoned the intersection with the virtual fields type.

Closes #383

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 27, 2026

🦋 Changeset detected

Latest commit: d81fb2b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@opensaas/stack-cli Patch
@opensaas/stack-auth Patch
@opensaas/stack-core Patch
@opensaas/stack-rag Patch
@opensaas/stack-storage-s3 Patch
@opensaas/stack-storage-vercel Patch
@opensaas/stack-storage Patch
@opensaas/stack-tiptap Patch
@opensaas/stack-ui Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-docs Ready Ready Preview, Comment Mar 27, 2026 6:39am

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Core Package Coverage (./packages/core)

Status Category Percentage Covered / Total
🔵 Lines 86.17% 455 / 528
🔵 Statements 85.45% 464 / 543
🔵 Functions 97.22% 70 / 72
🔵 Branches 73.86% 325 / 440
File CoverageNo changed files found.
Generated in workflow #1014 for commit d81fb2b by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for UI Package Coverage (./packages/ui)

Status Category Percentage Covered / Total
🔵 Lines 76.03% 92 / 121
🔵 Statements 75.39% 95 / 126
🔵 Functions 75.6% 31 / 41
🔵 Branches 65.78% 75 / 114
File CoverageNo changed files found.
Generated in workflow #1014 for commit d81fb2b by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for CLI Package Coverage (./packages/cli)

Status Category Percentage Covered / Total
🔵 Lines 75.87% 1176 / 1550
🔵 Statements 75.49% 1220 / 1616
🔵 Functions 79.59% 156 / 196
🔵 Branches 65.14% 542 / 832
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/generator/types.ts 93.47% 79.28% 93.33% 94.5% 11, 21, 30, 40, 68, 103-106, 151, 198, 238, 255, 356-360, 425-429, 464, 521, 872, 936-951, 959-963, 990-992
Generated in workflow #1014 for commit d81fb2b by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Auth Package Coverage (./packages/auth)

Status Category Percentage Covered / Total
🔵 Lines 64.49% 89 / 138
🔵 Statements 61.03% 94 / 154
🔵 Functions 74.46% 35 / 47
🔵 Branches 62.79% 54 / 86
File CoverageNo changed files found.
Generated in workflow #1014 for commit d81fb2b by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Storage Package Coverage (./packages/storage)

Status Category Percentage Covered / Total
🔵 Lines 42.44% 73 / 172
🔵 Statements 42.77% 74 / 173
🔵 Functions 42.85% 15 / 35
🔵 Branches 40.13% 61 / 152
File CoverageNo changed files found.
Generated in workflow #1014 for commit d81fb2b by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for RAG Package Coverage (./packages/rag)

Status Category Percentage Covered / Total
🔵 Lines 47.97% 355 / 740
🔵 Statements 48.14% 377 / 783
🔵 Functions 54.26% 70 / 129
🔵 Branches 42.55% 180 / 423
File CoverageNo changed files found.
Generated in workflow #1014 for commit d81fb2b by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Storage S3 Package Coverage (./packages/storage-s3)

Status Category Percentage Covered / Total
🔵 Lines 100% 40 / 40
🔵 Statements 100% 40 / 40
🔵 Functions 100% 9 / 9
🔵 Branches 100% 19 / 19
File CoverageNo changed files found.
Generated in workflow #1014 for commit d81fb2b by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Storage Vercel Package Coverage (./packages/storage-vercel)

Status Category Percentage Covered / Total
🔵 Lines 100% 38 / 38
🔵 Statements 100% 38 / 38
🔵 Functions 100% 8 / 8
🔵 Branches 100% 22 / 22
File CoverageNo changed files found.
Generated in workflow #1014 for commit d81fb2b by the Vitest Coverage Report Action

@borisno2 borisno2 enabled auto-merge (squash) March 27, 2026 06:45
@borisno2 borisno2 merged commit 6b7284a into main Mar 27, 2026
6 checks passed
@borisno2 borisno2 deleted the fix/virtual-fields-never-in-select branch March 27, 2026 06:46
@github-actions github-actions bot mentioned this pull request Mar 27, 2026
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.

Virtual fields typed as never when mixing with relation fields in select or using include

1 participant