问题描述
在 sqlAlchemy 中的数据模式级别,所有表都通过关系链接。我有以下 GraphQL 数据架构:
class CategoryGQL(sqlAlchemyObjectType):
class Meta:
proxy = True
description = "Table of category"
model = CategoryModel
interfaces = [relay.Node]
class DOOPGQL(sqlAlchemyObjectType):
class Meta:
proxy = True
description = "Table of DOOP"
model = DOOPModel
interfaces = (relay.Node,)
class DirectionGQL(sqlAlchemyObjectType):
class Meta:
description = "Table of direction"
model = DirectionModel
interfaces = [relay.Node]
class Category_DOOPGQL(sqlAlchemyObjectType):
class Meta:
description = "Category and Doop relationship table"
model = Category_DOOP_Model
interfaces = (relay.Node,)
我也实现了这个解析器。我收到错误:收到不兼容的实例,如果我没有将 lambda 与第一个参数 graphene.List() 一起使用:
class AdvancedSearch(ObjectType):
age = List(graphene.NonNull(graphene.String)) # [Array!]
direction = List(graphene.NonNull(graphene.String)) # [Array!]
ovz = graphene.Boolean()
doops = graphene.List(lambda: graphene.List(DOOPGQL),ovz=ovz,age=age,direction=direction)
def resolve_doops(self,info):
query = db.query(DOOP,Direction,Category,Category_DOOP)
query = query.filter_by(ovz=self.ovz)
query = query.join(Direction,Direction.id_cluster == DOOP.id_cluster)
query = query.filter(Direction.name.in_(self.direction))
query = query.join(Category_DOOP,Category_DOOP.id_doop == DOOP.id)
query = query.join(Category,Category_DOOP.id_category == Category.id)
query = query.filter(Category.age_max.in_(self.age),Category.age_min.in_(self.age))
query = query.all()
return query
我得到了这个答案:
"errors": [
{
"message": "Expected value of type \"DOOPGQL\" but got: Direction.","locations": [
{
"line": 3,"column": 5
}
]
},{
"message": "Expected value of type \"DOOPGQL\" but got: Category.",{
"message": "Expected value of type \"DOOPGQL\" but got: Category_DOOP.","column": 5
}
]
}
]
我该如何解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)