mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-14 02:02:20 +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 promise import Promise
|
||||||
|
|
||||||
from graphene.types import Field, List
|
from graphene.types import Field, List, NonNull
|
||||||
from graphene.relay import ConnectionField, PageInfo
|
from graphene.relay import ConnectionField, PageInfo
|
||||||
from graphql_relay.connection.arrayconnection import connection_from_list_slice
|
from graphql_relay.connection.arrayconnection import connection_from_list_slice
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ class DjangoConnectionField(ConnectionField):
|
||||||
super(DjangoConnectionField, self).__init__(*args, **kwargs)
|
super(DjangoConnectionField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def connection_type(self):
|
||||||
from .types import DjangoObjectType
|
from graphene_django.types import DjangoObjectType
|
||||||
|
|
||||||
_type = super(ConnectionField, self).type
|
_type = super(ConnectionField, self).type
|
||||||
assert issubclass(
|
assert issubclass(
|
||||||
|
@ -53,9 +53,15 @@ class DjangoConnectionField(ConnectionField):
|
||||||
)
|
)
|
||||||
return _type._meta.connection
|
return _type._meta.connection
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
if self.enforce_first_or_last:
|
||||||
|
return self.connection_type
|
||||||
|
return NonNull(self.connection_type)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def node_type(self):
|
def node_type(self):
|
||||||
return self.type._meta.node
|
return self.connection_type._meta.node
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def model(self):
|
def model(self):
|
||||||
|
@ -146,7 +152,7 @@ class DjangoConnectionField(ConnectionField):
|
||||||
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,
|
||||||
|
|
|
@ -110,7 +110,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,
|
||||||
|
|
|
@ -233,7 +233,7 @@ def test_should_manytomany_convert_connectionorlist_connection():
|
||||||
assert isinstance(graphene_field, graphene.Dynamic)
|
assert isinstance(graphene_field, graphene.Dynamic)
|
||||||
dynamic_field = graphene_field.get_type()
|
dynamic_field = graphene_field.get_type()
|
||||||
assert isinstance(dynamic_field, ConnectionField)
|
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():
|
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)
|
result = schema.execute(query)
|
||||||
assert len(result.errors) == 1
|
assert len(result.errors) == 1
|
||||||
assert str(result.errors[0]) == (
|
assert str(result.errors[0]) == (
|
||||||
"Requesting 101 records on the `allReporters` connection "
|
"Requesting 101 records on the `allReporters` connection "
|
||||||
"exceeds the `last` limit of 100 records."
|
"exceeds the `last` limit of 100 records."
|
||||||
)
|
)
|
||||||
assert result.data == expected
|
assert result.data == None
|
||||||
|
|
||||||
graphene_settings.RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
|
graphene_settings.RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ type Reporter {
|
||||||
pets: [Reporter]
|
pets: [Reporter]
|
||||||
aChoice: ReporterAChoice!
|
aChoice: ReporterAChoice!
|
||||||
reporterType: ReporterReporterType
|
reporterType: ReporterReporterType
|
||||||
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
|
articles(before: String, after: String, first: Int, last: Int): ArticleConnection!
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ReporterAChoice {
|
enum ReporterAChoice {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user