Skip to content

Input objects support default values #449

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
Code-Hex opened this issue Aug 12, 2023 · 4 comments
Closed

Input objects support default values #449

Code-Hex opened this issue Aug 12, 2023 · 4 comments

Comments

@Code-Hex
Copy link
Owner

Code-Hex commented Aug 12, 2023

#398

Input objects support default values and we'd like to get this supported in the generated schema: http://spec.graphql.org/June2018/#sec-Input-Objects

enum PageType {
  PUBLIC
  BASIC_AUTH
}
input PageInput {
  pageType: PageType! = PUBLIC
  greeting: String = "Hello"
  score: Int = 100
  ratio: Float = 0.5
  isMember: Boolean = true
}

Should be able to generate the following:

export const PageTypeSchema = z.nativeEnum(PageType);

export function PageInputSchema(): z.ZodObject<Properties<PageInput>> {
  return z.object({
    pageType: PageTypeSchema.default("PUBLIC"),
    greeting: z.string().default("Hello").nullish(),
    score: z.number().default(100).nullish(),
    ratio: z.number().default(0.5).nullish(),
    isMember: z.boolean().default(true).nullish()
  })
}
@bramvanderholst
Copy link
Contributor

@Code-Hex I'm looking to pick this up where the original PR left off.
If I implement the other 2 schema's, will this be ready to be merged or are other changes required?

@Code-Hex
Copy link
Owner Author

Code-Hex commented Dec 9, 2023

@bramvanderholst I can merge the PR if you implement the other schema's.

If I implement the other 2 schema's, will this be ready to be merged or are other changes required?

@bramvanderholst
Copy link
Contributor

@Code-Hex Done 🙂 #529

@paales
Copy link
Contributor

paales commented Feb 19, 2024

@Code-Hex Can we get a release please :)

@Code-Hex Code-Hex closed this as completed Apr 6, 2024
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

No branches or pull requests

3 participants