mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-25 11:04:11 +03:00
bugfix: let DjangoConnectionField call its resolver function
that is, the one specified using DjangoConnectionField(..., resolver=some_func)
This commit is contained in:
parent
886ce5ef03
commit
c127aec75b
|
@ -247,7 +247,7 @@ class DjangoConnectionField(ConnectionField):
|
||||||
def wrap_resolve(self, parent_resolver):
|
def wrap_resolve(self, parent_resolver):
|
||||||
return partial(
|
return partial(
|
||||||
self.connection_resolver,
|
self.connection_resolver,
|
||||||
parent_resolver,
|
self.resolver or parent_resolver,
|
||||||
self.connection_type,
|
self.connection_type,
|
||||||
self.get_manager(),
|
self.get_manager(),
|
||||||
self.get_queryset_resolver(),
|
self.get_queryset_resolver(),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import base64
|
import base64
|
||||||
import datetime
|
import datetime
|
||||||
|
from unittest.mock import ANY, Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.db import models
|
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
|
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():
|
def test_should_query_nullable_foreign_key():
|
||||||
class PetType(DjangoObjectType):
|
class PetType(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user