$extends(withAccelerate()) breaks type inference when orderBy is used inside nested includes
Description:
Environment:
- Prisma: 7.2.0
- @prisma/extension-accelerate: 3.0.1
- TypeScript: 5.9.3
- Framework: Next.js + tRPC
Setup (per docs):
```ts
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";
export const prisma = new PrismaClient({
accelerateUrl: process.env.DATABASE_URL,
}).$extends(withAccelerate());
Bug:
When using orderBy inside a nested include, all type inference for that query breaks. The return type loses all included relations.
Reproduction:
//
BROKEN - orderBy inside nested include
const result = await prisma.membership.findFirst({
include: {
prices: {
where: { status: "ACTIVE" },
orderBy: { createdAt: "desc" }, // <-- This breaks inference
take: 1,
},
},
});
result.prices // Error: Property 'prices' does not exist
//
WORKS - same query without orderBy
const result = await prisma.membership.findFirst({
include: {
prices: {
where: { status: "ACTIVE" },
take: 1,
},
},
});
result.prices //
Type: Price[]
Impact:
- 1000+ type errors across codebase
- All tRPC RouterOutputs types break
- Nested type derivations fail completely
Workaround:
Remove orderBy from nested includes and sort in JS after fetching.
Environment:
- Prisma: 7.2.0
- @prisma/extension-accelerate: 3.0.1
- TypeScript: 5.9.3
- Framework: Next.js + tRPC
Setup (per docs):
```ts
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";
export const prisma = new PrismaClient({
accelerateUrl: process.env.DATABASE_URL,
}).$extends(withAccelerate());
Bug:
When using orderBy inside a nested include, all type inference for that query breaks. The return type loses all included relations.
Reproduction:
//
const result = await prisma.membership.findFirst({
include: {
prices: {
where: { status: "ACTIVE" },
orderBy: { createdAt: "desc" }, // <-- This breaks inference
take: 1,
},
},
});
result.prices // Error: Property 'prices' does not exist
//
const result = await prisma.membership.findFirst({
include: {
prices: {
where: { status: "ACTIVE" },
take: 1,
},
},
});
result.prices //
Impact:
- 1000+ type errors across codebase
- All tRPC RouterOutputs types break
- Nested type derivations fail completely
Workaround:
Remove orderBy from nested includes and sort in JS after fetching.
Accelerate
Prisma Postgres