prisma-nestjs-graphql icon indicating copy to clipboard operation
prisma-nestjs-graphql copied to clipboard

feat: support default value for Json type.

Open lightrabbit opened this issue 10 months ago • 1 comments

For the following schema

model Dummy {
  id          String    @id
  /// @FieldType('Types.DummyJsonType')
  /// @PropertyType('Types.DummyJsonType')
  jsonDefault Json      @default("{\"foo\":\"bar\"}")
}

In previous versions, this code with errors would be generated:

@ObjectType()
export class Dummy {
    @Field(() => ID, { nullable: false })
    id!: string;

    @Field(() => Types.DummyJsonType, {nullable:false,defaultValue:'{"foo":"bar"}'})
    //                                                ^Type ‘string’ is not assignable to type ‘DummyJsonType’
    jsonDefault!: Types.DummyJsonType;
}

In this PR, code like this will be generated:

@ObjectType()
export class Dummy {
    @Field(() => ID, { nullable: false })
    id!: string;

    @Field(() => Types.DummyJsonType, { nullable: false, defaultValue: { foo: 'bar' } })
    jsonDefault!: Types.DummyJsonType;
}

lightrabbit avatar Apr 24 '24 08:04 lightrabbit