Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use graphql-type-json scalar in Nest.js code first appraoch

Tags:

graphql

nestjs

I've npm installed graphql-type-json and the types. How do I use it in a code first approach, where JSONObject is the scalar in the example below.

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**;
}
like image 791
Chris Avatar asked Nov 01 '19 14:11

Chris


1 Answers

I found this method and it worked for me. Might not be the code-first approach but I guess it would suffice until you figure it out :)

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

@ObjectType()
export class YourClass {
  @Field(() => JSON)
  myProperty: any;
}
like image 135
Nine Magics Avatar answered Oct 02 '22 09:10

Nine Magics