Skip to content

Input objects support default values - #529

Merged
Code-Hex merged 3 commits into
Code-Hex:mainfrom
bramvanderholst:feature/default-input-values
Jan 23, 2024
Merged

Input objects support default values#529
Code-Hex merged 3 commits into
Code-Hex:mainfrom
bramvanderholst:feature/default-input-values

Conversation

@bramvanderholst

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

@paales

paales commented Jan 23, 2024

Copy link
Copy Markdown
Contributor

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

@Code-Hex

Copy link
Copy Markdown
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

paales commented Jan 24, 2024

Copy link
Copy Markdown
Contributor

❤️

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