Circular dependencies
See original GitHub issuePython is not able to resolve circular dependencies for schemas with recursive types.
e.g
# category_type.py
from .post_type import Post
class Category(graphene.ObjectType):
Post = graphene.List(Post)
# post_type.py
from .category_type import Category
class Post(graphene.ObjectType):
category = graphene.Field(Category)
At runtime, the above fails as the types haven’t yet loaded before being used in field definitions. A better option would be to wrap the field definitions in a lambda to be called at resolve time and after the types have been declared.
e.g
# category_type.py
- from .post_type import Post
class Category(graphene.ObjectType):
- Post = graphene.List(Post)
+ Post = lambda: graphene.List(Post)
+ from .post_type import Post
# post_type.py
- from .category_type import Category
class Post(graphene.ObjectType):
- category = graphene.Field(Category)
+ category = lambda: graphene.Field(Category)
+ from .category_type import Category
cc @Globegitter
Issue Analytics
- State:
- Created 8 years ago
- Comments:19 (4 by maintainers)
Top Results From Across the Web
Circular dependency - Wikipedia
In software engineering, a circular dependency is a relation between two or more modules which either directly or indirectly depend on each other...
Read more >What is a circular dependency and how can I solve it?
A circular dependency is where Project A depends on something in Project B and project B depends on something in Project A. This...
Read more >Circular Dependencies in Spring - Baeldung
But with a circular dependency, Spring cannot decide which of the beans should be created first since they depend on one another. In...
Read more >What is a circular dependency? - CoConstruct
This is the more common and straightforward type of circular dependency. A circular dependency occurs when a task is dependent on itself.
Read more >Exploring how to solve circular dependencies | Pulumi Blog
Therefore, we can't express a circular dependency in this way. The simplest workaround for this error is to get a reference to our...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looking at some unrelated docs here it seems like you can do this:
I just tested it and it works.
Hi @imranolas,
You can achieve this by using String references (ala Django):