Nexus: is json field available to be used yet?

Created on 26 Jul 2020  路  1Comment  路  Source: graphql-nexus/nexus

im getting t.json is not a function when i have a json field in my model. how to correctly use json type in nexus/schema?

scopbacking-types typquestion

Most helpful comment

You can easily do that with a custom scalar.
For example using the graphql-scalars library:

import { asNexusMethod } from '@nexus/schema'
import { JSONObjectResolver } from 'graphql-scalars'

export const JSONObject = asNexusMethod(JSONObjectResolver, 'json')

That assumes you import all types in you nexus config.
If you want to have a backing type for an input, then you can also add something like this to your config (not tested):
yarn add type-fest

typegenAutoConfig: {
    backingTypeMap: {
      JSONObject: 'types.JsonObject',
    },
    sources: [
      {
        alias: 'types',
        source: 'type-fest',
      },
    ]
}

>All comments

You can easily do that with a custom scalar.
For example using the graphql-scalars library:

import { asNexusMethod } from '@nexus/schema'
import { JSONObjectResolver } from 'graphql-scalars'

export const JSONObject = asNexusMethod(JSONObjectResolver, 'json')

That assumes you import all types in you nexus config.
If you want to have a backing type for an input, then you can also add something like this to your config (not tested):
yarn add type-fest

typegenAutoConfig: {
    backingTypeMap: {
      JSONObject: 'types.JsonObject',
    },
    sources: [
      {
        alias: 'types',
        source: 'type-fest',
      },
    ]
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

deadcoder0904 picture deadcoder0904  路  3Comments

bizmedia picture bizmedia  路  4Comments

tonyfromundefined picture tonyfromundefined  路  3Comments

israelglar picture israelglar  路  3Comments

santialbo picture santialbo  路  5Comments