简体   繁体   中英

Graphene AssertionError: Can't find type in schema

I create such schema using 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, )

When I run query against it I got following error:

AssertionError: Can't find type PartTimeEmployee in schema

What do I do wrong here?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM