MichalLytek / MichalLytek/typegraphql-prisma
Error setting json value to null
- Dominant language
- TypeScript
- Stars
- 918
- Forks
- 130
- PR merge metrics
- No merged PRs in 30d
Description
You cannot set a nullable json value to null
**To Reproduce**
define a json column in the prisma schema like this:
```prisma
model MyTable {
id String @id @db.Uuid
myColumn Json?
}
```
then build graphql schema and execute the following mutation
```graphql
mutation {
updateMyTable(data: { myColumn: null},
where: {id: "3e48e900-20f3-4cce-899e-f6323525645d"}) {
id
myColumn
}
}
```
**Expected Behavior**
The value should be updated to null
**Logs**
```
[GraphQLError [Object]:
Invalid `helpers_1.getPrismaFromContext)(ctx).myTable.update()` invocation in
/node_modules/@generated/type-graphql/resolvers/crud/MyTable/MyTableCrudResolver.js:69:68
66 }
67 async updateMyTable(ctx, info, args) {
68 const { _count } = (0, helpers_1.transformFields)((0, graphql_fields_1.default)(info));
→ 69 return (0, helpers_1.getPrismaFromContext)(ctx).myTable.update({
where: {
id: '3e48e900-20f3-4cce-899e-f6323525645d'
},
data: {
myColumn: null
~~~~
}
})
Argument myColumn for data.myColumn must not be null. Please use undefined instead.
] {
locations: [ { line: 2, column: 3 } ],
path: [ 'updateMyTable' ],
extensions: {
requestId: '97562b3c-d5ad-4a1d-b944-3fb9f9729e82',
code: 'INTERNAL_SERVER_ERROR'
}
}
```
Package versions:
prisma@3.7.0
typegraphql-prisma@0.18.3
type-graphql@1.1.1
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the mutation against the Prisma schema and inspect the generated update resolver at node_modules/@generated/type-graphql/resolvers/crud/MyTable/MyTableCrudResolver.js:69. Trace how the nullable Json field reaches myTable.update, then verify that executing the mutation stores null without the reported validation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100