mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 19:43:56 +03:00
Fixed ConnectionField arguments overwritten. Fixed #252
This commit is contained in:
parent
bd207b5f06
commit
c961f0b3c6
|
@ -95,13 +95,13 @@ class Connection(six.with_metaclass(ConnectionMeta, ObjectType)):
|
|||
class IterableConnectionField(Field):
|
||||
|
||||
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__(
|
||||
type,
|
||||
*args,
|
||||
before=String(),
|
||||
after=String(),
|
||||
first=Int(),
|
||||
last=Int(),
|
||||
**kwargs
|
||||
)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
from ...types import AbstractType, Field, List, NonNull, ObjectType, String
|
||||
from ..connection import Connection, PageInfo
|
||||
from ...types import AbstractType, Field, List, NonNull, ObjectType, String, Argument, Int
|
||||
from ..connection import Connection, PageInfo, ConnectionField
|
||||
from ..node import Node
|
||||
|
||||
|
||||
|
@ -109,3 +109,32 @@ def test_pageinfo():
|
|||
assert PageInfo._meta.name == 'PageInfo'
|
||||
fields = PageInfo._meta.fields
|
||||
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),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user