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

Prisma client not setting null values in the database #3552

Closed
afropolymath opened this issue Sep 8, 2020 · 4 comments
Closed

Prisma client not setting null values in the database #3552

afropolymath opened this issue Sep 8, 2020 · 4 comments
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug.

Comments

@afropolymath
Copy link

afropolymath commented Sep 8, 2020

Bug description

When I try to use the Prisma client in my GraphQL resolver (starting from prisma version 2.6.1), I keep on getting an error that one of the keys provided is missing a value when I try perform an update query to set a field to null. The thing is that this field is actually defined as nullable both in the schema definition and across all the type definitions as well.

How to reproduce

extendType({
  type: 'Mutation',
  definition(t) {
    t.field('updatePublisherInfo', {
      type: 'Book',
      args: {
        id: idArg({ required: true }),
        data: arg({ type: 'UpdateInput', required: true }),
      },
      resolve: async (root, { id, data }, { prisma }) => {
        return prisma.book.update({
          where: { id },
          data: {
            ...data,
            isActive: data.isActive ?? false,
          },
        })
      },
    })
  }
})

Given that any of the keys in data is null regardless of whether that field has been set as nullable or not, I get this error in the console.

'Error: Missing a required value at `Mutation.updateOneBook.data.UpdateInput.bookPublisherName`',
[2]        |                   '    at PrismaClientFetcher.request (/Users/chidieberennadi/Work/code-book/packages/api/node_modules/@prisma/client/src/runtime/getPrismaClient.ts:1180:15)',
[2]        |                   '    at processTicksAndRejections (internal/process/task_queues.js:93:5)',
[2]        |                   '    at middleware (/Users/chidieberennadi/Work/code-book/packages/api/node_modules/graphql-shield/src/generator.ts:70:16)'

Expected behavior

Set nullable values in the database to null without throwing an error.

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v14.5.0
  • Prisma version:
@prisma/cli          : 2.6.1
Current platform     : darwin
Query Engine         : query-engine 6a8054bb549e4cc23f157b0010cb2e95cb2637fb (at node_modules/@prisma/cli/query-engine-darwin)
Migration Engine     : migration-engine-cli 6a8054bb549e4cc23f157b0010cb2e95cb2637fb (at node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 6a8054bb549e4cc23f157b0010cb2e95cb2637fb (at node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary        : prisma-fmt 6a8054bb549e4cc23f157b0010cb2e95cb2637fb (at node_modules/@prisma/cli/prisma-fmt-darwin)
Studio               : 0.272.0
@afropolymath
Copy link
Author

I ended up resolving the issue by replacing assignments to null with { set: null }. Seems like a lot of changes to make though given that this was a minor version bump 😅

@janpio
Copy link
Member

janpio commented Sep 8, 2020

Have you tried updating to 2.6.2 for CLI and Client? We had a few regressions in 2.6.0 and 2.6.1 which made that patch release necessary - and that should have caught these cases. If not, we still have some work in front of us to also fix that.

@pantharshit00
Copy link
Contributor

@afropolymath Indeed this was a regression that we fixed: #3497

If you can still reproduce this in 2.6.2, please report back. This might be a problem in nexus plugin then.

@pantharshit00 pantharshit00 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. labels Sep 9, 2020
@afropolymath
Copy link
Author

@pantharshit00 @janpio Thanks for the prompt response. Just did a package bump and seems like the issue is resolved in 2.6.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

3 participants