PrismaP
Prisma3mo ago
4 replies
Swerk

Prisma include becomes undefined when importing nested include objects across multiple files

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 only returns:
address: {
  streetName: "...",
  cityId: 37,
  // ...
}


The nested city -> department -> region relations are not loaded because the include was
undefined
.

Expected behaviour:
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.
Was this page helpful?