Skip to content

Support for InterfaceTypeDefinition #474

Closed
@simonljus

Description

@simonljus

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions