diff --git a/graphene_django/fields.py b/graphene_django/fields.py index 1bbe1f3..9e9f457 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -247,7 +247,7 @@ class DjangoConnectionField(ConnectionField): def wrap_resolve(self, parent_resolver): return partial( self.connection_resolver, - parent_resolver, + self.resolver or parent_resolver, self.connection_type, self.get_manager(), self.get_queryset_resolver(), diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 0e0a31c..85ea145 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -1,5 +1,6 @@ import base64 import datetime +from unittest.mock import ANY, Mock import pytest from django.db import models @@ -2000,6 +2001,52 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects(): assert result.data == expected +def test_connection_should_call_resolver_function(): + resolver_mock = Mock( + name="resolver", + return_value=[ + Reporter(first_name="Some", last_name="One"), + Reporter(first_name="John", last_name="Doe"), + ], + ) + + class ReporterType(DjangoObjectType): + class Meta: + model = Reporter + fields = "__all__" + interfaces = [Node] + + class Query(graphene.ObjectType): + reporters = DjangoConnectionField(ReporterType, resolver=resolver_mock) + + schema = graphene.Schema(query=Query) + result = schema.execute( + """ + query { + reporters { + edges { + node { + firstName + lastName + } + } + } + } + """ + ) + + resolver_mock.assert_called_once_with(None, ANY) + assert not result.errors + assert result.data == { + "reporters": { + "edges": [ + {"node": {"firstName": "Some", "lastName": "One"}}, + {"node": {"firstName": "John", "lastName": "Doe"}}, + ], + }, + } + + def test_should_query_nullable_foreign_key(): class PetType(DjangoObjectType): class Meta: