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

Add lazy support for potential self-referential types #838

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nickthegroot
Copy link

Fixes #599

Schemas with self-referential types can break the generated code. Take the following example:

type Comment {
   replies: [Comment!]
}

Prior to this PR, this would create a schemas.ts file with

export function CommentSchema(): z.ZodObject<Properties<Comment>> {
  return z.object({
    __typename: z.literal('Comment').optional(),
    replies: z.array(CommentSchema()).nullish()
  })
}
// Uncaught RangeError: Maximum call stack size exceeded

This PR edits the generation code for all validation libraries to use .lazy in this case.

@nickthegroot nickthegroot changed the title 🐛 Fix #599: add lazy support for potential self-referential types Add lazy support for potential self-referential types Oct 3, 2024
Copy link
Owner

@Code-Hex Code-Hex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nickthegroot Thanks for your PR!
Could you add test please 🙏

@btoo
Copy link

btoo commented Dec 8, 2024

@nickthegroot Thanks for your PR! Could you add test please 🙏

@Code-Hex #907

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.

Support for lazy
3 participants