Skip to content

Optional JSON Field Creates An Error Out Of The Box #1857

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

Closed
AlekseiAQ opened this issue Nov 14, 2024 · 3 comments
Closed

Optional JSON Field Creates An Error Out Of The Box #1857

AlekseiAQ opened this issue Nov 14, 2024 · 3 comments
Milestone

Comments

@AlekseiAQ
Copy link

AlekseiAQ commented Nov 14, 2024

Description and expected behavior
Optional json field creates an error out of the box due to a different optional type check.

Screenshots
n/a

Environment (please complete the following information):

  • ZenStack version: 2.8.1
  • Prisma version: "^5.21.1"
  • Database type: Postgresql
  • Zod: "^3.23.8"

Additional context

type JSONContent {
  type String
  text String?
}
Types of property 'contentJSON' are incompatible.
        Type '{ type: string; text?: string | null | undefined; } | null | undefined' is not assignable to type 'JSONContent | null | undefined'.
          Type '{ type: string; text?: string | null | undefined; }' is not assignable to type 'JSONContent'.
            Types of property 'text' are incompatible.
              Type 'string | null | undefined' is not assignable to type 'string | undefined'.
                Type 'null' is not assignable to type 'string | undefined'.ts-plugin(2322)
index-fixed.d.ts(11664, 9): The expected type comes from property 'data' which is declared here on type 'ArticleCreateArgs<DefaultArgs>'
@ymc9 ymc9 added this to the v2.9.0 milestone Nov 14, 2024
@ymc9
Copy link
Member

ymc9 commented Nov 15, 2024

Hi @AlekseiAQ , could you show me your mutation code? It seems in the mutation input the text field can be null (while ZenStack generated field is string | undefined). Is this intentional?

@ymc9
Copy link
Member

ymc9 commented Nov 15, 2024

Thought about it again, we should generate "| null" for the optional field in "type" to be consistent with Prisma. I'll make a fix.

@ymc9
Copy link
Member

ymc9 commented Nov 19, 2024

Fixed in 2.9.0

@ymc9 ymc9 closed this as completed Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants