Search code examples
node.jstypescriptexpressgraphqltypegraphql

How to use simple-json with intergers in type-graphql


I tried many different things to use simple-json as a type with integers on entities.

@ObjectType()
@Entity()
export default class PlayerEntity extends BaseEntity {
    @Field(() => Int)
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    @Field()
    username: string;

    @Column({ type: "simple-json" })
    @Field()
    info: Info;
}

and Info would've looked something like

@InputType()
@ObjectType()
export default class Info {
    @Field()
    address: string;

    @Field(() => Int)
    house_number: number;
}

Solution

  • You need to use GraphQL JSON scalar, e.g. the one from graphql-type-json library.