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?
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',
},
]
}
Most helpful comment
You can easily do that with a custom scalar.
For example using the graphql-scalars library:
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