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?