We are currently upgrading from an old version of graphene (0.99) to a new one (2.15). In the old version, we were able to set the value of a field in the query resolver. For example:
class DogType(DjangoObjectType):
selected = graphene.Boolean()
class Meta:
model = Dog
class DogsQuery(graphene.ObjectType):
dogs = graphene.List(DogType)
resolve_dogs(self, info):
top_dogs = Dogs.objects.all()[:10]
return [DogType(d, selected=(i == 0)) for i, d in enumerate(top_dogs)]
This resolver hands back a list of DogTypes, and the first dog in the list has "selected=True" while the others have "selected=False". It resolves successfully.
In newer versions of graphene, this throws an error: "'DogType' object has no attribute 'pk'". I presume this is because newer versions of graphene don't want us to return Types. So I'm just wondering if it is possible to set the graphene field "selected" in the query resolver itself in newer versions of graphene?