@@ -2,70 +2,70 @@ import Foundation
22
33/// The interface to create a "connection" structure in GraphQL output.
44public protocol GraphConnectable {
5- associatedtype Edge
6- var edges : [ Edge ] { get }
7- var pageInfo : GraphPageInfo { get }
5+ associatedtype Edge
6+ var edges : [ Edge ] { get }
7+ var pageInfo : GraphPageInfo { get }
88}
99
1010/// The interface for an "edge" in GraphQL connection output.
1111public protocol GraphEdgeable {
12- associatedtype Node
13- var cursor : Cursor { get }
14- var node : Node { get }
12+ associatedtype Node
13+ var cursor : Cursor { get }
14+ var node : Node { get }
1515}
1616
1717/// A simple connection structure.
1818public struct BasicConnection < Node> : GraphConnectable {
19- public var edges : [ BasicEdge < Node > ]
20- public var pageInfo : GraphPageInfo
21- public init ( edges: [ BasicEdge < Node > ] , pageInfo: GraphPageInfo ) {
22- self . edges = edges
23- self . pageInfo = pageInfo
24- }
19+ public var edges : [ BasicEdge < Node > ]
20+ public var pageInfo : GraphPageInfo
21+ public init ( edges: [ BasicEdge < Node > ] , pageInfo: GraphPageInfo ) {
22+ self . edges = edges
23+ self . pageInfo = pageInfo
24+ }
2525}
2626
2727/// A simple edge structure.
2828public struct BasicEdge < Node> : GraphEdgeable {
29- public var cursor : Cursor
30- public var node : Node
31- public init ( cursor: Cursor , node: Node ) {
32- self . cursor = cursor
33- self . node = node
34- }
29+ public var cursor : Cursor
30+ public var node : Node
31+ public init ( cursor: Cursor , node: Node ) {
32+ self . cursor = cursor
33+ self . node = node
34+ }
3535}
3636
3737extension BasicConnection {
38- /// Build a connection from nodes for any paginatable input.
39- public init (
40- nodes: [ Node ] ,
41- pagination: any GraphPaginatable ,
42- cursor: CursorType
43- ) where Node: GraphCursorable & Sendable {
44- self . init ( nodes: nodes, pagination: pagination. pagination, cursor: cursor)
45- }
46- /// Build a connection from nodes for any forward paginatable input.
47- public init (
48- nodes: [ Node ] ,
49- pagination: any GraphForwardPaginatable ,
50- cursor: CursorType
51- ) where Node: GraphCursorable & Sendable {
52- self . init ( nodes: nodes, pagination: pagination. pagination, cursor: cursor)
53- }
54- /// Build a connection from nodes with optional pagination input.
55- public init (
56- nodes: [ Node ] ,
57- pagination: GraphPagination ? ,
58- cursor: CursorType
59- ) where Node: GraphCursorable & Sendable {
60- let result = EdgeBuilder . build (
61- cursor: cursor,
62- nodes: nodes,
63- pagination: pagination,
64- transform: BasicEdge . init ( cursor: node: )
65- )
66- self . edges = result. edges
67- self . pageInfo = result. pageInfo
68- }
38+ /// Build a connection from nodes for any paginatable input.
39+ public init (
40+ nodes: [ Node ] ,
41+ pagination: any GraphPaginatable ,
42+ cursor: CursorType
43+ ) where Node: GraphCursorable & Sendable {
44+ self . init ( nodes: nodes, pagination: pagination. pagination, cursor: cursor)
45+ }
46+ /// Build a connection from nodes for any forward paginatable input.
47+ public init (
48+ nodes: [ Node ] ,
49+ pagination: any GraphForwardPaginatable ,
50+ cursor: CursorType
51+ ) where Node: GraphCursorable & Sendable {
52+ self . init ( nodes: nodes, pagination: pagination. pagination, cursor: cursor)
53+ }
54+ /// Build a connection from nodes with optional pagination input.
55+ public init (
56+ nodes: [ Node ] ,
57+ pagination: GraphPagination ? ,
58+ cursor: CursorType
59+ ) where Node: GraphCursorable & Sendable {
60+ let result = EdgeBuilder . build (
61+ cursor: cursor,
62+ nodes: nodes,
63+ pagination: pagination,
64+ transform: BasicEdge . init ( cursor: node: )
65+ )
66+ self . edges = result. edges
67+ self . pageInfo = result. pageInfo
68+ }
6969}
7070
7171extension BasicConnection : Codable where Node: Codable { }
0 commit comments