mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
make django connection nonnull unless enforce first or last
This commit is contained in:
parent
f76f38ef30
commit
d10a5806ce
|
@ -4,7 +4,7 @@ from django.db.models.query import QuerySet
|
|||
|
||||
from promise import Promise
|
||||
|
||||
from graphene.types import Field, List
|
||||
from graphene.types import Field, List, NonNull
|
||||
from graphene.relay import ConnectionField, PageInfo
|
||||
from graphql_relay.connection.arrayconnection import connection_from_list_slice
|
||||
|
||||
|
@ -41,8 +41,8 @@ class DjangoConnectionField(ConnectionField):
|
|||
super(DjangoConnectionField, self).__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
from .types import DjangoObjectType
|
||||
def connection_type(self):
|
||||
from graphene_django.types import DjangoObjectType
|
||||
|
||||
_type = super(ConnectionField, self).type
|
||||
assert issubclass(
|
||||
|
@ -53,9 +53,15 @@ class DjangoConnectionField(ConnectionField):
|
|||
)
|
||||
return _type._meta.connection
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
if self.enforce_first_or_last:
|
||||
return self.connection_type
|
||||
return NonNull(self.connection_type)
|
||||
|
||||
@property
|
||||
def node_type(self):
|
||||
return self.type._meta.node
|
||||
return self.connection_type._meta.node
|
||||
|
||||
@property
|
||||
def model(self):
|
||||
|
@ -146,7 +152,7 @@ class DjangoConnectionField(ConnectionField):
|
|||
return partial(
|
||||
self.connection_resolver,
|
||||
parent_resolver,
|
||||
self.type,
|
||||
self.connection_type,
|
||||
self.get_manager(),
|
||||
self.max_limit,
|
||||
self.enforce_first_or_last,
|
||||
|
|
|
@ -110,7 +110,7 @@ class DjangoFilterConnectionField(DjangoConnectionField):
|
|||
return partial(
|
||||
self.connection_resolver,
|
||||
parent_resolver,
|
||||
self.type,
|
||||
self.connection_type,
|
||||
self.get_manager(),
|
||||
self.max_limit,
|
||||
self.enforce_first_or_last,
|
||||
|
|
|
@ -233,7 +233,7 @@ def test_should_manytomany_convert_connectionorlist_connection():
|
|||
assert isinstance(graphene_field, graphene.Dynamic)
|
||||
dynamic_field = graphene_field.get_type()
|
||||
assert isinstance(dynamic_field, ConnectionField)
|
||||
assert dynamic_field.type == A._meta.connection
|
||||
assert dynamic_field.connection_type == A._meta.connection
|
||||
|
||||
|
||||
def test_should_manytoone_convert_connectionorlist():
|
||||
|
|
|
@ -638,15 +638,13 @@ def test_should_error_if_last_is_greater_than_max():
|
|||
}
|
||||
"""
|
||||
|
||||
expected = {"allReporters": None}
|
||||
|
||||
result = schema.execute(query)
|
||||
assert len(result.errors) == 1
|
||||
assert str(result.errors[0]) == (
|
||||
"Requesting 101 records on the `allReporters` connection "
|
||||
"exceeds the `last` limit of 100 records."
|
||||
)
|
||||
assert result.data == expected
|
||||
assert result.data == None
|
||||
|
||||
graphene_settings.RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ type Reporter {
|
|||
pets: [Reporter]
|
||||
aChoice: ReporterAChoice!
|
||||
reporterType: ReporterReporterType
|
||||
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
|
||||
articles(before: String, after: String, first: Int, last: Int): ArticleConnection!
|
||||
}
|
||||
|
||||
enum ReporterAChoice {
|
||||
|
|
Loading…
Reference in New Issue
Block a user