Skip to content

How to use resolve in Graphene Relay Node? #1482

@nnluk1010

Description

@nnluk1010

How can I use resolve in relay.Node.Field?

I have tried to use resolve in DjangoFilterConnectionField(CategoryNode), and it works.

But it does not work when I use the same resolve function in relay.Node.Field(CategoryNode)

This is my code:

#schema.py
class Query(graphene.ObjectType):
    category = relay.Node.Field(CategoryNode)
    all_categories = DjangoFilterConnectionField(CategoryNode)


    def resolve_category(root, info, **kwargs):
        print("###TESTING resolve_category###")

    def resolve_all_categories(self, info, **kwargs):
        print("###TESTING resolve_all_categories###")

When I call the following GraphQL:

query {
  allCategories {
    edges {
      node {
        name
      }
    }
  }
}

The terminal will return ###TESTING resolve_category###

However, if I call the following GraphQL:

query {
  category(id: "Q2F0ZWdvcnlOb2RlOjE=") {
    id
    name
  }
}

The terminal will not return ###TESTING resolve_category###

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions