docs icon indicating copy to clipboard operation
docs copied to clipboard

Client extensions: $allOperations limitations

Open ul8 opened this issue 2 years ago • 5 comments

Bug description

prisma.$extends typescript validation fails when trying to modify all operations in a specific model

I get a type error on args.where

Property 'where' does not exist on type '({ readonly select?: ReadonlyDeep<CategoryTranslationSelect<DefaultArgs> | null | undefined>; readonly include?: ReadonlyDeep<CategoryTranslationInclude<DefaultArgs> | null | undefined>; } & { ...; }) | ... 12 more ... | ({ ...; } & { ...; })'.
  Property 'where' does not exist on type '{ readonly select?: ReadonlyDeep<CategoryTranslationSelect<DefaultArgs> | null | undefined>; readonly include?: ReadonlyDeep<CategoryTranslationInclude<DefaultArgs> | null | undefined>; } & { ...; }'.ts(2339)

How to reproduce

Code that works fine:

prisma.$extends({
    query: {
        categoryTranslation: {
            async findMany({ model, operation, args, query }) {
                args.where = { locale: { code: 'en_US' }, ...args.where };
                return query(args);
            }
        }
    }
});

When I change it to this it starts showing the above error

prisma.$extends({
    query: {
        categoryTranslation: {
            $allOperations({ model, operation, args, query }) {
                args.where = { locale: { code: 'en_US' }, ...args.where };
                return query(args);
            }
        }
    }
});

Expected behavior

From reading the documentation, I would expect not to see any error here.

If this is expected behavior, the documentation could probably be improved.

To be clear, it does work, just the type errors are the problem.

Prisma information

model CategoryTranslation {
  id                  Int               @id @default(autoincrement())
  localeId            Int
  locale              Locale            @relation(fields: [localeId], references: [id])
}

model Locale {
  id                        Int                        @id @default(autoincrement())
  code                      String                     @unique
  categoryTranslations      CategoryTranslation[]
}

Environment & setup

  • OS:macOS→
  • Database: SQLite→
  • Node.js version: 19.3

Prisma Version

prisma                  : 4.11.0
@prisma/client          : 4.11.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 8fde8fef4033376662cad983758335009d522acb (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 8fde8fef4033376662cad983758335009d522acb (at node_modules/@prisma/engines/migration-engine-darwin)
Format Wasm             : @prisma/prisma-fmt-wasm 4.11.0-57.8fde8fef4033376662cad983758335009d522acb
Default Engines Hash    : 8fde8fef4033376662cad983758335009d522acb
Studio                  : 0.483.0
Preview Features        : clientExtensions

ul8 avatar Mar 02 '23 16:03 ul8

Related https://github.com/prisma/prisma/issues/16500#issuecomment-1337088740 https://github.com/prisma/prisma/issues/16500#issuecomment-1337112721 https://github.com/prisma/prisma/issues/16500#issuecomment-1337135233 https://github.com/prisma/prisma/issues/16500#issuecomment-1362632016

millsp avatar Jun 01 '23 00:06 millsp

Do you know if there has been any progress on this issue? The code works just fine but there are build errors. I don't want to enable ignoreBuildError in next.config.js. Also, this error is not ignorable using // eslint-disable-next-line

$allOperations extensions are critical for our current multitenant solution. Would love to find a solution to this.

If anyone has found work or fix around, I'd love to hear.

BrettBurbidge avatar Dec 05 '23 16:12 BrettBurbidge

Please open an issue in https://github.com/prisma/prisma. Thanks.

janpio avatar Dec 05 '23 18:12 janpio

This issue is already articulated very well on this ticket from @ul8. I am happy to create a new ticket, but it be a duplicate this one.

If an issue is required to get this fixed. I will submit one.

BrettBurbidge avatar Dec 06 '23 20:12 BrettBurbidge

Having the same issue, would appreciate a fix. That is crucial for multi tenancy development.

gal-terra avatar Feb 26 '24 12:02 gal-terra