Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support default value for Json type. #212

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lightrabbit
Copy link

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;
}

@unlight unlight self-requested a review May 19, 2024 11:53
@unlight
Copy link
Owner

unlight commented May 19, 2024

tests fails

@unlight unlight marked this pull request as draft May 19, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants