Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$on is missing on the extended client #24070

Open
aqrln opened this issue May 3, 2024 · 3 comments
Open

$on is missing on the extended client #24070

aqrln opened this issue May 3, 2024 · 3 comments
Labels
kind/feature A request for a new feature. team/client Issue for team Client. topic: client types Types in Prisma Client topic: clientExtensions topic: logging topic: $on

Comments

@aqrln
Copy link
Member

aqrln commented May 3, 2024

Bug description

After applying a query extension to the client, it's not possible to add event listeners to it anymore.

How to reproduce

  1. Create a client
  2. Apply an extension
  3. $on method is not present, neither in types nor at run time

Expected behavior

Client extensions shouldn't remove any methods from the client.

Prisma information

  const prisma = new PrismaClient({
    log: [{ emit: "event", level: "query" }],
  }).$extends({
    query: {
      $allOperations({ query, args }) {
        return query(args);
      },
    },
  });

  prisma.$on("query", (e) => console.log(e));

Environment & setup

  • OS: macOS
  • Database: SQLite
  • Node.js version: v22.1.0

Prisma Version

prisma                  : 5.13.0
@prisma/client          : 5.13.0
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v22.1.0
Query Engine (Node-API) : libquery-engine b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b (at ../../node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b (at ../../node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.13.0-23.b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b
Default Engines Hash    : b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b
Studio                  : 0.500.0
@SevInf
Copy link
Contributor

SevInf commented May 3, 2024

This is by design: https://www.prisma.io/docs/orm/prisma-client/client-extensions/query#if-you-use-the-query-extension-component-and-middlewares

Middlewares are supposed to be added before extensions.

@aqrln
Copy link
Member Author

aqrln commented May 4, 2024

This issue is about events/logging, not middleware, though.

@SevInf
Copy link
Contributor

SevInf commented May 6, 2024

Right, linked to the wrong page. $on is also missing by design: https://www.prisma.io/docs/orm/prisma-client/client-extensions#usage-of-on-and-use-with-extended-clients

@aqrln aqrln added kind/feature A request for a new feature. and removed kind/bug A reported bug. labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. topic: client types Types in Prisma Client topic: clientExtensions topic: logging topic: $on
Projects
None yet
Development

No branches or pull requests

2 participants