Skip to content

Input objects support default values #398

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
wants to merge 1 commit into from

Conversation

paales
Copy link
Contributor

@paales paales commented Jun 19, 2023

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()
  })
}

This PR is not complete, but I wanted to start a conversation about supporting this.

To make this a complete PR there needs to happen a few things in my opinion:

  • Decide how to handle more complex default values like lists / objects (can we omit this for now?)
  • How to handle nullish values here, should we keep the 'nullish' here?
  • Implement similar functionality for the other schema's

paales added a commit to graphcommerce-org/graphcommerce that referenced this pull request Jun 19, 2023
@Code-Hex
Copy link
Owner

Code-Hex commented Jun 19, 2023

@paales Thanks for your nice suggestions!

I think we can omit lists / objects for now. But we need to write README about this.

Decide how to handle more complex default values like lists / objects (can we omit this for now?)

What do you mean nullish?
If you mean Null Value, I think we can omit for now (as same as lists / objects)

How to handle nullish values here, should we keep the 'nullish' here?

Yes. this is required.

Implement similar functionality for the other schema's

Please remove d0809b1 commit If you want to work on this PR 🙏

@paales
Copy link
Contributor Author

paales commented Jun 23, 2023

Thanks for the green light on this!

Please remove d0809b1 commit If you want to work on this PR 🙏

This commit isn't in this repository, it is in our repository, just referencing this PR :)

@Code-Hex
Copy link
Owner

@paales I see!

@Code-Hex
Copy link
Owner

@paales What do you have plan (period) to implement for this?

@paales
Copy link
Contributor Author

paales commented Aug 4, 2023

@Code-Hex Uhhmm, I haven't gotten around to it yet. Not sure when I'll be able to get around to it.

@Code-Hex
Copy link
Owner

Code-Hex commented Aug 12, 2023

@paales Thank you for your reply.
It looks like this PR hasn't been updated in a while, so I'll close it for now.

I moved to #449

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.

2 participants