Python 如何将graphene解析方法移动到不同的文件?

Python 如何将graphene解析方法移动到不同的文件?,python,graphql,graphene-python,Python,Graphql,Graphene Python,我有以下代码。查询是我的根模式。 若我只有一个profile,那个么在查询中使用resolve方法是可以的。但若模式太大怎么办? 是否仍要在配置文件对象类型内移动解析\u profile 导入石墨烯 类查询(graphene.ObjectType): profile=graphene.ObjectType(profile) def解析_配置文件(自身): 返回。。。 类配置文件(graphene.ObjectType): firstName=graphene.String(graphene.St

我有以下代码。查询是我的根模式。 若我只有一个
profile
,那个么在查询中使用resolve方法是可以的。但若模式太大怎么办? 是否仍要在配置文件对象类型内移动
解析\u profile

导入石墨烯
类查询(graphene.ObjectType):
profile=graphene.ObjectType(profile)
def解析_配置文件(自身):
返回。。。
类配置文件(graphene.ObjectType):
firstName=graphene.String(graphene.String)
lastName=graphene.String(graphene.String)

不,您不能将
解析_profile
移动到
profile
中,但有另一种技术可以处理大型架构。您可以将查询拆分为多个文件,并在
query
中继承每个文件。在本例中,我将
Query
分为
AQuery
BQuery
CQuery

class Query(AQuery, BQuery, CQuery, graphene.ObjectType):
   pass
然后您可以在不同的文件中定义
AQuery
,如下所示:

class AQuery(graphene.ObjectType):
    profile = graphene.ObjectType(Profile)

    def resolve_profile(self):
         return ...
并将其他代码放入
BQuery
CQuery


您也可以使用相同的技术来分割突变。

我不熟悉graphene,但我认为在定义模式时,查询也会被视为任何其他对象类型,因此每个字段的类型本身都应该有自己的解析器