Prisma extensions and i18n

Hello! I have an issue with creating an extension that would append a computed field based on relations. I read in the docs that adding anything besides scalars to the needs field is impossible, so I wanted to take another approach and append relations using 1 extension. Next, I would use them in a second extension. However, they still don't show up in the needs field. How do i utilise the relations to create an extension appending a computed field? What I want to is basically: take the metadata with model's name based on the locale (from the metadatas relation) and append that name as a computed field. Here's my code snippet that doesn't work:
export const prisma = (locale: Locale) =>
new PrismaClient({
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
})
.$extends({
name: "i18n-queries",
query: {
allergen: {
findMany: async ({ query, args }) => {
return await query({
...args,
include: {
metadatas: {
select: { name: true, description: true, locale: true },
},
},
});
},
// the same for other methods
},
},
})
.$extends({
name: "i18n-fields",
result: {
allergen: {
name: {
needs: { metadatas: true }, // this doesn't work
compute: (allergen) => {
return ""; // compute the value
},
},
},
},
});
export const prisma = (locale: Locale) =>
new PrismaClient({
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
})
.$extends({
name: "i18n-queries",
query: {
allergen: {
findMany: async ({ query, args }) => {
return await query({
...args,
include: {
metadatas: {
select: { name: true, description: true, locale: true },
},
},
});
},
// the same for other methods
},
},
})
.$extends({
name: "i18n-fields",
result: {
allergen: {
name: {
needs: { metadatas: true }, // this doesn't work
compute: (allergen) => {
return ""; // compute the value
},
},
},
},
});
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server