15
15
class MongoengineListField (Field ):
16
16
17
17
def __init__ (self , _type , * args , ** kwargs ):
18
- super (MongoengineListField , self ).__init__ (List (_type ), * args , ** kwargs )
18
+ super (MongoengineListField , self ).__init__ (
19
+ List (_type ), * args , ** kwargs )
19
20
20
21
@property
21
22
def model (self ):
@@ -42,8 +43,10 @@ def __init__(self, type, *args, **kwargs):
42
43
def type (self ):
43
44
from .types import MongoengineObjectType
44
45
_type = super (ConnectionField , self ).type
45
- assert issubclass (_type , MongoengineObjectType ), "MongoengineConnectionField only accepts MongoengineObjectType types"
46
- assert _type ._meta .connection , "The type {} doesn't have a connection" .format (_type .__name__ )
46
+ assert issubclass (
47
+ _type , MongoengineObjectType ), "MongoengineConnectionField only accepts MongoengineObjectType types"
48
+ assert _type ._meta .connection , "The type {} doesn't have a connection" .format (
49
+ _type .__name__ )
47
50
return _type ._meta .connection
48
51
49
52
@property
@@ -68,10 +71,11 @@ def args(self, args):
68
71
def default_filter_args (self ):
69
72
def is_filterable (kv ):
70
73
return hasattr (kv [1 ], '_type' ) \
71
- and callable (getattr (kv [1 ]._type , '_of_type' , None ))
74
+ and callable (getattr (kv [1 ]._type , '_of_type' , None ))
72
75
73
76
return reduce (
74
- lambda r , kv : r .update ({kv [0 ]: kv [1 ]._type ._of_type ()}) or r if is_filterable (kv ) else r ,
77
+ lambda r , kv : r .update (
78
+ {kv [0 ]: kv [1 ]._type ._of_type ()}) or r if is_filterable (kv ) else r ,
75
79
self .fields .items (),
76
80
{}
77
81
)
@@ -96,17 +100,29 @@ def get_query(cls, model, info, **args):
96
100
first = args .pop ('first' , None )
97
101
last = args .pop ('last' , None )
98
102
id = args .pop ('id' , None )
103
+ before = args .pop ('before' , None )
104
+ after = args .pop ('after' , None )
99
105
100
106
if id is not None :
101
107
# https://github.com/graphql-python/graphene/issues/124
102
108
args ['pk' ] = from_global_id (id )[- 1 ]
103
109
104
110
objs = objs .filter (** args )
105
111
112
+ # https://github.com/graphql-python/graphene-mongo/issues/21
113
+ if after is not None :
114
+ _after = from_global_id (after )[- 1 ]
115
+ objs = objs [_after :]
116
+
117
+ if before is not None :
118
+ _before = from_global_id (before )[- 1 ]
119
+ objs = objs [:_before ]
120
+
106
121
if first is not None :
107
122
objs = objs [:first ]
108
123
if last is not None :
109
- objs = objs [:- last ]
124
+ # fix for https://github.com/graphql-python/graphene-mongo/issues/20
125
+ objs = objs [- last :]
110
126
111
127
return objs
112
128
0 commit comments