-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String References on Schema produce Attr Error #436
Comments
String references are no longer available. You can achieve the same result with: class A(graphene.ObjectType):
name = graphene.String()
to_b = graphene.Field(lambda: B)
class B(graphene.ObjectType):
name = graphene.String()
to_b = graphene.Field(lambda: B)
class Query(graphene.ObjectType):
get_a = graphene.Field(A)
get_b = graphene.Field(B)
schema = graphene.Schema(query=Query) |
So to confirm, the recommend approach to circular references is to import the referenced (or, related) ObjectType after its needed:
The other alternative I'm aware of is the method you mentioned here using I can't seem to find it, but why was support for string references dropped? Thanks for your help. |
There is also the # mymodule/a.py
class A(graphene.ObjectType):
name = graphene.String()
to_b = graphene.Field(graphene.lazy_import('mymodule.b.B')) # mymodule/b.py
class B(graphene.ObjectType):
name = graphene.String()
to_a = graphene.Field(graphene.lazy_import('mymodule.a.A'))
to_b = graphene.Field(lambda: B) The main reason string references were dropped was because it was non-deterministic. Hope this makes sense! |
Undocumented except in some issues (graphql-python/graphene#110 and graphql-python/graphene#436). The old mechanism worked in Python 3 but not in Python 2.
In this example code, I try to relate objects to each other.
However, I get an
AttributeError
The text was updated successfully, but these errors were encountered: