返回石墨烯中的可迭代查询集
在我的解析器中,我尝试使用通用的车辆ID在行上汇总距离,迫使我在查询上调用value('warter_id')
,从而创建了一个可抛出的QuerySet,以抛出:例外:接收到不兼容的实例“ {'warter_id':x,'sum_distance':y}”
返回GraphQL时。
class AssignmentType(DjangoObjectType):
class Meta:
model = Assignment
sum_distance = graphene.Int()
def resolve_sum_distance(self, info):
return getattr(self, "sum_distance", None)
class Query(graphene.ObjectType):
all_assignments = graphene.List(AssignmentType)
def resolve_all_assignments(self, info, **kwargs):
return Assignment.objects.order_by().values("vehicle_id").\
annotate(sum_distance=Sum("distance", output_field=IntegerField()))
schema = graphene.Schema(query=Query)
Django 4.0.3
Graphene 2.19
从我在类似帖子中看到的答案中,例如这不应该失败吗?
In my resolver, I attempt to aggregate distance driven on rows with a common vehicle id, forcing me to call values('vehicle_id')
on the query and thus creating a iterable queryset which throws:Exception: Received incompatible instance "{'vehicle_id': x, 'sum_distance': y}"
when returned to graphql.
class AssignmentType(DjangoObjectType):
class Meta:
model = Assignment
sum_distance = graphene.Int()
def resolve_sum_distance(self, info):
return getattr(self, "sum_distance", None)
class Query(graphene.ObjectType):
all_assignments = graphene.List(AssignmentType)
def resolve_all_assignments(self, info, **kwargs):
return Assignment.objects.order_by().values("vehicle_id").\
annotate(sum_distance=Sum("distance", output_field=IntegerField()))
schema = graphene.Schema(query=Query)
django 4.0.3
graphene 2.19
From the answers I have seen in similar posts like https://stackoverflow.com/a/51425324/7267684, this should not be failing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一次不确定
Try This Once Not Sure