Skip to content
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

Support for InterfaceTypeDefinition #474

Open
simonljus opened this issue Sep 8, 2023 · 2 comments
Open

Support for InterfaceTypeDefinition #474

simonljus opened this issue Sep 8, 2023 · 2 comments

Comments

@simonljus
Copy link
Contributor

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)

@Code-Hex
Copy link
Owner

Code-Hex commented Dec 9, 2023

@simonljus Hi 👋
Thanks for made this issue.

Could you give me PR for this fix?

@simonljus
Copy link
Contributor Author

@simonljus Hi 👋 Thanks for made this issue.

Could you give me PR for this fix?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants