Skip to content

Resolve lambda fields at runtime#111

Closed
imranolas wants to merge 1 commit intographql-python:masterfrom
imranolas:lambda-fields
Closed

Resolve lambda fields at runtime#111
imranolas wants to merge 1 commit intographql-python:masterfrom
imranolas:lambda-fields

Conversation

@imranolas
Copy link
Copy Markdown

Resolves #110

The following is now also valid and allow for circular dependencies to be resolved at runtime.

# category_type.py
class Category(graphene.ObjectType):
Post = graphene.List(lambda: Post)

from .post_type import Post

# post_type.py
class Post(graphene.ObjectType):
category = graphene.Field(lambda: Category)

from .category_type import Category

@syrusakbary
Copy link
Copy Markdown
Member

Hi @imranolas,

You can actually do this if you don't want to use string references.

class Category(graphene.ObjectType):
    Post = graphene.List(graphene.LazyType(lambda _: Post))

from .post_type import Post

# post_type.py
class Post(graphene.ObjectType):
    category = graphene.LazyType(lambda _: Category)

Sorry it's not documented anywhere (Docs will be improved soon too!)

@imranolas
Copy link
Copy Markdown
Author

@syrusakbary: This is exactly what I was looking for. Thanks

@imranolas imranolas closed this Feb 9, 2016
@xikxp1
Copy link
Copy Markdown

xikxp1 commented Nov 29, 2017

What is the status of it now? I don't see LazyType wrapper in graphene implementation now. Should I use lazy_import?

@djmaze
Copy link
Copy Markdown

djmaze commented Jul 17, 2019

Seems it has been removed again?!

@djmaze
Copy link
Copy Markdown

djmaze commented Jul 17, 2019

The currently working method is using string references: #110 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Circular dependencies

4 participants