Мы меняем модель следующим образом: Models.py
class ObjectA(models.Model):
...
class ObjectB(models.Model):
propertyB = models.ForeignKey(ObjectA, on_delete=models.CASCADE, related_name='nestedB')
class ObjectC(models.Model):
propertyC = models.ForeignKey(ObjectB, on_delete=models.CASCADE, related_name='nestedC')
@property # new property created
def nestedB_nestedA_id(self):
return self.propertyC.nested_objectB.nested_objectA.id
Мы меняем схему graphql следующим образом: // schema.py
class ObjectCNode(DjangoObjectType):
nestedB_nestedA_id = graphene.Int(source='nestedB_nestedA_id') # as proxy
nestedA_id = graphene.ID() # globalID of ObjectANode we want to get
def resolve_nestedB_nestedA_id(self, info, **kwargs):
return self.nestedB_nestedA_id
def resolve_nestedA_id(self, info, **kwargs):
return relay.Node.to_global_id(ObjectANode._meta.name, self.nestedB_nestedA_id)
И теперь запрос
query {
allObjectC {
id # self ID()
nestedA_id # nested nested ID() we want to get
}
}
Другие предложения?