Skip to content

[Docs] Add example for combining multiple middleware in Prisma Client #7420

@therbta

Description

@therbta

Problem

The current documentation shows individual middleware examples, but doesn't demonstrate how to properly chain multiple middleware together with proper TypeScript typing.

Suggested Addition

Add a section under the Middleware docs showing:

  1. How to compose multiple middleware
  2. How to handle typing when middleware modifies the query/result
  3. Best practices for middleware ordering

Example Code Needed

const prisma = new PrismaClient().$extends({
  query: {
    $allModels: {
      async $allOperations({ model, operation, args, query }) {
        // Logging middleware
        const start = Date.now()
        const result = await query(args)
        console.log(`${model}.${operation} took ${Date.now() - start}ms`)
        return result
      }
    }
  }
})

Why This Matters

Many production apps need multiple middleware (logging, soft deletes, multi-tenancy). Clear examples would help adoption.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions