Fixed ConnectionField arguments overwritten. Fixed #252

This commit is contained in:
Syrus Akbary 2016-10-01 11:52:31 -07:00
parent bd207b5f06
commit c961f0b3c6
2 changed files with 35 additions and 6 deletions

View File

@ -95,13 +95,13 @@ class Connection(six.with_metaclass(ConnectionMeta, ObjectType)):
class IterableConnectionField(Field): class IterableConnectionField(Field):
def __init__(self, type, *args, **kwargs): def __init__(self, type, *args, **kwargs):
kwargs.setdefault('before', String())
kwargs.setdefault('after', String())
kwargs.setdefault('first', Int())
kwargs.setdefault('last', Int())
super(IterableConnectionField, self).__init__( super(IterableConnectionField, self).__init__(
type, type,
*args, *args,
before=String(),
after=String(),
first=Int(),
last=Int(),
**kwargs **kwargs
) )

View File

@ -1,6 +1,6 @@
from ...types import AbstractType, Field, List, NonNull, ObjectType, String from ...types import AbstractType, Field, List, NonNull, ObjectType, String, Argument, Int
from ..connection import Connection, PageInfo from ..connection import Connection, PageInfo, ConnectionField
from ..node import Node from ..node import Node
@ -109,3 +109,32 @@ def test_pageinfo():
assert PageInfo._meta.name == 'PageInfo' assert PageInfo._meta.name == 'PageInfo'
fields = PageInfo._meta.fields fields = PageInfo._meta.fields
assert list(fields.keys()) == ['has_next_page', 'has_previous_page', 'start_cursor', 'end_cursor'] assert list(fields.keys()) == ['has_next_page', 'has_previous_page', 'start_cursor', 'end_cursor']
def test_connectionfield():
class MyObjectConnection(Connection):
class Meta:
node = MyObject
field = ConnectionField(MyObjectConnection)
assert field.args == {
'before': Argument(String),
'after': Argument(String),
'first': Argument(Int),
'last': Argument(Int),
}
def test_connectionfield_custom_args():
class MyObjectConnection(Connection):
class Meta:
node = MyObject
field = ConnectionField(MyObjectConnection, before=String(required=True), extra=String())
assert field.args == {
'before': Argument(NonNull(String)),
'after': Argument(String),
'first': Argument(Int),
'last': Argument(Int),
'extra': Argument(String),
}