prisma-client-go
prisma-client-go copied to clipboard
Unique composite key in Where() subquery results in runtime error
a user reported:
model AccountEntity {
id Int @id @default(autoincrement())
...
orgId Int
entityId String
...
users UserEntity[]
@@unique([orgId, entityId])
}
model UserEntity {
id Int @id @default(autoincrement())
...
account AccountEntity? @relation(fields: [accountId], references: [id])
accountId Int?
...
}
and the following client query compiles
userEntities, err := client.UserEntity.FindMany(
db.UserEntity.Account.Where(
db.AccountEntity.OrgIDEntityID(
db.AccountEntity.OrgID.Equals(int(orgID)),
db.AccountEntity.EntityID.Equals(entityID),
),
), ).OrderBy(db.UserEntity.Email.Order(db.DESC)).Take(int(itemsPerPage)).Skip(int(page * itemsPerPage)).Exec(ctx)
but ends up with this error trace
Error in query graph construction: QueryParserError(QueryParserError { path: QueryPath { segments: [\"Query\", \"findManyUserEntity\", \"where\", \"UserEntityWhereInput\", \"AND\"] }, error_kind: InputUnionParseError { parsing_errors: [QueryParserError { path: QueryPath { segments: [\"Query\", \"findManyUserEntity\", \"where\", \"UserEntityWhereInput\", \"AND\"] }, error_kind: ValueTypeMismatchError { have: List([Object({\"account\": Object({\"is\": Object({\"AND\": List([Object({\"orgId_entityId\": Object({\"orgId\": Int(11), \"entityId\": String(\"account_6\")})})])})})})]), want: Object(UserEntityWhereInput) } }, QueryParserError { path: QueryPath { segments: [\"Query\", \"findManyUserEntity\", \"where\", \"UserEntityWhereInput\", \"AND\", \"UserEntityWhereInput\", \"account\"] }, error_kind: InputUnionParseError { parsing_errors: [QueryParserError { path: QueryPath { segments: [\"Query\", \"findManyUserEntity\", \"where\", \"UserEntityWhereInput\", \"AND\", \"UserEntityWhereInput\", \"account\", \"AccountEntityRelationFilter\", \"is\", \"AccountEntityWhereInput\", \"AND\"] }, error_kind: InputUnionParseError { parsing_errors: [QueryParserError { path: QueryPath { segments: [\"Query\", \"findManyUserEntity\", \"where\", \"UserEntityWhereInput\", \"AND\", \"UserEntityWhereInput\", \"account\", \"AccountEntityRelationFilter\", \"is\", \"AccountEntityWhereInput\", \"AND\"] }, error_kind: ValueTypeMismatchError { have: List([Object({\"orgId_entityId\": Object({\"orgId\": Int(11), \"entityId\": String(\"account_6\")})})]), want: Object(AccountEntityWhereInput) } }, QueryParserError { path: QueryPath { segments: [\"Query\", \"findManyUserEntity\", \"where\", \"UserEntityWhereInput\", \"AND\", \"UserEntityWhereInput\", \"account\", \"AccountEntityRelationFilter\", \"is\", \"AccountEntityWhereInput\", \"AND\", \"AccountEntityWhereInput\", \"orgId_entityId\"] }, error_kind: FieldNotFoundError }] } }, QueryParserError { path: QueryPath { segments: [\"Query\", \"findManyUserEntity\", \"where\", \"UserEntityWhereInput\", \"AND\", \"UserEntityWhereInput\", \"account\", \"AccountEntityWhereInput\", \"is\"] }, error_kind: FieldNotFoundError }, QueryParserError { path: QueryPath { segments: [\"Query\", \"findManyUserEntity\", \"where\", \"UserEntityWhereInput\", \"AND\", \"UserEntityWhereInput\", \"account\"] }, error_kind: ValueTypeMismatchError { have: Object({\"is\": Object({\"AND\": List([Object({\"orgId_entityId\": Object({\"orgId\": Int(11), \"entityId\": String(\"account_6\")})})])})}), want: Null } }] } }] } })
Basically the OrgIDEntityID() unique function call is now allowed internally in the QE, so it's a bug in the sense that the Go client allows this.
We may not add this (this is up to the query engine team), which means the “fix” to this bug would be to just disallow this syntax (so only allowing specifying individual fields), at least in the short term