Prisma-client-js: Prisma DMMF `JsonFilter` input has no fields

Created on 13 May 2020  路  5Comments  路  Source: prisma/prisma-client-js

Bug description

When I have really simple model:

model Post {
  uuid      String    @default(uuid()) @id
  title     String
  metadata  Json
}

For filter input types, for fields of type Json, it emits JsonFilter object type as field input type:

{
  "name": "PostScalarWhereInput",
  "fields": [
    {
      "name": "title",
      "inputType": [
        {
          "isList": false,
          "isRequired": false,
          "kind": "scalar",
          "type": "String"
        },
        {
          "type": "StringFilter",
          "isList": false,
          "isRequired": false,
          "kind": "object"
        }
      ],
      "isRelationFilter": false
    },
    {
      "name": "metadata",
      "inputType": [
        {
          "isList": false,
          "isRequired": false,
          "kind": "scalar",
          "type": "Json"
        },
        {
          "type": "JsonFilter",
          "isList": false,
          "isRequired": false,
          "kind": "object"
        }
      ],
      "isRelationFilter": false
    }
  ],
  "isWhereType": true,
  "atLeastOne": false
}

But the generated JsonFilter type has no fields which results in empty input type class generated by TypeGraphQL integration:

{
  "name": "JsonFilter",
  "fields": [],
  "atLeastOne": false
}

Environment & setup

  • OS: [e.g. Mac OS, Windows, Debian, CentOS, ...] Windows 10 x64
  • Database: [PostgreSQL, MySQL, MariaDB or SQLite] Postgres
  • Prisma version: [Run prisma -v to see your Prisma version] 2.0.0-beta.5
  • Node.js version: [Run node -v to see your Node.js version] 13.12
@prisma/cli          : 2.0.0-beta.5
Current platform     : windows
Query Engine         : query-engine 0c2ec197653b278b2978845ef958db88824cd82e (at D:\#Projekty\typegraphql-prisma\experiments\node_modules\@prisma\cli\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 0c2ec197653b278b2978845ef958db88824cd82e (at D:\#Projekty\typegraphql-prisma\experiments\node_modules\@prisma\cli\migration-engine-windows.exe)
Introspection Engine : introspection-core 0c2ec197653b278b2978845ef958db88824cd82e (at D:\#Projekty\typegraphql-prisma\experiments\node_modules\@prisma\cli\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 0c2ec197653b278b2978845ef958db88824cd82e (at D:\#Projekty\typegraphql-prisma\experiments\node_modules\@prisma\cli\prisma-fmt-windows.exe)
bu2-confirmed tectypescript json

Most helpful comment

Thanks a lot for your input everyone!
It turned out, that we already had not and equals available, we just didn't expose them!

So from now on, you can filter by equality of a Json blob!

Closed by https://github.com/prisma/prisma/commit/3a1a4fb2f1c739febc7f7509c45ecc0eb64cdb08

All 5 comments

Thanks for reporting @MichalLytek!
For now, this is just a placeholder until we have proper filters.

Hi @timsuchanek!
Is it possible to disable generation of the JsonFilter. Or some workaround to tell the generator it should skip specific fields from the model?
I know this is beta, but thought this json feature is actually usable. Unfortunately it's not at the moment.

Is there any news on this? It is causing a blocking issue for us with an existing database. I have a field of the Json type, so it will break the API. Even when I don't enable the filter for that field (I don't need it) in Nexus, it still results in an exception. Would be great if we can disable this placeholder or workaround it. Now I have to write custom queries in Nexus for normal crud operations.

Thanks a lot for your input everyone!
It turned out, that we already had not and equals available, we just didn't expose them!

So from now on, you can filter by equality of a Json blob!

Closed by https://github.com/prisma/prisma/commit/3a1a4fb2f1c739febc7f7509c45ecc0eb64cdb08

This is how you can filter for Json now:

  const result = await prisma.post.findMany({
    where: {
      jsonData: [
        {
          array1key: 'array1value',
        },
      ],
    },
  })

https://github.com/prisma/prisma/blob/3a1a4fb2f1c739febc7f7509c45ecc0eb64cdb08/src/packages/client/src/__tests__/runtime-tests/blog-env-postgresql/index.js#L239

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maartenraes picture maartenraes  路  4Comments

divyenduz picture divyenduz  路  4Comments

julien1619 picture julien1619  路  3Comments

Errorname picture Errorname  路  3Comments

AhmedElywa picture AhmedElywa  路  4Comments