Skip to content

Commit 0d178b3

Browse files
authored
Merge pull request #609 from acu/fix-connection-field-required
Fix passing required=True to DjangoConnectionField
2 parents 9a43f65 + b49d315 commit 0d178b3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

graphene_django/fields.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from functools import partial
22

33
from django.db.models.query import QuerySet
4+
from graphene import NonNull
45

56
from promise import Promise
67

@@ -45,17 +46,31 @@ def type(self):
4546
from .types import DjangoObjectType
4647

4748
_type = super(ConnectionField, self).type
49+
non_null = False
50+
if isinstance(_type, NonNull):
51+
_type = _type.of_type
52+
non_null = True
4853
assert issubclass(
4954
_type, DjangoObjectType
5055
), "DjangoConnectionField only accepts DjangoObjectType types"
5156
assert _type._meta.connection, "The type {} doesn't have a connection".format(
5257
_type.__name__
5358
)
54-
return _type._meta.connection
59+
connection_type = _type._meta.connection
60+
if non_null:
61+
return NonNull(connection_type)
62+
return connection_type
63+
64+
@property
65+
def connection_type(self):
66+
type = self.type
67+
if isinstance(type, NonNull):
68+
return type.of_type
69+
return type
5570

5671
@property
5772
def node_type(self):
58-
return self.type._meta.node
73+
return self.connection_type._meta.node
5974

6075
@property
6176
def model(self):
@@ -151,7 +166,7 @@ def get_resolver(self, parent_resolver):
151166
return partial(
152167
self.connection_resolver,
153168
parent_resolver,
154-
self.type,
169+
self.connection_type,
155170
self.get_manager(),
156171
self.max_limit,
157172
self.enforce_first_or_last,

0 commit comments

Comments
 (0)