prisma icon indicating copy to clipboard operation
prisma copied to clipboard

Allow `String` type for `Bigint` fields input create/update (postgres)

Open demkinmaxim opened this issue 4 years ago • 0 comments

Problem

I am using Postgres DB with user insertable BigInt columns. Prisma Client requires me to send BigInt type values.

model job {
  id  BigInt  @id
}
    const job = await prisma.job.create( {
        data: {
            id: '6927893654417707008', // ERROR! BigInt expected, got String
        },
    })

But Postgres is doing fine with strings, internally converting them to BigInt. JSON storing BigInt as string also, so I send and receive strings to/from my frontend.

I've found two types of validations:

  • TS typing
  • prisma object validation (hasCorrectScalarType() fn)

Suggested solution

Probably add id: bigint | number | string to client generator

And add to validator:

hasCorrectScalarType() {
 /...
  if (graphQLType === "String" && expectedType === "BigInt") {
    return true;
  }
}

It seems to be working for me.

demkinmaxim avatar May 05 '22 08:05 demkinmaxim