Skip to content

Add maxDepth Option to Handle Circular References in Validation Schema Generation #1039

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

Open
lewisblackburn opened this issue Apr 10, 2025 · 0 comments
Labels
good first issue Good for newcomers

Comments

@lewisblackburn
Copy link

Description:
I'm encountering issues with circular references in my GraphQL schema when using the graphql-codegen-typescript-validation-schema plugin. The generated validation schemas (e.g., for Zod) result in infinite recursion or stack overflow errors due to self-referencing types.

For example, consider the following schema:

type Movie {
  id: ID!
  title: String!
  alternativeTitles: [MovieAlternativeTitle!]!
}

type MovieAlternativeTitle {
  id: ID!
  title: String!
  movie: Movie!
}

In this case, Movie references MovieAlternativeTitle, which in turn references Movie, creating a circular dependency.

To mitigate this, I propose adding a maxDepth configuration option to the plugin. This option would allow users to specify the maximum depth for nested validation schema generation, preventing infinite recursion by limiting how deeply nested schemas are generated.

Proposed Configuration:

generates:
  path/to/validation.ts:
    plugins:
      - typescript-validation-schema
    config:
      schema: zod
      maxDepth: 1

Implementing this feature would enhance the plugin's robustness, especially for schemas with complex relationships, and align it with similar options available in other plugins like typescript-mock-data.

Thank you for considering this enhancement!

@github-actions github-actions bot added the good first issue Good for newcomers label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant