prisma-nestjs-graphql
prisma-nestjs-graphql copied to clipboard
feat: support default value for Json type.
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;
}