Skip to content

How to unit test a resolver without creating a Query #531

Description

@BossGrand

I have this node

class ConversationNode(DjangoObjectType):

    unread_count = graphene.Int()

    def resolve_unread_count(self, info):
        comments = self.comments_set.all()
        unread_count = # logic for determing unread status
        return unread_count

and I want to run a test like this

def test_unread_count(create_mock_info, create_converstaion):
    mock_info = create_mock_info()
    conversation = create_converstaion()

    conversation_node = ConversationNode(conversation)
 
    assert conversation_node.resolve_unread_count(mock_info) == 3

but self is refering to the node and not the model,

so I get this error

E       AttributeError: 'NoneType' object has no attribute 'all'

how do I run resolvers but have self refer to the model instead of the node?

Edit

Interestingly self.id refers to the model in the resolver

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions