Skip to content

Commit f594464

Browse files
authored
Merge pull request #12 from futuredapp/feature/Add-github-workflows
Add github workflows
2 parents 681c74d + 6ded630 commit f594464

14 files changed

Lines changed: 154 additions & 27 deletions

.github/actionlint-matcher.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "actionlint",
5+
"pattern": [
6+
{
7+
"regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)?:(?:\\x1b\\[\\d+m)?(\\d+)(?:\\x1b\\[\\d+m)?:(?:\\x1b\\[\\d+m)?(\\d+)(?:\\x1b\\[\\d+m)?: (?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)? \\[(.+?)\\]$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"message": 4,
12+
"code": 5
13+
}
14+
]
15+
}
16+
]
17+
}

.github/workflows/lint-swift.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lint Swift
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
paths:
8+
- '**/*.swift'
9+
- 'Package.swift'
10+
- 'Package.resolved'
11+
- '.swiftlint.yml'
12+
- '.github/workflows/lint-swift.yml'
13+
14+
jobs:
15+
swiftlint:
16+
name: SwiftLint
17+
runs-on: macos-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Install SwiftLint
23+
run: brew install swiftlint
24+
25+
- name: Run SwiftLint
26+
run: swiftlint lint --strict
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Lint Workflows
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
paths:
8+
- '.github/workflows/*.yml'
9+
- '.github/actionlint-matcher.json'
10+
11+
jobs:
12+
actionlint:
13+
name: actionlint
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 30
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Download actionlint
21+
id: get_actionlint
22+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
23+
shell: bash
24+
25+
- name: Register problem matcher
26+
run: echo "::add-matcher::.github/actionlint-matcher.json"
27+
28+
- name: Run actionlint
29+
run: ${{ steps.get_actionlint.outputs.executable }} -color
30+
shell: bash

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '**/*.swift'
9+
- 'Package.swift'
10+
- 'Package.resolved'
11+
- '.github/workflows/test.yml'
12+
pull_request:
13+
branches:
14+
- '*'
15+
paths:
16+
- '**/*.swift'
17+
- 'Package.swift'
18+
- 'Package.resolved'
19+
- '.github/workflows/test.yml'
20+
21+
jobs:
22+
macos:
23+
name: macOS
24+
runs-on: macos-latest
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Swift version
30+
run: swift --version
31+
32+
- name: Build
33+
run: swift build -v
34+
35+
- name: Run tests
36+
run: swift test -v

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let package = Package(
2727
.target(
2828
name: "GraphQLAPIKit",
2929
dependencies: [
30-
.product(name: "Apollo", package: "apollo-ios"),
30+
.product(name: "Apollo", package: "apollo-ios")
3131
]
3232
),
3333
.testTarget(

Sources/GraphQLAPIKit/Errors/GraphQLAPIAdapterError.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ public enum GraphQLAPIAdapterError: LocalizedError {
1818
/// Errors returned by GraphQL API as part of `errors` field
1919
case graphQl([GraphQLError])
2020

21-
2221
init(error: Error) {
2322
if let error = error as? GraphQLAPIAdapterError {
2423
self = error
2524
} else if let error = error as? ApolloError {
2625
self = .graphQl(error.errors.map(GraphQLError.init))
2726
} else if let error = error as? URLSessionClient.URLSessionClientError,
28-
case let URLSessionClient.URLSessionClientError.networkError(_, response, underlyingError) = error
29-
{
27+
case let URLSessionClient.URLSessionClientError.networkError(_, response, underlyingError) = error {
3028
if let response = response {
3129
self = .network(code: response.statusCode, error: underlyingError)
3230
} else {

Sources/GraphQLAPIKit/Extensions/GraphQLAPIAdapter+Extensions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Apollo
22
import ApolloAPI
33
import Foundation
44

5+
// swiftlint:disable:next no_extension_access_modifier
56
public extension GraphQLAPIAdapterProtocol {
67
func fetch<Query: GraphQLQuery>(
78
query: Query,

Sources/GraphQLAPIKit/GraphQLAPIAdapter.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ public protocol GraphQLAPIAdapterProtocol: AnyObject {
3838
public final class GraphQLAPIAdapter: GraphQLAPIAdapterProtocol {
3939
private let apollo: ApolloClientProtocol
4040

41+
// swiftlint:disable function_default_parameter_at_end
4142
public init<each Observer: GraphQLNetworkObserver>(
4243
url: URL,
4344
urlSessionConfiguration: URLSessionConfiguration = .default,
4445
defaultHeaders: [String: String] = [:],
4546
networkObservers: repeat each Observer
4647
) {
48+
// swiftlint:enable function_default_parameter_at_end
4749
var observers: [any GraphQLNetworkObserver] = []
4850
repeat observers.append(each networkObservers)
4951

@@ -68,7 +70,7 @@ public final class GraphQLAPIAdapter: GraphQLAPIAdapterProtocol {
6870
url: URL,
6971
urlSessionConfiguration: URLSessionConfiguration = .default,
7072
defaultHeaders: [String: String] = [:],
71-
networkObservers: [any GraphQLNetworkObserver]
73+
networkObservers: [any GraphQLNetworkObserver] = []
7274
) {
7375
let provider = NetworkInterceptorProvider(
7476
client: URLSessionClient(sessionConfiguration: urlSessionConfiguration),

Sources/GraphQLAPIKit/Interceptors/NetworkInterceptorProvider.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct NetworkInterceptorProvider: InterceptorProvider {
2121
func interceptors<Operation: GraphQLOperation>(for operation: Operation) -> [ApolloInterceptor] {
2222
// Headers first, then before-observers, then network fetch, then after-observers
2323
[
24-
RequestHeaderInterceptor(defaultHeaders: defaultHeaders),
24+
RequestHeaderInterceptor(defaultHeaders: defaultHeaders)
2525
]
2626
+ pairOfObserverInterceptors.map(\.before) // Before network - captures timing
2727
+ [
@@ -35,8 +35,8 @@ struct NetworkInterceptorProvider: InterceptorProvider {
3535
JSONResponseParsingInterceptor()
3636
]
3737
}
38-
39-
static private func makePair<T: GraphQLNetworkObserver>(of observer: T) -> (before: ApolloInterceptor, after: ApolloInterceptor) {
38+
39+
private static func makePair<T: GraphQLNetworkObserver>(of observer: T) -> (before: ApolloInterceptor, after: ApolloInterceptor) {
4040
let contextStore = ObserverContextStore<T.Context>()
4141
let beforeInterceptor = ObserverInterceptor(observer: observer, contextStore: contextStore)
4242
let afterInterceptor = ObserverInterceptor(observer: observer, contextStore: contextStore)

Tests/GraphQLAPIKitTests/GraphQLAPIAdapterErrorTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import XCTest
21
import Apollo
32
@testable import GraphQLAPIKit
3+
import XCTest
44

55
final class GraphQLAPIAdapterErrorTests: XCTestCase {
66
func testGraphQLAPIAdapterErrorPassthrough() {
@@ -46,12 +46,14 @@ final class GraphQLAPIAdapterErrorTests: XCTestCase {
4646
code: 500,
4747
userInfo: [NSLocalizedDescriptionKey: "Server error"]
4848
)
49+
// swiftlint:disable force_unwrapping
4950
let response = HTTPURLResponse(
5051
url: URL(string: "https://example.com")!,
5152
statusCode: 500,
5253
httpVersion: nil,
5354
headerFields: nil
5455
)!
56+
// swiftlint:enable force_unwrapping
5557
let urlSessionError = URLSessionClient.URLSessionClientError.networkError(
5658
data: Data(),
5759
response: response,

0 commit comments

Comments
 (0)