When using Nexus, what's the equivalent to stringA...
# orm-help
s
When using Nexus, what's the equivalent to stringArg() for JSON? I can't find jsonArg() ...
I can of course just use stringArg() and then JSON.parse before I pass the data to Prisma, but as the
scalar Json
actually shows up in my Nexus generated schema, I assume there's a better way?
r
Hey @Sascha 👋 You would need to use something like this:
Copy code
field: arg({ type: 'Json' })
s
Works like a charm, cheers.
💯 1
m
Hello @Ryan @Sascha I tried to do it but doesn’t work, where do I need to put field: arg(…) ? Thanks 🙂
r
You would need to add to the
args
option like this:
Copy code
t.field('someField', {
      type: 'ModelType',
      args: {
        field: arg({ type: 'Json' }),
      },
      async resolve(_root, args, ctx) {
        // resolver
      },
    })
If the
Json
scalar is not present in your
schema.graphql
then you can add it as follows:
Copy code
const Json = scalarType({
  name: 'Json',
  asNexusMethod: 'json',
  description: 'Json custom scalar type',
  parseValue(value) {
    return JSON.stringify(value)
  },
  serialize(value) {
    return JSON.parse(value)
  },
})