0

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.

1
  • Do you have circular dependencies? I'm not seeing any in the code you've shared, but this can happen if you have a situation where module A statically depends on a value from module B, and module B also statically depends on a value from module A. Whichever one the runtime evaluates first will observe undefined for the other not-yet-initialized value. It could be indirect with other modules in-between in the dependency chain. I've used madge in the past to debug this stuff. Commented Nov 13 at 11:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.