graphql-codegen-typescript-validation-schema: TypeError: Cannot read properties of undefined (reading 'input')
TypeError: Cannot read properties of undefined (reading 'input')
at Visitor.getScalarType (graphcommerce/node_modules/graphql-codegen-typescript-validation-schema/dist/main/visitor.js:30:40)
at generateFieldTypeZodSchema (graphcommerce/node_modules/graphql-codegen-typescript-validation-schema/dist/main/zod/index.js:146:40)
at generateFieldTypeZodSchema (graphcommerce/node_modules/graphql-codegen-typescript-validation-schema/dist/main/zod/index.js:135:21)
at generateFieldTypeZodSchema (graphcommerce/node_modules/graphql-codegen-typescript-validation-schema/dist/main/zod/index.js:126:21)
at generateFieldTypeZodSchema (graphcommerce/node_modules/graphql-codegen-typescript-validation-schema/dist/main/zod/index.js:135:21)
at generateFieldZodSchema (graphcommerce/node_modules/graphql-codegen-typescript-validation-schema/dist/main/zod/index.js:121:17)
at graphcommerce/node_modules/graphql-codegen-typescript-validation-schema/dist/main/zod/index.js:46:103
at Array.map (<anonymous>)
at Object.leave (graphcommerce/node_modules/graphql-codegen-typescript-validation-schema/dist/main/zod/index.js:46:90)
at visit (graphcommerce/node_modules/graphql/language/visitor.js:197:21) {
source: '../../packagesDev/next-config/src/generated/config.ts'
It seems to be a problem with nested input types. To fix the issue the following patch seems to be working:
diff --git a/node_modules/graphql-codegen-typescript-validation-schema/dist/main/visitor.js b/node_modules/graphql-codegen-typescript-validation-schema/dist/main/visitor.js
index 82da858..f2088f0 100644
--- a/node_modules/graphql-codegen-typescript-validation-schema/dist/main/visitor.js
+++ b/node_modules/graphql-codegen-typescript-validation-schema/dist/main/visitor.js
@@ -26,6 +26,9 @@ class Visitor extends typescript_1.TsVisitor {
if (this.scalarDirection === 'both') {
return null;
}
+ if (!this.scalars[scalarName]) {
+ return null;
+ }
return this.scalars[scalarName][this.scalarDirection];
}
}
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 19 (14 by maintainers)
Award for fastest responder in a GitHub issue goes to @Code-Hex! ❤️
Awesome, thanks for looking into it!
I created a new issue https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/issues/394 Close this issue one.
@maoosi I understand why this is happening.
The generation logic relied on the schema passed from graphql-codegen. If this was a schema generated based on introspection, the astNode information was lost, so it seems that it was not possible to determine whether each schema was an enum or a scalar.
This issue was reported here:
https://github.com/graphql/graphql-js/issues/1575
I will fix the logic to take this into consideration 🙏
@Code-Hex Thanks! Sadly the issue still persists on my end.
Here is a reproduction link: https://codesandbox.io/p/sandbox/mystifying-thompson-z2h8m9?welcome=true
Just run
pnpm run gento see the error: ✖ Cannot read properties of undefined (reading ‘input’)Few notes:
http://127.0.0.1:4444/graphql.schema.graphqlfile.@paales I’m sorry, I didn’t read your latest comment, I could reproduce this error 🙏 I will fix it ASAP
Colleague of @Giovanni-Schroevers here.
This schema gives me an error:
If I make InputNested optional, it doesn’t anymore. Debugging now.