bugfix: let DjangoConnectionField call its resolver function

that is, the one specified using DjangoConnectionField(..., resolver=some_func)
This commit is contained in:
Florian Zimmermann 2024-07-04 12:24:30 +02:00
parent 886ce5ef03
commit c127aec75b
2 changed files with 48 additions and 1 deletions

View File

@ -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(),

View File

@ -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: