Problem
I'm working with Prisma and TypeScript and I have a set of nested include objects split across multiple files.
However, when I import and use them in a repository, some of the nested includes appear as undefined at runtime.
// owner.includes.ts
export const ownerIndexInclude: Prisma.OwnerInclude = {
user: true,
address: {
include: DetailedAddressInclude,
},
};
// address.includes.ts
export const DetailedAddressInclude: Prisma.AddressInclude = {
city: {
include: DetailedCityInclude,
},
};
// city.includes.ts
export const DetailedCityInclude: Prisma.CityInclude = {
department: {
include: DetailedDepartmentInclude,
},
country: true,
};
// department.includes.ts
export const DetailedDepartmentInclude: Prisma.DepartmentInclude = {
region: true,
};
When I log the include objects, I get:
{ user: true, address: { include: undefined } }
{ city: { include: { department: [Object], country: true } } }
{ department: { include: { region: true } }, country: true }
{ region: true }
And Prisma returns only:
address: {
streetName: "...",
cityId: 37,
// ...
}
The nested city -> department -> region relations are not loaded because the include was undefined.
Expected behavior
ownerIndexInclude should contain all nested includes, and Prisma should hydrate the entire object tree.
Question
Is this a known issue with Prisma + TypeScript module evaluation order? How can I reliably build nested include objects across multiple files without them becoming undefined?
Any help or recommended pattern would be appreciated.
Astatically depends on a value from moduleB, and moduleBalso statically depends on a value from moduleA. Whichever one the runtime evaluates first will observeundefinedfor the other not-yet-initialized value. It could be indirect with other modules in-between in the dependency chain. I've usedmadgein the past to debug this stuff.