【NestJS/GraphQL】处理JSON的方法
环境
-
- NestJS 7.0.7
- nestjs/graphql 7.3.7
首先编写代码的方法
安裝
yarn add graphql-type-json
yarn add -D @types/graphql-type-json
设置
import graphqlTypeJson from 'graphql-type-json'
import { Field, ObjectType } from '@nestjs/graphql'
@ObjectType()
export class SomeClass {
@Field(() => graphqlTypeJson, { nullable: true })
json?: object
}
确认
请确认 schemal.gql 文件中已添加以下条目。
type SomeClass {
json: JSON
}
"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSON