我如何在 Nest.js 代码中首先使用 graphql-type-json 标量

Chr*_*ris 5 graphql nestjs

我已经 npm 安装了 graphql-type-json 和类型。我如何在代码优先的方法中使用它,其中 JSONObject 是下面示例中的标量。

import {Field, Int, InputType} from 'type-graphql';
import {Direction, MessageType} from '../interfaces/message.interface';

@InputType()
export class MessageInput {
    @Field()
    readonly to: string;

    @Field()
    readonly type: MessageType;

    @Field()
    readonly direction: Direction;

    @Field()
    readonly body: **JSONObject**;
}
Run Code Online (Sandbox Code Playgroud)

Nin*_*ics 6

我找到了这个方法,它对我有用。可能不是代码优先的方法,但我想在你弄清楚之前它就足够了:)

import { Field, ObjectType } from 'type-graphql';
import JSON from 'graphql-type-json';

@ObjectType()
export class YourClass {
  @Field(() => JSON)
  myProperty: any;
}
Run Code Online (Sandbox Code Playgroud)