Prisma1: Cannot use a null criteria in Prisma Client "where" filter (equivalent of SQL's IS NULL)

Created on 4 Jan 2019  路  4Comments  路  Source: prisma/prisma1

Describe the bug
In the prisma Client, when using null as the criteria in a where filter, corresponding records aren't fetched.

To Reproduce
datamodel.prisma

type User {
  id: ID! @unique
  name: String
}

In JavaScript code, I'm trying to retrieve all Users that have a null name:

const usersWithNoName = await prisma
  .users({
    where: {
      name: null
    }
  })

This doesn't return any records even if there are some records that have a null name

If I directly use a GraphQL query to perform the same task, however, I am getting the expected records:

      const query = `
        query ($nullValue: String){
          users(where:{
            name: $nullValue
          }) {
            id
          }
        }
      `

      const variables = { nullValue: null }
      const { users } = await prisma.$graphql(query, variables)

Expected behavior
The records with a null name should be returned

Versions (please complete the following information):

  • OS: macOS Mojave 10.14.2
  • prisma CLI: prisma/1.23.2 (darwin-x64) node-v10.15.0
  • Prisma Server: prismagraphql/prisma:1.22
  • prisma-client-lib: 1.23.2
  • Database: PostgreSQL 11.1
bu0-needs-info areclient

Most helpful comment

@pantharshit00 I am running into a similar issue where with the generated typescript client.

The generated typescript code is

export interface TenantWhereInput {
address?: String;
  address_not?: String;
  address_in?: String[] | String;
  address_not_in?: String[] | String;
  address_lt?: String;
  address_lte?: String;
  address_gt?: String;
  address_gte?: String;
  address_contains?: String;
  address_not_contains?: String;
  address_starts_with?: String;
  address_not_starts_with?: String;
  address_ends_with?: String;
  address_not_ends_with?: String;
}

Then when I try to do

let tenants = await prisma.tenants({
      where: {
        address: null
      }
   });

I get an error saying that type null is not assignable to type String

Looks related to https://github.com/prisma/prisma/issues/3774

  • OS: macOS Sierra 10.12.6
  • prisma CLI: prisma/1.26.4 (darwin-x64) node-v11.9.0
  • Prisma Server: prismagraphql/prisma:1.26
  • prisma: 1.26.4
  • prisma-binding: 2.3.2
  • Database: PostgreSQL 11.1

All 4 comments

Hi @mobiware,

I am unable to reproduce this bug. I used the following piece of code to reproduce this:

const { prisma } = require('./generated/prisma-client')

async function whyNodeDoesntHaveTopLevelAwaitYet(){
  const usersWithNoName = await prisma.users({where:{
    name: null
  }})
  console.log(usersWithNoName);
}

whyNodeDoesntHaveTopLevelAwaitYet();

Here is the output of the code I used:
image

You are using an old version of prisma server so please try upgrading that.

@pantharshit00 I am running into a similar issue where with the generated typescript client.

The generated typescript code is

export interface TenantWhereInput {
address?: String;
  address_not?: String;
  address_in?: String[] | String;
  address_not_in?: String[] | String;
  address_lt?: String;
  address_lte?: String;
  address_gt?: String;
  address_gte?: String;
  address_contains?: String;
  address_not_contains?: String;
  address_starts_with?: String;
  address_not_starts_with?: String;
  address_ends_with?: String;
  address_not_ends_with?: String;
}

Then when I try to do

let tenants = await prisma.tenants({
      where: {
        address: null
      }
   });

I get an error saying that type null is not assignable to type String

Looks related to https://github.com/prisma/prisma/issues/3774

  • OS: macOS Sierra 10.12.6
  • prisma CLI: prisma/1.26.4 (darwin-x64) node-v11.9.0
  • Prisma Server: prismagraphql/prisma:1.26
  • prisma: 1.26.4
  • prisma-binding: 2.3.2
  • Database: PostgreSQL 11.1

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

@seawatts Sorry for a very late response. This issue does seem to be a duplicate of https://github.com/prisma/prisma/issues/3774. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikolasburk picture nikolasburk  路  3Comments

sorenbs picture sorenbs  路  3Comments

schickling picture schickling  路  3Comments

marktani picture marktani  路  3Comments

sedubois picture sedubois  路  3Comments