Skip to content

Input objects support default values #529

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

Merged
merged 3 commits into from
Jan 23, 2024

Conversation

bramvanderholst
Copy link
Contributor

This is a continuation on #398 (& #449). I've added basic support for default values in all 3 schema's.

As stated in the original PR (#398), more complex default values like lists & objects are omitted for now.

Example:

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 Author

@Code-Hex Anything else required to get this merged?

@paales
Copy link
Contributor

paales commented Jan 23, 2024

@Code-Hex Anything we can do to move this forward? 🙂

@Code-Hex
Copy link
Owner

I'm sorry too late I have lost this PR
Let's go

@Code-Hex Code-Hex merged commit 8535755 into Code-Hex:main Jan 23, 2024
@paales
Copy link
Contributor

paales commented Jan 24, 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

Successfully merging this pull request may close these issues.

3 participants