Skip to content

Commit dfbefc2

Browse files
Merge pull request #116 from NeedleInAJayStack/fix/swiftformat
chore: Adjusts format CI to use docker
2 parents b4942cf + 5063688 commit dfbefc2

File tree

24 files changed

+367
-299
lines changed

24 files changed

+367
-299
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ jobs:
1414
name: Format linting
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
18-
- uses: swift-actions/setup-swift@v1
19-
- name: GitHub Action for SwiftFormat
20-
uses: CassiusPacheco/[email protected]
21-
with:
22-
swiftformat-version: '0.49.11'
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v2
21+
- name: Pull formatting docker image
22+
run: docker pull ghcr.io/nicklockwood/swiftformat:latest
23+
- name: Run format linting
24+
run: docker run --rm -v ${{ github.workspace }}:/repo ghcr.io/nicklockwood/swiftformat:latest /repo --lint
2325

2426
# Disabled until https://github.com/paulofaria/test-reporter is updated to Swift 5.4
2527
macos:

Sources/Graphiti/API/API.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ public extension API {
3434
on eventLoopGroup: EventLoopGroup,
3535
validationRules: [(ValidationContext) -> Visitor] = []
3636
) -> EventLoopFuture<GraphQLResult> {
37-
return execute(request: request.query,
38-
context: context,
39-
on: eventLoopGroup,
40-
variables: request.variables,
41-
operationName: request.operationName,
42-
validationRules: validationRules
37+
return execute(
38+
request: request.query,
39+
context: context,
40+
on: eventLoopGroup,
41+
variables: request.variables,
42+
operationName: request.operationName,
43+
validationRules: validationRules
4344
)
4445
}
4546

Sources/Graphiti/Argument/Argument.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ public class Argument<ArgumentsType: Decodable, ArgumentType>: ArgumentComponent
88
typeProvider: TypeProvider,
99
coders: Coders
1010
) throws -> (String, GraphQLArgument) {
11-
let argument = GraphQLArgument(
12-
type: try typeProvider.getInputType(from: ArgumentType.self, field: name),
11+
let argument = try GraphQLArgument(
12+
type: typeProvider.getInputType(from: ArgumentType.self, field: name),
1313
description: description,
14-
defaultValue: try defaultValue.map { try coders.encoder.encode($0) }
14+
defaultValue: defaultValue.map { try coders.encoder.encode($0) }
1515
)
1616

1717
return (name, argument)

Sources/Graphiti/Connection/Connection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func connect<Node>(
122122
makeCursor: @escaping (Node) throws -> String
123123
) throws -> Connection<Node> where Node: Encodable {
124124
let edges = try elements.map { element in
125+
// swiftformat:disable:next hoistTry
125126
Edge<Node>(node: element, cursor: try makeCursor(element))
126127
}
127128

Sources/Graphiti/Enum/Enum.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public final class Enum<
1515
name: name,
1616
description: description,
1717
values: values.reduce(into: [:]) { result, value in
18-
result[value.value.rawValue] = GraphQLEnumValue(
19-
value: try MapEncoder().encode(value.value),
18+
result[value.value.rawValue] = try GraphQLEnumValue(
19+
value: MapEncoder().encode(value.value),
2020
description: value.description,
2121
deprecationReason: value.deprecationReason
2222
)

Sources/Graphiti/Federation/Any.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import GraphQL
33
let anyType = try! GraphQLScalarType(
44
name: "_Any",
55
description: "Scalar representing the JSON form of any type. A __typename field is required.",
6-
serialize: { try map(from: $0) } ,
6+
serialize: { try map(from: $0) },
77
parseValue: { $0 },
88
parseLiteral: { ast in
9-
return ast.map
9+
ast.map
1010
}
1111
)

Sources/Graphiti/Federation/Key/Key.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import GraphQL
22
import NIO
33

4-
public class Key<ObjectType, Resolver, Context, Arguments: Codable>: KeyComponent<ObjectType, Resolver, Context> {
4+
public class Key<ObjectType, Resolver, Context, Arguments: Codable>: KeyComponent<
5+
ObjectType,
6+
Resolver,
7+
Context
8+
> {
59
let arguments: [ArgumentComponent<Arguments>]
610
let resolve: AsyncResolve<Resolver, Context, Arguments, ObjectType?>
7-
11+
812
override func mapMatchesArguments(_ map: Map, coders: Coders) -> Bool {
913
let args = try? coders.decoder.decode(Arguments.self, from: map)
1014
return args != nil
1115
}
12-
16+
1317
override func resolveMap(
1418
resolver: Resolver,
1519
context: Context,
@@ -18,10 +22,14 @@ public class Key<ObjectType, Resolver, Context, Arguments: Codable>: KeyComponen
1822
coders: Coders
1923
) throws -> EventLoopFuture<Any?> {
2024
let arguments = try coders.decoder.decode(Arguments.self, from: map)
21-
return try self.resolve(resolver)(context, arguments, eventLoopGroup).map { $0 as Any? }
25+
return try resolve(resolver)(context, arguments, eventLoopGroup).map { $0 as Any? }
2226
}
23-
24-
override func validate(againstFields fieldNames: [String], typeProvider: TypeProvider, coders: Coders) throws {
27+
28+
override func validate(
29+
againstFields fieldNames: [String],
30+
typeProvider: TypeProvider,
31+
coders: Coders
32+
) throws {
2533
// Ensure that every argument is included in the provided field list
2634
for (name, _) in try arguments(typeProvider: typeProvider, coders: coders) {
2735
if !fieldNames.contains(name) {
@@ -46,7 +54,7 @@ public class Key<ObjectType, Resolver, Context, Arguments: Codable>: KeyComponen
4654
asyncResolve: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>
4755
) {
4856
self.arguments = arguments
49-
self.resolve = asyncResolve
57+
resolve = asyncResolve
5058
}
5159

5260
convenience init(

Sources/Graphiti/Federation/Key/KeyComponent.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@ import GraphQL
22
import NIO
33

44
public class KeyComponent<ObjectType, Resolver, Context> {
5-
func mapMatchesArguments(_ map: Map, coders: Coders) -> Bool {
5+
func mapMatchesArguments(_: Map, coders _: Coders) -> Bool {
66
fatalError()
77
}
8-
8+
99
func resolveMap(
10-
resolver: Resolver,
11-
context: Context,
12-
map: Map,
13-
eventLoopGroup: EventLoopGroup,
14-
coders: Coders
10+
resolver _: Resolver,
11+
context _: Context,
12+
map _: Map,
13+
eventLoopGroup _: EventLoopGroup,
14+
coders _: Coders
1515
) throws -> EventLoopFuture<Any?> {
1616
fatalError()
1717
}
18-
19-
func validate(againstFields fieldNames: [String], typeProvider: TypeProvider, coders: Coders) throws {
18+
19+
func validate(
20+
againstFields _: [String],
21+
typeProvider _: TypeProvider,
22+
coders _: Coders
23+
) throws {
2024
fatalError()
2125
}
2226
}
Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import GraphQL
22

3-
extension Type {
4-
3+
public extension Type {
54
@discardableResult
65
/// Define and add the federated key to this type.
76
///
@@ -10,14 +9,14 @@ extension Type {
109
/// - function: The resolver function used to load this entity based on the key value.
1110
/// - _: The key value. The name of this argument must match a Type field.
1211
/// - Returns: Self for chaining.
13-
public func key<Arguments: Codable>(
12+
func key<Arguments: Codable>(
1413
at function: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>,
1514
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
1615
) -> Self {
1716
keys.append(Key(arguments: [argument()], asyncResolve: function))
1817
return self
1918
}
20-
19+
2120
@discardableResult
2221
/// Define and add the federated key to this type.
2322
///
@@ -26,15 +25,15 @@ extension Type {
2625
/// - function: The resolver function used to load this entity based on the key value.
2726
/// - _: The key values. The names of these arguments must match Type fields.
2827
/// - Returns: Self for chaining.
29-
public func key<Arguments: Codable>(
28+
func key<Arguments: Codable>(
3029
at function: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>,
3130
@ArgumentComponentBuilder<Arguments> _ arguments: ()
32-
-> [ArgumentComponent<Arguments>] = { [] }
31+
-> [ArgumentComponent<Arguments>] = { [] }
3332
) -> Self {
3433
keys.append(Key(arguments: arguments(), asyncResolve: function))
3534
return self
3635
}
37-
36+
3837
@discardableResult
3938
/// Define and add the federated key to this type.
4039
///
@@ -43,14 +42,14 @@ extension Type {
4342
/// - function: The resolver function used to load this entity based on the key value.
4443
/// - _: The key value. The name of this argument must match a Type field.
4544
/// - Returns: Self for chaining.
46-
public func key<Arguments: Codable>(
45+
func key<Arguments: Codable>(
4746
at function: @escaping SimpleAsyncResolve<Resolver, Context, Arguments, ObjectType?>,
4847
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
4948
) -> Self {
5049
keys.append(Key(arguments: [argument()], simpleAsyncResolve: function))
5150
return self
5251
}
53-
52+
5453
@discardableResult
5554
/// Define and add the federated key to this type.
5655
///
@@ -59,15 +58,15 @@ extension Type {
5958
/// - function: The resolver function used to load this entity based on the key value.
6059
/// - _: The key values. The names of these arguments must match Type fields.
6160
/// - Returns: Self for chaining.
62-
public func key<Arguments: Codable>(
61+
func key<Arguments: Codable>(
6362
at function: @escaping SimpleAsyncResolve<Resolver, Context, Arguments, ObjectType?>,
6463
@ArgumentComponentBuilder<Arguments> _ arguments: ()
65-
-> [ArgumentComponent<Arguments>] = { [] }
64+
-> [ArgumentComponent<Arguments>] = { [] }
6665
) -> Self {
6766
keys.append(Key(arguments: arguments(), simpleAsyncResolve: function))
6867
return self
6968
}
70-
69+
7170
@discardableResult
7271
/// Define and add the federated key to this type.
7372
///
@@ -76,15 +75,15 @@ extension Type {
7675
/// - function: The resolver function used to load this entity based on the key value.
7776
/// - _: The key value. The name of this argument must match a Type field.
7877
/// - Returns: Self for chaining.
79-
public func key<Arguments: Codable>(
78+
func key<Arguments: Codable>(
8079
at function: @escaping SyncResolve<Resolver, Context, Arguments, ObjectType?>,
8180
@ArgumentComponentBuilder<Arguments> _ arguments: ()
82-
-> [ArgumentComponent<Arguments>] = { [] }
81+
-> [ArgumentComponent<Arguments>] = { [] }
8382
) -> Self {
8483
keys.append(Key(arguments: arguments(), syncResolve: function))
8584
return self
8685
}
87-
86+
8887
@discardableResult
8988
/// Define and add the federated key to this type.
9089
///
@@ -93,51 +92,51 @@ extension Type {
9392
/// - function: The resolver function used to load this entity based on the key value.
9493
/// - _: The key values. The names of these arguments must match Type fields.
9594
/// - Returns: Self for chaining.
96-
public func key<Arguments: Codable>(
95+
func key<Arguments: Codable>(
9796
at function: @escaping SyncResolve<Resolver, Context, Arguments, ObjectType?>,
9897
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
9998
) -> Self {
10099
keys.append(Key(arguments: [argument()], syncResolve: function))
101100
return self
102101
}
103102
}
104-
103+
105104
#if compiler(>=5.5) && canImport(_Concurrency)
106105

107-
public extension Type {
108-
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
109-
@discardableResult
110-
/// Define and add the federated key to this type.
111-
///
112-
/// For more information, see https://www.apollographql.com/docs/federation/entities
113-
/// - Parameters:
114-
/// - function: The resolver function used to load this entity based on the key value.
115-
/// - _: The key value. The name of this argument must match a Type field.
116-
/// - Returns: Self for chaining.
117-
func key<Arguments: Codable>(
118-
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
119-
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
120-
) -> Self {
121-
keys.append(Key(arguments: [argument()], concurrentResolve: function))
122-
return self
123-
}
124-
125-
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
126-
@discardableResult
127-
/// Define and add the federated key to this type.
128-
///
129-
/// For more information, see https://www.apollographql.com/docs/federation/entities
130-
/// - Parameters:
131-
/// - function: The resolver function used to load this entity based on the key value.
132-
/// - _: The key values. The names of these arguments must match Type fields.
133-
/// - Returns: Self for chaining.
134-
func key<Arguments: Codable>(
135-
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
136-
@ArgumentComponentBuilder<Arguments> _ arguments: () -> [ArgumentComponent<Arguments>]
137-
) -> Self {
138-
keys.append(Key(arguments: arguments(), concurrentResolve: function))
139-
return self
106+
public extension Type {
107+
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
108+
@discardableResult
109+
/// Define and add the federated key to this type.
110+
///
111+
/// For more information, see https://www.apollographql.com/docs/federation/entities
112+
/// - Parameters:
113+
/// - function: The resolver function used to load this entity based on the key value.
114+
/// - _: The key value. The name of this argument must match a Type field.
115+
/// - Returns: Self for chaining.
116+
func key<Arguments: Codable>(
117+
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
118+
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
119+
) -> Self {
120+
keys.append(Key(arguments: [argument()], concurrentResolve: function))
121+
return self
122+
}
123+
124+
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
125+
@discardableResult
126+
/// Define and add the federated key to this type.
127+
///
128+
/// For more information, see https://www.apollographql.com/docs/federation/entities
129+
/// - Parameters:
130+
/// - function: The resolver function used to load this entity based on the key value.
131+
/// - _: The key values. The names of these arguments must match Type fields.
132+
/// - Returns: Self for chaining.
133+
func key<Arguments: Codable>(
134+
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
135+
@ArgumentComponentBuilder<Arguments> _ arguments: () -> [ArgumentComponent<Arguments>]
136+
) -> Self {
137+
keys.append(Key(arguments: arguments(), concurrentResolve: function))
138+
return self
139+
}
140140
}
141-
}
142141

143142
#endif

0 commit comments

Comments
 (0)