Skip to content
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

Support for lazy #599

Open
sschneider-ihre-pvs opened this issue Apr 2, 2024 · 2 comments · May be fixed by #838
Open

Support for lazy #599

sschneider-ihre-pvs opened this issue Apr 2, 2024 · 2 comments · May be fixed by #838

Comments

@sschneider-ihre-pvs
Copy link
Contributor

There is a chance that there will be some self referencing group going on which is currently not supported but is possible in Zod for example

This leads to callstack size exceeded

export function GroupSchema {
  return z.object({
    name: z.string(),
    subGroup:  GroupSchema()
  })
}

This does not

export function GroupSchema {
  return z.object({
    name: z.string(),
    subGroup: z.lazy(() => GroupSchema())
  })
}
@Code-Hex
Copy link
Owner

Code-Hex commented Apr 6, 2024

@sschneider-ihre-pvs Thanks!
Yeah, I agree fix this if possible to keep returning type the same as current.

Could you send me PR for this?

@elierotenberg
Copy link

I am interested in providing a fix for this.
I think we must do 2 things:

  1. Use z.lazy. We can try and detect recursive references (by implementing a DFS), or simply use z.lazy everywhere. There isn't really a downside to the latter.
  2. Memoize calls to the schema generating functions (using let xxxSchema: null | ZodType<xxxx> for each function should be enough) so that multiple calls returns the same reference.

I can get started by hacking my way through the generator but any help/advice would be appreciated!

nickthegroot added a commit to nickthegroot/graphql-codegen-typescript-validation-schema that referenced this issue Oct 3, 2024
btoo pushed a commit to btoo/graphql-codegen-typescript-validation-schema that referenced this issue Dec 8, 2024
btoo pushed a commit to btoo/graphql-codegen-typescript-validation-schema that referenced this issue Dec 8, 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
3 participants