1
1
import binascii
2
2
import warnings
3
- from typing import Any , Optional , Sequence
3
+ from typing import Any , List , Optional , Sequence
4
+ from typing_extensions import Protocol
4
5
5
6
from ..utils .base64 import base64 , unbase64
6
7
from .connectiontypes import (
21
22
]
22
23
23
24
25
+ class EdgeType (Protocol ):
26
+ @property
27
+ def node (self ) -> Any : ...
28
+ @property
29
+ def cursor (self ) -> ConnectionCursor : ...
30
+
31
+
32
+ class EdgeConstructor (Protocol ):
33
+ def __call__ (self , * , node : Any , cursor : ConnectionCursor ) -> EdgeType : ...
34
+
35
+
36
+ class PageInfoType (Protocol ):
37
+ @property
38
+ def startCursor (self ) -> Optional [ConnectionCursor ]: ...
39
+ def endCursor (self ) -> Optional [ConnectionCursor ]: ...
40
+ def hasPreviousPage (self ) -> Optional [bool ]: ...
41
+ def hasNextPage (self ) -> Optional [bool ]: ...
42
+
43
+
44
+ class PageInfoConstructor (Protocol ):
45
+ def __call__ (
46
+ self ,
47
+ * ,
48
+ startCursor : Optional [ConnectionCursor ],
49
+ endCursor : Optional [ConnectionCursor ],
50
+ hasPreviousPage : Optional [bool ],
51
+ hasNextPage : Optional [bool ],
52
+ ) -> PageInfoType : ...
53
+
54
+
55
+ class ConnectionType (Protocol ):
56
+ @property
57
+ def edges (self ): List [EdgeType ]: ...
58
+ @property
59
+ def pageInfo (self ): PageInfoType : ...
60
+
61
+
62
+ class ConnectionConstructor (Protocol ):
63
+ def __call__ (
64
+ self ,
65
+ * ,
66
+ edges : List [EdgeType ],
67
+ pageInfo : PageInfoType ,
68
+ ) -> ConnectionType : ...
69
+
70
+
24
71
def connection_from_array (
25
72
data : Sequence ,
26
73
args : ConnectionArguments = None ,
27
- connection_type : Any = Connection ,
28
- edge_type : Any = Edge ,
29
- page_info_type : Any = PageInfo ,
30
- ) -> Connection :
74
+ connection_type : ConnectionConstructor = Connection ,
75
+ edge_type : EdgeConstructor = Edge ,
76
+ page_info_type : PageInfoConstructor = PageInfo ,
77
+ ) -> ConnectionType :
31
78
"""Create a connection object from a sequence of objects.
32
79
33
80
Note that different from its JavaScript counterpart which expects an array,
@@ -54,10 +101,10 @@ def connection_from_array(
54
101
def connection_from_list (
55
102
data : Sequence ,
56
103
args : ConnectionArguments = None ,
57
- connection_type : Any = Connection ,
58
- edge_type : Any = Edge ,
59
- pageinfo_type : Any = PageInfo ,
60
- ) -> Connection :
104
+ connection_type : ConnectionConstructor = Connection ,
105
+ edge_type : EdgeConstructor = Edge ,
106
+ pageinfo_type : PageInfoConstructor = PageInfo ,
107
+ ) -> ConnectionType :
61
108
"""Deprecated alias for connection_from_array.
62
109
63
110
We're now using the JavaScript terminology in Python as well, since list
@@ -84,10 +131,10 @@ def connection_from_array_slice(
84
131
slice_start : int = 0 ,
85
132
array_length : int = None ,
86
133
array_slice_length : int = None ,
87
- connection_type : Any = Connection ,
88
- edge_type : Any = Edge ,
89
- page_info_type : Any = PageInfo ,
90
- ) -> Connection :
134
+ connection_type : ConnectionConstructor = Connection ,
135
+ edge_type : EdgeConstructor = Edge ,
136
+ page_info_type : PageInfoConstructor = PageInfo ,
137
+ ) -> ConnectionType :
91
138
"""Create a connection object from a slice of the result set.
92
139
93
140
Note that different from its JavaScript counterpart which expects an array,
@@ -162,13 +209,13 @@ def connection_from_array_slice(
162
209
def connection_from_list_slice (
163
210
list_slice : Sequence ,
164
211
args : ConnectionArguments = None ,
165
- connection_type : Any = Connection ,
166
- edge_type : Any = Edge ,
167
- pageinfo_type : Any = PageInfo ,
212
+ connection_type : ConnectionConstructor = Connection ,
213
+ edge_type : EdgeConstructor = Edge ,
214
+ pageinfo_type : PageInfoConstructor = PageInfo ,
168
215
slice_start = 0 ,
169
216
list_length = 0 ,
170
217
list_slice_length = None ,
171
- ) -> Connection :
218
+ ) -> ConnectionType :
172
219
"""Deprecated alias for connection_from_array_slice.
173
220
174
221
We're now using the JavaScript terminology in Python as well, since list
0 commit comments