Prisma-client-js: where query not working as expected

Created on 16 Aug 2020  路  7Comments  路  Source: prisma/prisma-client-js

Bug description

not filter not working as doc says here

await prisma.post.findMany({
      where: {
        content: {
          not: { contains: "sample" },
        },
      },
    });


Error happened  PrismaClientValidationError: 
Invalid `prisma.post.findMany()` invocation in
/home/galala/projects/prisma-examples/typescript/rest-express/src/index.ts:24:23

{
  where: {
    content: {
      not: {
        contains: 'sample'
      }
      ~~~~~~~~~~~~~~~~~~~~
    }
  }
}

Argument not: Got invalid value 
{
  contains: 'sample'
}
on prisma.findManyPost. Provided Json, expected String or null or NullableStringFilter.


How to reproduce

https://github.com/mohamedGamalAbuGalala/prisma-bugs

link to the sandbox

Expected behavior

query with not is supposed to work as expected in docs and in typedef not?: string | StringFilter | null

bu0-needs-info kinbug

All 7 comments

Do you want "NOT" as boolean expression?
If yes then you need an array here.
Hence, the right syntax will be

await prisma.post.findMany({
      where: {
          NOT: [ content:{
                  contains: "sample" 
              }],
        },
    });

For more refer this.

@RitikDua
Your example is not working with the typedef

image

The problem here is that typedef has the definition of not as not?: string | StringFilter | null

So this example should work and it is accepted by typedef but it doesn't in runtime and it throws the error I posted in the issue description.

 await prisma.post.findMany({
      where: {
        content: {
          not: { contains: "sample" },
        },
      },
    });

The problem here is that typedef has the definition of not as not?: string | StringFilter | null

So this example should work and it is accepted by typedef but it doesn't in runtime and it throws the error I posted in the issue description.

 await prisma.post.findMany({
      where: {
        content: {
          not: { contains: "sample" },
        },
      },
    });

sorry , i did a little mistake there . Actually,you need not in Capital letters.
Hence you need it as NOT

I know that NOT will work for me.

@pantharshit00 what kind of info do you need?

I updated the issue description to include a link to code sandbox

Hey @mohamedGamalAbuGalala

I was waiting for you to respond to @RitikDua's comment so that is why I added that label.

Also, I am unable to reproduce this with 2.6.0, the provided example works.

I was having trouble running it on codesandbox so I made a repl it with working example: https://repl.it/@HarshitPant/prisma-issue-833#src/index.ts

So please try this once again with latest version.

Confirming that the bug is no longer exist in 2.6.0 (sandbox)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timsuchanek picture timsuchanek  路  4Comments

esistgut picture esistgut  路  4Comments

FluorescentHallucinogen picture FluorescentHallucinogen  路  3Comments

Errorname picture Errorname  路  3Comments

MichalLytek picture MichalLytek  路  3Comments