Graphene AssertionError: Can't find type in schema

Graphene AssertionError: Can't find type in schema

我使用 graphene v2.1.8 and looking into this example 创建这样的架构:

class Employee(graphene.Interface):
    employee_id = graphene.ID()
    employee_type = graphene.Field(lambda: EmployeeType)

    @classmethod
    def resolve_type(cls, instance, info):
        if instance.get("employee_type") == EmployeeType.PART_TIME.name:
            return PartTimeEmployee
        return FullTimeEmployee


class PartTimeEmployee(graphene.ObjectType):
    class Meta:
        interfaces = (Employee, )


class FullTimeEmployee(graphene.ObjectType):
    class Meta:
        interfaces = (Employee, )

当我 运行 查询它时,出现以下错误:

AssertionError: Can't find type PartTimeEmployee in schema

我这里做错了什么?

如果类型PartTimeEmployeeFullTimeEmployee不明确提及 在查询 类 中 - 您必须在 Schema 中手动注册类型。

schema = Schema(query=Query, types=[PartTimeEmployee, FullTimeEmployee])