@@ -13,54 +13,82 @@ public extension Connection where Node : Identifiable, Node.ID : LosslessStringC
13
13
cursor. base64Decoded ( ) . flatMap ( { Node . ID ( $0) } )
14
14
}
15
15
16
- static func cursor( _ id : Node . ID ) -> String ? {
17
- id. description. base64Encoded ( )
16
+ static func cursor( _ node : Node ) -> String {
17
+ node . id. description. base64Encoded ( ) !
18
18
}
19
19
}
20
20
21
21
@available ( OSX 10 . 15 , * )
22
22
public extension EventLoopFuture where Value : Sequence , Value. Element : Encodable & Identifiable , Value. Element. ID : LosslessStringConvertible {
23
23
func connection( from arguments: Paginatable ) -> EventLoopFuture < Connection < Value . Element > > {
24
+ connection ( from: arguments, makeCursor: Connection< Value . Element> . cursor)
25
+ }
26
+
27
+ func connection( from arguments: ForwardPaginatable ) -> EventLoopFuture < Connection < Value . Element > > {
28
+ connection ( from: arguments, makeCursor: Connection< Value . Element> . cursor)
29
+ }
30
+
31
+ func connection( from arguments: BackwardPaginatable ) -> EventLoopFuture < Connection < Value . Element > > {
32
+ connection ( from: arguments, makeCursor: Connection< Value . Element> . cursor)
33
+ }
34
+ }
35
+
36
+ public extension EventLoopFuture where Value: Sequence , Value. Element: Encodable {
37
+ func connection( from arguments: Paginatable , makeCursor: @escaping ( Value . Element ) throws -> String ) -> EventLoopFuture < Connection < Value . Element > > {
24
38
flatMapThrowing { value in
25
- try value. connection ( from: arguments)
39
+ try value. connection ( from: arguments, makeCursor : makeCursor )
26
40
}
27
41
}
28
42
29
- func connection( from arguments: ForwardPaginatable ) -> EventLoopFuture < Connection < Value . Element > > {
43
+ func connection( from arguments: ForwardPaginatable , makeCursor : @escaping ( Value . Element ) throws -> String ) -> EventLoopFuture < Connection < Value . Element > > {
30
44
flatMapThrowing { value in
31
- try value. connection ( from: arguments)
45
+ try value. connection ( from: arguments, makeCursor : makeCursor )
32
46
}
33
47
}
34
48
35
- func connection( from arguments: BackwardPaginatable ) -> EventLoopFuture < Connection < Value . Element > > {
49
+ func connection( from arguments: BackwardPaginatable , makeCursor : @escaping ( Value . Element ) throws -> String ) -> EventLoopFuture < Connection < Value . Element > > {
36
50
flatMapThrowing { value in
37
- try value. connection ( from: arguments)
51
+ try value. connection ( from: arguments, makeCursor : makeCursor )
38
52
}
39
53
}
40
54
}
41
55
42
56
@available ( OSX 10 . 15 , * )
43
57
public extension Sequence where Element : Encodable & Identifiable , Element. ID : LosslessStringConvertible {
44
58
func connection( from arguments: Paginatable ) throws -> Connection < Element > {
45
- try connect ( to : Array ( self ) , arguments : PaginationArguments ( arguments ) )
59
+ try connection ( from : arguments , makeCursor : Connection < Element > . cursor )
46
60
}
47
61
48
62
func connection( from arguments: ForwardPaginatable ) throws -> Connection < Element > {
49
- try connect ( to : Array ( self ) , arguments : PaginationArguments ( arguments ) )
63
+ try connection ( from : arguments , makeCursor : Connection < Element > . cursor )
50
64
}
51
65
52
66
func connection( from arguments: BackwardPaginatable ) throws -> Connection < Element > {
53
- try connect ( to: Array ( self ) , arguments: PaginationArguments ( arguments) )
67
+ try connection ( from: arguments, makeCursor: Connection< Element> . cursor)
68
+ }
69
+ }
70
+
71
+ public extension Sequence where Element : Encodable {
72
+ func connection( from arguments: Paginatable , makeCursor: @escaping ( Element ) throws -> String ) throws -> Connection < Element > {
73
+ try connect ( to: Array ( self ) , arguments: PaginationArguments ( arguments) , makeCursor: makeCursor)
74
+ }
75
+
76
+ func connection( from arguments: ForwardPaginatable , makeCursor: @escaping ( Element ) throws -> String ) throws -> Connection < Element > {
77
+ try connect ( to: Array ( self ) , arguments: PaginationArguments ( arguments) , makeCursor: makeCursor)
78
+ }
79
+
80
+ func connection( from arguments: BackwardPaginatable , makeCursor: @escaping ( Element ) throws -> String ) throws -> Connection < Element > {
81
+ try connect ( to: Array ( self ) , arguments: PaginationArguments ( arguments) , makeCursor: makeCursor)
54
82
}
55
83
}
56
84
57
- @available ( OSX 10 . 15 , * )
58
85
func connect< Node> (
59
86
to elements: [ Node ] ,
60
- arguments: PaginationArguments
61
- ) throws -> Connection < Node > where Node : Encodable & Identifiable , Node. ID : LosslessStringConvertible {
62
- let edges = elements. map { element in
63
- Edge < Node > ( node: element, cursor: Connection < Node > . cursor ( element. id) !)
87
+ arguments: PaginationArguments ,
88
+ makeCursor: @escaping ( Node ) throws -> String
89
+ ) throws -> Connection < Node > where Node : Encodable {
90
+ let edges = try elements. map { element in
91
+ Edge < Node > ( node: element, cursor: try makeCursor ( element) )
64
92
}
65
93
66
94
let cursorEdges = slicingCursor ( edges: edges, arguments: arguments)
0 commit comments