graphene.List with and without lambda

Created on 28 Apr 2017  路  1Comment  路  Source: graphql-python/graphene

I noticed that one of the examples shows two different ways of creating a List (lines 16 & 17 here):

class Character(graphene.Interface):
    id = graphene.ID()
    name = graphene.String()
    friends = graphene.List(lambda: Character)
    appears_in = graphene.List(Episode)

The documentation shows only without a lambda:

class Character(graphene.ObjectType):
    appears_in = graphene.List(graphene.String)

Are these equivalent? If not when would you use one form or the other?

Thanks!

Most helpful comment

Usually lambdas are used when there is a dependency that only can be resolved lazily.
(for example, a self-reference to the field parent type).

Otherwise, using the non-lambda form is the recommended approach :)

>All comments

Usually lambdas are used when there is a dependency that only can be resolved lazily.
(for example, a self-reference to the field parent type).

Otherwise, using the non-lambda form is the recommended approach :)

Was this page helpful?
0 / 5 - 0 ratings