This commit is contained in:
Jonathan Kim 2019-07-13 11:22:27 +01:00
parent de98fb5812
commit b2cb074777
3 changed files with 78 additions and 1 deletions

View File

@ -111,7 +111,7 @@ class DjangoFilterConnectionField(DjangoConnectionField):
return partial( return partial(
self.connection_resolver, self.connection_resolver,
parent_resolver, parent_resolver,
self.type, self.connection_type,
self.get_manager(), self.get_manager(),
self.max_limit, self.max_limit,
self.enforce_first_or_last, self.enforce_first_or_last,

View File

@ -818,3 +818,38 @@ def test_integer_field_filter_type():
} }
""" """
) )
def test_required_filter_field():
class ReporterType(DjangoObjectType):
class Meta:
model = Reporter
interfaces = (Node,)
filter_fields = ()
class Query(ObjectType):
all_reporters = DjangoFilterConnectionField(ReporterType, required=True)
def resolve_all_reporters(self, info, **args):
return Reporter.objects.all()
Reporter.objects.create(first_name="John", last_name="Doe")
schema = Schema(query=Query)
query = """
query NodeFilteringQuery {
allReporters(first: 1) {
edges {
node {
firstName
}
}
}
}
"""
expected = {"allReporters": {"edges": [{"node": {"firstName": "John"}}]}}
result = schema.execute(query)
assert not result.errors
assert result.data == expected

View File

@ -0,0 +1,42 @@
import pytest
from graphene import ObjectType, Schema
from graphene.relay import Node
from graphene_django import DjangoConnectionField, DjangoObjectType
from graphene_django.tests.models import Article, Pet, Reporter
pytestmark = pytest.mark.django_db
def test_required_connection_field():
class ReporterType(DjangoObjectType):
class Meta:
model = Reporter
interfaces = (Node,)
class Query(ObjectType):
all_reporters = DjangoConnectionField(ReporterType, required=True)
def resolve_all_reporters(self, info, **args):
return Reporter.objects.all()
Reporter.objects.create(first_name="John", last_name="Doe")
schema = Schema(query=Query)
query = """
query NodeFilteringQuery {
allReporters {
edges {
node {
firstName
}
}
}
}
"""
expected = {"allReporters": {"edges": [{"node": {"firstName": "John"}}]}}
result = schema.execute(query)
assert not result.errors
assert result.data == expected