Skip to content

Commit 8beadc7

Browse files
author
Alexandre Kirszenberg
committed
Correctly propagate NonNull to inner connection type
1 parent 3d493c3 commit 8beadc7

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

graphene_django/fields.py

Lines changed: 27 additions & 12 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):
@@ -103,15 +118,15 @@ def resolve_connection(cls, connection, default_manager, args, iterable):
103118

104119
@classmethod
105120
def connection_resolver(
106-
cls,
107-
resolver,
108-
connection,
109-
default_manager,
110-
max_limit,
111-
enforce_first_or_last,
112-
root,
113-
info,
114-
**args
121+
cls,
122+
resolver,
123+
connection,
124+
default_manager,
125+
max_limit,
126+
enforce_first_or_last,
127+
root,
128+
info,
129+
**args
115130
):
116131
first = args.get("first")
117132
last = args.get("last")
@@ -146,7 +161,7 @@ def get_resolver(self, parent_resolver):
146161
return partial(
147162
self.connection_resolver,
148163
parent_resolver,
149-
self.type,
164+
self.connection_type,
150165
self.get_manager(),
151166
self.max_limit,
152167
self.enforce_first_or_last,

0 commit comments

Comments
 (0)