nexus-prisma icon indicating copy to clipboard operation
nexus-prisma copied to clipboard

Use JSONResolver instead of JSONObjectResolver for Json scalar

Open recidive opened this issue 2 years ago • 1 comments

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.

recidive avatar Mar 11 '22 19:03 recidive

@andrewicarlson it's easy to go with that

AhmedElywa avatar Aug 03 '22 10:08 AhmedElywa

:tada: This issue has been resolved in version 1.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: