首页 > 解决方案 > 石墨烯:抽象对象类型和接口之间的区别

问题描述

我无法区分graphene.Interface对象和graphene.ObjectType具有abstract = True元类选项的对象。

例如:

import graphene

class A(graphene.Interface):
    field_y = graphene.Int()
    field_z = graphene.String()

class B(graphene.ObjectType):
    class Meta:
        abstract = True
    field_y = graphene.Int()
    field_z = graphene.String()

class ChildA(graphene.ObjectType):
    class Meta:
        interfaces = (A,)

    field_x = graphene.Float()

class ChildB(B):
    field_x = graphene.Float()

我什么时候会使用一个孩子而不是另一个?我什么时候不使用其中一个?

任何帮助表示赞赏。

标签: pythondjangographqlgraphene-python

解决方案


推荐阅读