added a test and made the type property better

This commit is contained in:
Tony Angerilli 2016-11-14 23:44:50 -08:00
parent dc6e8f110a
commit 207f4ebb41
2 changed files with 20 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import inspect
from collections import OrderedDict from collections import OrderedDict
from functools import partial from functools import partial
@ -21,7 +23,7 @@ class DjangoFilterConnectionField(DjangoConnectionField):
@property @property
def node_type(self): def node_type(self):
if callable(self._type): if inspect.isfunction(self._type) or inspect.ismethod(self._type):
return self._type() return self._type()
return self._type return self._type

View File

@ -350,3 +350,20 @@ def test_filter_filterset_related_results():
assert not result.errors assert not result.errors
# We should only get two reporters # We should only get two reporters
assert len(result.data['allReporters']['edges']) == 2 assert len(result.data['allReporters']['edges']) == 2
def test_recursive_filter_connection():
class ReporterFilterNode(DjangoObjectType):
child_reporters = DjangoFilterConnectionField(lambda: ReporterFilterNode)
def resolve_child_reporters(self, args, context, info):
return []
class Meta:
model = Reporter
interfaces = (Node, )
class Query(ObjectType):
all_reporters = DjangoFilterConnectionField(ReporterFilterNode)
assert ReporterFilterNode._meta.fields['child_reporters'].node_type == ReporterFilterNode