piscopancer
piscopancer2mo ago

TS error when JSON field in Prisma - Type instantiation is excessively deep

error seen here
const field = trpc.field.find.useQuery({
documentId: props.docId,
path: props.fieldName,
})
field.data?.value
/*
Type instantiation is excessively deep and possibly infinite.
(property) value: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | ... 4 more ... | null)[] | Record<...> | null)[] | Record<...> | null)[] | Record<...> | null)[] | Record<...> | null)[] | Record<...> | null)[] | Record<...> | null | undefined
*/
const field = trpc.field.find.useQuery({
documentId: props.docId,
path: props.fieldName,
})
field.data?.value
/*
Type instantiation is excessively deep and possibly infinite.
(property) value: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | ... 4 more ... | null)[] | Record<...> | null)[] | Record<...> | null)[] | Record<...> | null)[] | Record<...> | null)[] | Record<...> | null)[] | Record<...> | null | undefined
*/
find
export const fieldRouter = t.router({
find: t.procedure
.input(
z.object({
documentId: z.string(),
path: z.string(),
})
)
.query(async ({ input: { documentId, path } }) => {
return db.field.findFirst({
where: {
documentId,
path,
},
select: {
value: true,
},
})
}),
export const fieldRouter = t.router({
find: t.procedure
.input(
z.object({
documentId: z.string(),
path: z.string(),
})
)
.query(async ({ input: { documentId, path } }) => {
return db.field.findFirst({
where: {
documentId,
path,
},
select: {
value: true,
},
})
}),
prisma schema
model Field {
documentId String
path String
value Json

document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)

@@id([documentId, path])
}
model Field {
documentId String
path String
value Json

document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)

@@id([documentId, path])
}
4 Replies
piscopancer
piscopancerOP2mo ago
here it's just fine
No description
piscopancer
piscopancerOP2mo ago
but look at the find object
No description
piscopancer
piscopancerOP2mo ago
trpcRouter is fine too
No description
FluX
FluX2mo ago
You're missing an await. Not sure though if this will fix the issue, but that's the only error I see in your code Should be
return await db.field.findFirst({
where: {
documentId,
path,
},
select: {
value: true,
},
})
return await db.field.findFirst({
where: {
documentId,
path,
},
select: {
value: true,
},
})

Did you find this page helpful?