Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSONResolver instead of JSONObjectResolver for Json scalar #197

Closed
recidive opened this issue Mar 11, 2022 · 2 comments · Fixed by #231
Closed

Use JSONResolver instead of JSONObjectResolver for Json scalar #197

recidive opened this issue Mar 11, 2022 · 2 comments · Fixed by #231
Labels
type/feat Add a new capability or enhance an existing one

Comments

@recidive
Copy link

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 recidive added the type/feat Add a new capability or enhance an existing one label Mar 11, 2022
@AhmedElywa
Copy link
Contributor

@andrewicarlson it's easy to go with that

@rostislav-simonik-nexus-prisma-admin
Copy link
Collaborator

🎉 This issue has been resolved in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feat Add a new capability or enhance an existing one
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants