SoftwareBrothers / adminjs-prisma

MIT License
44 stars 27 forks source link

TypeError: Do not know how to serialize a BigInt #22

Open capaj opened 1 year ago

capaj commented 1 year ago
TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at stringify (/home/capaj/work-repos/official/official-graphql/prisma-admin/node_modules/express/lib/response.js:1150:12)
    at ServerResponse.json (/home/capaj/work-repos/official/official-graphql/prisma-admin/node_modules/express/lib/response.js:271:14)
    at ServerResponse.send (/home/capaj/work-repos/official/official-graphql/prisma-admin/node_modules/express/lib/response.js:162:21)
    at handler (/home/capaj/work-repos/official/official-graphql/prisma-admin/node_modules/@adminjs/express/src/buildRouter.ts:60:15)

I got this in my schema:

  id               BigInt          @id @default(autoincrement())
monish96 commented 1 year ago

I think this is an issue with prisma itself and nothing to do with adminjs. https://github.com/prisma/studio/issues/816

UdittLamba commented 1 year ago

facing the same issue

UdittLamba commented 1 year ago

ok, So I fixed it by patching the bigint prototype BigInt.prototype.toJSON = function () { const int = Number.parseInt(this.toString()) return int ?? this.toString() }

reference

capaj commented 1 year ago

Yes we have the same hackfix In our own codebase. This should resolve it.