Skip to content

Commit 49eba3b

Browse files
rcarvergithub-actions[bot]
authored andcommitted
Run swift-format
1 parent 2fcdc8a commit 49eba3b

File tree

11 files changed

+1399
-1392
lines changed

11 files changed

+1399
-1392
lines changed

Package.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
import PackageDescription
44

55
let package = Package(
6-
name: "swift-graphql-pagination",
7-
products: [
8-
.library(name: "GraphQLPagination", targets: ["GraphQLPagination"]),
9-
],
10-
dependencies: [
11-
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "1.3.0"),
12-
],
13-
targets: [
14-
.target(
15-
name: "GraphQLPagination",
16-
),
17-
.testTarget(
18-
name: "GraphQLPaginationTests",
19-
dependencies: [
20-
"GraphQLPagination",
21-
.product(name: "CustomDump", package: "swift-custom-dump"),
22-
]
23-
),
24-
]
6+
name: "swift-graphql-pagination",
7+
products: [
8+
.library(name: "GraphQLPagination", targets: ["GraphQLPagination"])
9+
],
10+
dependencies: [
11+
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "1.3.0")
12+
],
13+
targets: [
14+
.target(
15+
name: "GraphQLPagination",
16+
),
17+
.testTarget(
18+
name: "GraphQLPaginationTests",
19+
dependencies: [
20+
"GraphQLPagination",
21+
.product(name: "CustomDump", package: "swift-custom-dump"),
22+
]
23+
),
24+
]
2525
)

Sources/GraphQLPagination/Connection.swift

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,70 @@ import Foundation
22

33
/// The interface to create a "connection" structure in GraphQL output.
44
public 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.
1111
public 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.
1818
public 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.
2828
public 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

3737
extension 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

7171
extension BasicConnection: Codable where Node: Codable {}
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
11
import Foundation
22

33
public struct Cursor: RawRepresentable, Hashable, Sendable {
4-
public var rawValue: String
5-
public init(rawValue: String) {
6-
self.rawValue = rawValue
7-
}
4+
public var rawValue: String
5+
public init(rawValue: String) {
6+
self.rawValue = rawValue
7+
}
88
}
99

1010
extension Cursor: ExpressibleByStringLiteral {
11-
public init(stringLiteral value: String) {
12-
self.rawValue = value
13-
}
11+
public init(stringLiteral value: String) {
12+
self.rawValue = value
13+
}
1414
}
1515

1616
extension Cursor: ExpressibleByIntegerLiteral {
17-
public init(integerLiteral value: Int) {
18-
self.rawValue = String(describing: value)
19-
}
17+
public init(integerLiteral value: Int) {
18+
self.rawValue = String(describing: value)
19+
}
2020
}
2121

2222
extension Cursor {
23-
public init(intValue: Int) {
24-
self.rawValue = String(intValue)
25-
}
26-
public func intValue() -> Int? {
27-
return Int(self.rawValue)
28-
}
23+
public init(intValue: Int) {
24+
self.rawValue = String(intValue)
25+
}
26+
public func intValue() -> Int? {
27+
return Int(self.rawValue)
28+
}
2929
}
3030

3131
extension Cursor: CustomStringConvertible {
32-
public var description: String {
33-
self.rawValue.encodeBase64()
34-
}
32+
public var description: String {
33+
self.rawValue.encodeBase64()
34+
}
3535
}
3636

3737
extension Cursor: Codable {
38-
public func encode(to encoder: Encoder) throws {
39-
var container = encoder.singleValueContainer()
40-
try container.encode(self.rawValue.encodeBase64())
41-
}
42-
public init(from decoder: Decoder) throws {
43-
let container = try decoder.singleValueContainer()
44-
let value = try container.decode(String.self)
45-
guard
46-
let data = Data(base64Encoded: value),
47-
let string = String(data: data, encoding: .utf8)
48-
else {
49-
throw DecodingError.dataCorruptedError(
50-
in: container,
51-
debugDescription: "Cursor was invalid: \(value)"
52-
)
53-
}
54-
self.rawValue = string
38+
public func encode(to encoder: Encoder) throws {
39+
var container = encoder.singleValueContainer()
40+
try container.encode(self.rawValue.encodeBase64())
41+
}
42+
public init(from decoder: Decoder) throws {
43+
let container = try decoder.singleValueContainer()
44+
let value = try container.decode(String.self)
45+
guard
46+
let data = Data(base64Encoded: value),
47+
let string = String(data: data, encoding: .utf8)
48+
else {
49+
throw DecodingError.dataCorruptedError(
50+
in: container,
51+
debugDescription: "Cursor was invalid: \(value)"
52+
)
5553
}
54+
self.rawValue = string
55+
}
5656
}
5757

5858
extension String {
59-
func encodeBase64() -> String {
60-
Data(self.utf8).base64EncodedString()
61-
}
62-
func decodeBase64() -> String? {
63-
guard let data = self.data(using: .utf8) else { return nil }
64-
return String(data: data, encoding: .utf8)
65-
}
59+
func encodeBase64() -> String {
60+
Data(self.utf8).base64EncodedString()
61+
}
62+
func decodeBase64() -> String? {
63+
guard let data = self.data(using: .utf8) else { return nil }
64+
return String(data: data, encoding: .utf8)
65+
}
6666
}

0 commit comments

Comments
 (0)