-
-
Notifications
You must be signed in to change notification settings - Fork 51
TypeError: Cannot read properties of undefined (reading 'input') #386
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
Comments
Fix works, but then the types don't get generated correctly |
Are your scalars something like this?
|
@Giovanni-Schroevers Thanks for reporting your issue! |
Experiencing the same issue - seems to be erroring on all GraphQL Enums. Also it is not depending on the configuration (I've tried disabling everything else apart from Example Enum: enum Allergen {
MILK
EGGS
PEANUTS
SOY
WHEAT
TREE_NUTS
SHELLFISH
FISH
SESAME
} |
@maoosi I cannot reproduce this error: enum Allergen {
MILK
EGGS
PEANUTS
SOY
WHEAT
TREE_NUTS
SHELLFISH
FISH
SESAME
} then I can generate this code: import { z } from 'zod'
import { Allergen } from '../types'
type Properties<T> = Required<{
[K in keyof T]: z.ZodType<T[K], any, T[K]>;
}>;
type definedNonNullAny = {};
export const isDefinedNonNullAny = (v: any): v is definedNonNullAny => v !== undefined && v !== null;
export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v));
export const AllergenSchema = z.nativeEnum(Allergen); and run I checked w/ ee78cf3 |
Colleague of @Giovanni-Schroevers here. This schema gives me an error: input InputOne {
field: InputNested!
}
input InputNested {
field: String
} If I make InputNested optional, it doesn't anymore. Debugging now. |
@paales mmm, I could generate validation schema w/o errors: import { z } from 'zod'
import { InputNested, InputOne } from '../types'
type Properties<T> = Required<{
[K in keyof T]: z.ZodType<T[K], any, T[K]>;
}>;
type definedNonNullAny = {};
export const isDefinedNonNullAny = (v: any): v is definedNonNullAny => v !== undefined && v !== null;
export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v));
export function InputNestedSchema(): z.ZodObject<Properties<InputNested>> {
return z.object({
field: z.string().nullish()
})
}
export function InputOneSchema(): z.ZodObject<Properties<InputOne>> {
return z.object({
field: z.lazy(() => InputNestedSchema())
})
} Could you give me your configuration? |
Digging in the code it seems related to |
I'm wondering if it's the same as this quickstart. |
Code I'm using to generate
|
@paales It looks to me like you didn't follow the quickstart. I want you to try it once. generates:
path/to/graphql.ts:
plugins:
- typescript
- typescript-validation-schema # specify to use this plugin
config:
# You can put the config for typescript plugin here
# see: https://www.graphql-code-generator.com/plugins/typescript
strictScalars: true
# Overrides built-in ID scalar to both input and output types as string.
# see: https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#scalars
scalars:
ID: string
# You can also write the config for this plugin together
schema: yup # or zod |
If I follow the quickstart guide it works as expected! |
@paales I'm sorry, I didn't read your latest comment, I could reproduce this error 🙏 |
Award for fastest responder in a GitHub issue goes to @Code-Hex! ❤️ |
I just published the latest version as v0.11.0 |
@Code-Hex Thanks! Sadly the issue still persists on my end. Here is a reproduction link: Just run Few notes:
|
@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: I will fix the logic to take this into consideration 🙏 |
I created a new issue #394 |
Awesome, thanks for looking into it! |
It seems to be a problem with nested input types. To fix the issue the following patch seems to be working:
The text was updated successfully, but these errors were encountered: