In my structure I would like to introduce circular dependency like below to avoid submiting two separate queries to backend. Can someone advise how this can be done in Python.
Below is the sample code:
parent.py
import graphene
class Parent(graphene.ObjectType):
id = graphene.ID()
name = graphene.String()
child= graphene.Field(Child)
child.py
import graphene
class Child(graphene.ObjectType):
id = graphene.ID()
name = graphene.String()
parent = graphene.Field(Parent)
test.py
from parent import Parent
print("TEST")
Error
ImportError: cannot import name 'Parent' from partially initialized module 'parent' (most likely due to a circular import)
Update The following also doesn't work (circular import error)
import graphene
class Child(graphene.ObjectType):
import app.parent as P
id = graphene.ID()
name = graphene.String()
parent = graphene.Field(P.Parent)
...
import graphene
class Parent(graphene.ObjectType):
import app.child as C
id = graphene.ID()
name = graphene.String()
child = graphene.Field(C.Child)
...
from app.parent import Parent
print("TEST")
AttributeError: partially initialized module 'app.parent' has no attribute 'Parent' (most likely due to a circular import)