3
3
from graphql_relay .utils import base64
4
4
5
5
from ...types import ObjectType , Schema , String
6
- from ..connection import ConnectionField
6
+ from ..connection import ConnectionField , PageInfo
7
7
from ..node import Node
8
8
9
9
letter_chars = ['A' , 'B' , 'C' , 'D' , 'E' ]
@@ -19,11 +19,26 @@ class Meta:
19
19
20
20
class Query (ObjectType ):
21
21
letters = ConnectionField (Letter )
22
+ connection_letters = ConnectionField (Letter )
23
+
24
+ node = Node .Field ()
22
25
23
26
def resolve_letters (self , args , context , info ):
24
27
return list (letters .values ())
25
28
26
- node = Node .Field ()
29
+ def resolve_connection_letters (self , args , context , info ):
30
+ return Letter .Connection (
31
+ page_info = PageInfo (
32
+ has_next_page = True ,
33
+ has_previous_page = False
34
+ ),
35
+ edges = [
36
+ Letter .Connection .Edge (
37
+ node = Letter (id = 0 , letter = 'A' ),
38
+ cursor = 'a-cursor'
39
+ ),
40
+ ]
41
+ )
27
42
28
43
29
44
schema = Schema (Query )
@@ -176,3 +191,40 @@ def test_returns_all_elements_if_cursors_are_on_the_outside():
176
191
177
192
def test_returns_no_elements_if_cursors_cross ():
178
193
check ('before: "{}" after: "{}"' .format (base64 ('arrayconnection:%s' % 2 ), base64 ('arrayconnection:%s' % 4 )), '' )
194
+
195
+
196
+ def test_connection_type_nodes ():
197
+ result = schema .execute ('''
198
+ {
199
+ connectionLetters {
200
+ edges {
201
+ node {
202
+ id
203
+ letter
204
+ }
205
+ cursor
206
+ }
207
+ pageInfo {
208
+ hasPreviousPage
209
+ hasNextPage
210
+ }
211
+ }
212
+ }
213
+ ''' )
214
+
215
+ assert not result .errors
216
+ assert result .data == {
217
+ 'connectionLetters' : {
218
+ 'edges' : [{
219
+ 'node' : {
220
+ 'id' : 'TGV0dGVyOjA=' ,
221
+ 'letter' : 'A' ,
222
+ },
223
+ 'cursor' : 'a-cursor' ,
224
+ }],
225
+ 'pageInfo' : {
226
+ 'hasPreviousPage' : False ,
227
+ 'hasNextPage' : True ,
228
+ }
229
+ }
230
+ }
0 commit comments