Skip to content

Commit c961f0b

Browse files
committed
Fixed ConnectionField arguments overwritten. Fixed #252
1 parent bd207b5 commit c961f0b

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

graphene/relay/connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ class Connection(six.with_metaclass(ConnectionMeta, ObjectType)):
9595
class IterableConnectionField(Field):
9696

9797
def __init__(self, type, *args, **kwargs):
98+
kwargs.setdefault('before', String())
99+
kwargs.setdefault('after', String())
100+
kwargs.setdefault('first', Int())
101+
kwargs.setdefault('last', Int())
98102
super(IterableConnectionField, self).__init__(
99103
type,
100104
*args,
101-
before=String(),
102-
after=String(),
103-
first=Int(),
104-
last=Int(),
105105
**kwargs
106106
)
107107

graphene/relay/tests/test_connection.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
from ...types import AbstractType, Field, List, NonNull, ObjectType, String
3-
from ..connection import Connection, PageInfo
2+
from ...types import AbstractType, Field, List, NonNull, ObjectType, String, Argument, Int
3+
from ..connection import Connection, PageInfo, ConnectionField
44
from ..node import Node
55

66

@@ -109,3 +109,32 @@ def test_pageinfo():
109109
assert PageInfo._meta.name == 'PageInfo'
110110
fields = PageInfo._meta.fields
111111
assert list(fields.keys()) == ['has_next_page', 'has_previous_page', 'start_cursor', 'end_cursor']
112+
113+
114+
def test_connectionfield():
115+
class MyObjectConnection(Connection):
116+
class Meta:
117+
node = MyObject
118+
119+
field = ConnectionField(MyObjectConnection)
120+
assert field.args == {
121+
'before': Argument(String),
122+
'after': Argument(String),
123+
'first': Argument(Int),
124+
'last': Argument(Int),
125+
}
126+
127+
128+
def test_connectionfield_custom_args():
129+
class MyObjectConnection(Connection):
130+
class Meta:
131+
node = MyObject
132+
133+
field = ConnectionField(MyObjectConnection, before=String(required=True), extra=String())
134+
assert field.args == {
135+
'before': Argument(NonNull(String)),
136+
'after': Argument(String),
137+
'first': Argument(Int),
138+
'last': Argument(Int),
139+
'extra': Argument(String),
140+
}

0 commit comments

Comments
 (0)