11import binascii
22import warnings
3- from typing import Any , Optional , Sequence
3+ from typing import Any , List , Optional , Sequence
4+ from typing_extensions import Protocol
45
56from ..utils .base64 import base64 , unbase64
67from .connectiontypes import (
2122]
2223
2324
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+
2471def connection_from_array (
2572 data : Sequence ,
2673 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 :
3178 """Create a connection object from a sequence of objects.
3279
3380 Note that different from its JavaScript counterpart which expects an array,
@@ -54,10 +101,10 @@ def connection_from_array(
54101def connection_from_list (
55102 data : Sequence ,
56103 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 :
61108 """Deprecated alias for connection_from_array.
62109
63110 We're now using the JavaScript terminology in Python as well, since list
@@ -84,10 +131,10 @@ def connection_from_array_slice(
84131 slice_start : int = 0 ,
85132 array_length : int = None ,
86133 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 :
91138 """Create a connection object from a slice of the result set.
92139
93140 Note that different from its JavaScript counterpart which expects an array,
@@ -162,13 +209,13 @@ def connection_from_array_slice(
162209def connection_from_list_slice (
163210 list_slice : Sequence ,
164211 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 ,
168215 slice_start = 0 ,
169216 list_length = 0 ,
170217 list_slice_length = None ,
171- ) -> Connection :
218+ ) -> ConnectionType :
172219 """Deprecated alias for connection_from_array_slice.
173220
174221 We're now using the JavaScript terminology in Python as well, since list
0 commit comments