nexus-prisma
nexus-prisma copied to clipboard
Use JSONResolver instead of JSONObjectResolver for Json scalar
Perceived Problem
The Json
scalar was added in the pull request [#9] but it uses the JSONObjectResolver
from graphql-scalars
which only support JSON objects. This is a problem because databases JSON datatypes, such as of Postgres, allow other types of serializable JSON data such as arrays, strings, etc. And if the value in a JSON column doesn't represent a JSON object prisma will crash.
Ideas / Proposed Solution(s)
To work around this, I had to override the Json scalar to use JSONResolver
like this:
import { GraphQLScalarType } from 'graphql'
import { JSONResolver } from 'graphql-scalars'
// Overrides Json scalar to use JSONResolver instead of JSONObjectResolver
// which doesn't support arrays and other JSON serializable values.
NexusPrismaScalars.Json = new GraphQLScalarType({
...JSONResolver,
name: 'Json',
})
The sollution would be changing the Json
scalar provided by nexus-prisma
to use JSONResolver
instead of JSONObjectResolver
.
I believe making this change will be backwards compatible since JSONResolver
also support objects.
@andrewicarlson it's easy to go with that
:tada: This issue has been resolved in version 1.0.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: