-
Notifications
You must be signed in to change notification settings - Fork 82
Description
Description
Views in Prisma are read-only database objects, but prisma-nestjs-graphql generates mutation input types for them, which is incorrect by design. This causes TypeScript compilation errors and violates the fundamental nature of database views.
Current Behavior
When a Prisma schema contains a view:
view MyReadOnlyView {
id String @unique
field1 String
field2 String
}The generator creates:
- ✅
MyReadOnlyView(ObjectType) - CORRECT - ❌
MyReadOnlyViewCreateInput- WRONG (views are read-only) - ❌
MyReadOnlyViewUpdateInput- WRONG - ❌
MyReadOnlyViewUpdateManyMutationInput- WRONG - ❌
MyReadOnlyViewScalarWhereInput- WRONG (references non-existent mutation inputs)
This causes compilation errors:
error TS2552: Cannot find name 'MyReadOnlyViewUpdateManyMutationInput'.
106983 @Field(() => MyReadOnlyViewUpdateManyMutationInput, {nullable:false})
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expected Behavior
Views should only generate:
- ✅ ObjectType (output type for queries)
- ✅ WhereInput (for filtering in queries)
- ✅ OrderByInput (for sorting in queries)
Views should never generate:
- ❌ Any Create/Update/Delete/Upsert input types
- ❌ Any mutation-related types
- ❌ ScalarWhereInput that references mutation inputs
Steps to Reproduce
- Create a Prisma schema with a view:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["views"]
}
generator nestgraphql {
provider = "node node_modules/prisma-nestjs-graphql"
output = "../src/@generated/prisma-nestjs-graphql"
emitSingle = true
}
model ParentModel {
id String @id
name String
ViewRefs MyReadOnlyView[]
}
view MyReadOnlyView {
id String @unique
parentModelId String
ParentModel ParentModel @relation(fields: [parentModelId], references: [id])
field1 String
field2 String
}- Run
npx prisma generate - Check generated file - mutation input types are created for the view
- Run TypeScript compilation - fails with "Cannot find name" errors
Environment
prisma-nestjs-graphql: 21.2.0 (latest)@prisma/client: 6.17.0@nestjs/graphql: 12.2.2- Node.js: 20.x
Attempted Workarounds
Workaround 1: Using @HideField directive
/// @HideField({ input: true })
view MyReadOnlyView {
id String @unique
field1 String
}Result: Doesn't work - mutation input types are still generated and referenced
Workaround 2: Hiding relation fields in models
model OtherModel {
id String @id
/// @HideField()
ViewRefs MyReadOnlyView[]
}Result: Doesn't prevent view mutation types from being generated
Workaround 3: Completely hiding views
/// @HideField({ input: true, output: true })
view MyReadOnlyView {
id String @unique
field1 String
}Result: Removes views from GraphQL entirely, but views are still useful for queries
Workaround 4: Excluding from tsconfig
{
"exclude": ["src/@generated/prisma-nestjs-graphql/**/*"]
}Result: Not a real solution - hides all generated types from type checking, creating runtime risks
Root Cause Analysis
The generator treats view definitions identically to model definitions, but they have fundamentally different semantics:
- Models: Represent database tables → support full CRUD operations
- Views: Represent database views → read-only, no mutations possible
Prisma Client correctly handles this distinction (views only have findMany, findUnique, etc.), but the GraphQL generator does not.
Suggested fix
Add logic to detect view models (via DMMF metadata) and skip generation of mutation inputs/args for them. Possibly provide config skipMutationForViews to make behavior optional.
Thank you for maintaining this excellent tool!