-
-
Notifications
You must be signed in to change notification settings - Fork 60
Description
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: 1Implementing 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!