Code-Hex/graphql-codegen-typescript-validation-schema

Support for InterfaceTypeDefinition

simonljus opened this issue · 2 comments

Description

If a type has a property of an interface (InterfaceTypeDefinition), the Zod (have not tried others) schema generation will fail.

interface Animal {
}
type Dog implements Animal {
}

type Cat implements Animal {
}

type Something {
animal: Animal
}

Workaround

The current workaround is adding the interface as a scalar

scalarSchemas:
    Animal: z.unknown()

Another workaround is modifying the GQL schema (not preferred):

  • Animal being a superclass
  • Using unions of all the Animal types instead.

Suggestion

Same logic as ZodSchemaVisitor.ObjectTypeDefinition but remove the addition of __typename (since an interface has no typename)

@simonljus Hi 👋
Thanks for made this issue.

Could you give me PR for this fix?

@simonljus Hi 👋 Thanks for made this issue.

Could you give me PR for this fix?

Hi Code-Hex
Yes I will try, see #530