Skip to content

Generate invalid schema for zod #19

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
michiomochi opened this issue Feb 28, 2022 · 4 comments · Fixed by #24
Closed

Generate invalid schema for zod #19

michiomochi opened this issue Feb 28, 2022 · 4 comments · Fixed by #24
Labels
good first issue Good for newcomers

Comments

@michiomochi
Copy link

Version

v0.3.0

Reproduce

codegen.yml

schema: ./schema.graphql
documents:
  - ./app/frontend/javascripts/graphql/**/*.graphql
overwrite: true
generates:
  ./app/frontend/javascripts/graphql/generated/zodSchema.tsx:
    plugins:
      - typescript
      - typescript-validation-schema
    config:
      schema: zod
      strictScalars: true
      directives:
        constraint:
          minLength: ['min', "$1", "$1文字以上入力してください"]
          maxLength: ['max', "$1", "$1文字以内で入力してください"]
      scalars:
        Date: string
        DateTime: string
        File: File
        ISO8601DateTime: string
      scalarSchemas:
        File: z.instanceof(File)

schema.graphql

input UserCreateInput {
  profile: String @constraint(minLength: 1, maxLength: 5000)
}

zodSchema.tsx

export function UserCreateInputSchema(): z.ZodSchema<UserCreateInput> {
  return z.object({
    profile: z.string().nullish().min(1, "1文字以上入力してください").max(5000, "5000文字以内で入力してください"),
  })
}

Actual Behavior

TS2339: Property 'min' does not exist on type 'ZodNullable >'. error occur in zodSchema.tsx.

profile: z.string().nullish().min(1, "1文字以上入力してください").max(5000, "5000文字以内で入力してください"),
  })

Expected Behavior

zodSchema.tsx

export function UserCreateInputSchema(): z.ZodSchema<UserCreateInput> {
  return z.object({
    profile: z.string().min(1, "1文字以上入力してください").max(5000, "5000文字以内で入力してください").nullish(),
  })
}
@github-actions github-actions bot added the good first issue Good for newcomers label Feb 28, 2022
@Code-Hex
Copy link
Owner

Code-Hex commented Mar 3, 2022

@michiomochi Sorry for the delay. I was busy.
I will handle it. But I appreciate if you send PR for this.

Thanks

@michiomochi
Copy link
Author

@Code-Hex Thank you for your reply!
OK, I will send PR!

@Code-Hex
Copy link
Owner

Code-Hex commented Mar 9, 2022

@michiomochi Thank you so much!
If you have any questions, please ask me anytime.

Code-Hex added a commit that referenced this issue Mar 27, 2022
Code-Hex added a commit that referenced this issue Mar 27, 2022
@Code-Hex
Copy link
Owner

@michiomochi I'm sorry toooo late.

I fixed this issue at https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/releases/tag/v0.4.1

I'm pleasure if this change helps you. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants