New Features
1. Using "type" to define the shape of auth()
In previous versions, the auth()
call in ZModel must be resolved to a User
model or a model marked @@auth
. However, when using auth-as-a-service products like Clerk, you can choose not to store user data in the database. This release allows you to define the auth model as a type
. E.g.:
type User {
id String
...
}
Or
type Auth {
id String
@@auth
}
2. Portable mode for TanStack Query hooks
The @zenstackhq/tanstack-query plugin has a new "portable" option to make the generated code's typing "self-contained". When enabled, PrismaClient's types will be included with the generated code. It's useful when you output the hooks code into a separate project where Prisma/ZenStack is not referenced. Please note that the "@zenstackhq/tanstack-query" package still needs to be referenced in the target project. doc
plugin hooks {
provider = '@zenstackhq/tanstack-query'
output = "../client/src/lib/hooks"
target = "react"
portable = true
}
3. Reducing the size of generated OpenAPI spec
When using the @zenstackhq/openapi plugin to generate API spec for the "rpc" flavor, the result can be huge due to how Prisma allows flexible structures of query and mutation input. This release introduced a omitInputDetails
option to generate the specification with lower fidelity. When the option is turned on, fields in the query/mutation input like where
, select
, data
, etc. will be generated as generic objects. doc
plugin openapi {
provider = '@zenstackhq/openapi'
flavor = 'rpc'
omitInputDetails = true
...
}
Fixes and Improvements
- TanStack Query and SWR hooks now handle nested read data during optimistic updates #1840
- Prisma client extensions now work consistently regardless the order you call
enhance
and$extends
- Generated TS code now includes
// @ts-nocheck
to suppress tsc warnings by @genu - Fixed the issue that unreferenced enums in ZModel cause generation errors #1835
- Fixed compatibility issues with turborepo #1687
- Fixed ZModel validation error when importing enums from a separate schema file #1849
- Fixed runtime error when creating delegate model entities with foreign key fields with default values #1843
- Include
null
into a type's field if the field is optional #1857 - Fixed code generation issue when a
type
is recursive #1868 - Using
@@validate
inside type declarations is now supported - Fixed OpenAPI generation to exclude foreign key fields from mutation payload by @thomassnielsen
New Contributors
- Welcome @genu as our new contributor! ❤️
Full Changelog: v2.8.1...v2.9.0