Skip to content

Commit b98c7bc

Browse files
Merge pull request #5 from NeedleInAJayStack/chore/warning-cleanup
General repo refresh
2 parents c7ec659 + daa794b commit b98c7bc

File tree

8 files changed

+344
-242
lines changed

8 files changed

+344
-242
lines changed

.github/workflows/build.yml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore: [ README.md ]
7+
pull_request:
8+
branches: [ main ]
9+
paths-ignore: [ README.md ]
10+
workflow_dispatch:
11+
12+
jobs:
13+
formatlint:
14+
name: Format linting
15+
runs-on: ubuntu-latest
16+
steps:
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
25+
26+
macos:
27+
name: Test on macOS
28+
runs-on: macos-latest
29+
steps:
30+
- uses: maxim-lobanov/setup-xcode@v1
31+
with:
32+
xcode-version: latest-stable
33+
- uses: actions/checkout@v3
34+
- name: Build and test
35+
run: swift test --parallel --enable-test-discovery
36+
37+
linux:
38+
name: Test on Linux
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: swift-actions/setup-swift@v2
42+
- uses: actions/checkout@v3
43+
- name: Test
44+
run: swift test --parallel --enable-code-coverage
45+
- name: Get test coverage html
46+
run: |
47+
llvm-cov show \
48+
$(swift build --show-bin-path)/GraphQLRxSwiftPackageTests.xctest \
49+
--instr-profile $(swift build --show-bin-path)/codecov/default.profdata \
50+
--ignore-filename-regex="\.build|Tests" \
51+
--format html \
52+
--output-dir=.test-coverage
53+
- name: Upload test coverage html
54+
uses: actions/upload-artifact@v3
55+
with:
56+
name: test-coverage-report
57+
path: .test-coverage
58+
59+
backcompat-ubuntu-22_04:
60+
name: Test Swift ${{ matrix.swift }} on Ubuntu 22.04
61+
runs-on: ubuntu-22.04
62+
strategy:
63+
matrix:
64+
swift: ["5.7", "5.8", "5.9", "5.10", "6.0"]
65+
steps:
66+
- uses: swift-actions/setup-swift@v2
67+
with:
68+
swift-version: ${{ matrix.swift }}
69+
- uses: actions/checkout@v3
70+
- name: Test
71+
run: swift test --parallel
72+
73+
# Swift versions older than 5.7 don't have builds for 22.04. https://www.swift.org/download/
74+
backcompat-ubuntu-20_04:
75+
name: Test Swift ${{ matrix.swift }} on Ubuntu 20.04
76+
runs-on: ubuntu-20.04
77+
strategy:
78+
matrix:
79+
swift: ["5.4", "5.5", "5.6"]
80+
steps:
81+
- uses: swift-actions/setup-swift@v2
82+
with:
83+
swift-version: ${{ matrix.swift }}
84+
- uses: actions/checkout@v3
85+
- name: Test
86+
run: swift test --parallel

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
### SwiftPM ###
44
.build/
55
.swiftpm/
6+
7+
# VS Code
8+
.vscode

Package.resolved

+28-10
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,62 @@
66
"repositoryURL": "https://github.com/GraphQLSwift/Graphiti.git",
77
"state": {
88
"branch": null,
9-
"revision": "c9bc9d1cc9e62e71a824dc178630bfa8b8a6e2a4",
10-
"version": "1.0.0"
9+
"revision": "ed06f0608a72176fd572763660e7492bfb53a419",
10+
"version": "1.15.1"
1111
}
1212
},
1313
{
1414
"package": "GraphQL",
1515
"repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git",
1616
"state": {
1717
"branch": null,
18-
"revision": "e5de315125f8220334ba3799bbd78c7c1ed529f7",
19-
"version": "2.0.0"
18+
"revision": "87649dbc3cdab0be0256c86235f2aec22ec1bfc1",
19+
"version": "2.10.0"
2020
}
2121
},
2222
{
2323
"package": "RxSwift",
2424
"repositoryURL": "https://github.com/ReactiveX/RxSwift.git",
2525
"state": {
2626
"branch": null,
27-
"revision": "7c17a6ccca06b5c107cfa4284e634562ddaf5951",
28-
"version": "6.2.0"
27+
"revision": "b06a8c8596e4c3e8e7788e08e720e3248563ce6a",
28+
"version": "6.7.1"
29+
}
30+
},
31+
{
32+
"package": "swift-atomics",
33+
"repositoryURL": "https://github.com/apple/swift-atomics.git",
34+
"state": {
35+
"branch": null,
36+
"revision": "cd142fd2f64be2100422d658e7411e39489da985",
37+
"version": "1.2.0"
2938
}
3039
},
3140
{
3241
"package": "swift-collections",
3342
"repositoryURL": "https://github.com/apple/swift-collections",
3443
"state": {
3544
"branch": null,
36-
"revision": "d45e63421d3dff834949ac69d3c37691e994bd69",
37-
"version": "0.0.3"
45+
"revision": "9bf03ff58ce34478e66aaee630e491823326fd06",
46+
"version": "1.1.3"
3847
}
3948
},
4049
{
4150
"package": "swift-nio",
4251
"repositoryURL": "https://github.com/apple/swift-nio.git",
4352
"state": {
4453
"branch": null,
45-
"revision": "d161bf658780b209c185994528e7e24376cf7283",
46-
"version": "2.29.0"
54+
"revision": "9746cf80e29edfef2a39924a66731249223f42a3",
55+
"version": "2.72.0"
56+
}
57+
},
58+
{
59+
"package": "swift-system",
60+
"repositoryURL": "https://github.com/apple/swift-system.git",
61+
"state": {
62+
"branch": null,
63+
"revision": "d2ba781702a1d8285419c15ee62fd734a9437ff5",
64+
"version": "1.3.2"
4765
}
4866
}
4967
]

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ let package = Package(
99
dependencies: [
1010
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "2.0.0"),
1111
.package(url: "https://github.com/GraphQLSwift/Graphiti.git", from: "1.0.0"),
12-
.package(url: "https://github.com/ReactiveX/RxSwift.git", from: "6.1.0")
12+
.package(url: "https://github.com/ReactiveX/RxSwift.git", from: "6.1.0"),
1313
],
1414
targets: [
1515
.target(name: "GraphQLRxSwift", dependencies: ["GraphQL", "Graphiti", "RxSwift"]),
16-
.testTarget(name: "GraphQLRxSwiftTests",dependencies: ["GraphQLRxSwift"]),
16+
.testTarget(name: "GraphQLRxSwiftTests", dependencies: ["GraphQLRxSwift"]),
1717
]
1818
)
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import GraphQL
2+
import NIO
23
import RxSwift
34

45
// EventStream wrapper for Observable
5-
public class ObservableEventStream<Element> : EventStream<Element> {
6+
public class ObservableEventStream<Element>: EventStream<Element> {
67
public var observable: Observable<Element>
78
init(_ observable: Observable<Element>) {
89
self.observable = observable
910
}
11+
1012
override open func map<To>(_ closure: @escaping (Element) throws -> To) -> EventStream<To> {
1113
return ObservableEventStream<To>(observable.map(closure))
1214
}
1315
}
16+
1417
// Convenience types
1518
public typealias ObservableSubscriptionEventStream = ObservableEventStream<Future<GraphQLResult>>
1619

17-
extension Observable {
20+
public extension Observable {
1821
// Convenience method for wrapping Observables in EventStreams
19-
public func toEventStream() -> ObservableEventStream<Element> {
22+
func toEventStream() -> ObservableEventStream<Element> {
2023
return ObservableEventStream(self)
2124
}
2225
}

Tests/GraphQLRxSwiftTests/GraphQL/SubscriptionSchema.swift

+34-32
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import NIO
44
import RxSwift
55

66
// MARK: Types
7-
struct Email : Encodable {
8-
let from:String
9-
let subject:String
10-
let message:String
11-
let unread:Bool
12-
let priority:Int
13-
14-
init(from:String, subject:String, message:String, unread:Bool, priority:Int = 0) {
7+
8+
struct Email: Encodable {
9+
let from: String
10+
let subject: String
11+
let message: String
12+
let unread: Bool
13+
let priority: Int
14+
15+
init(from: String, subject: String, message: String, unread: Bool, priority: Int = 0) {
1516
self.from = from
1617
self.subject = subject
1718
self.message = message
@@ -20,16 +21,17 @@ struct Email : Encodable {
2021
}
2122
}
2223

23-
struct Inbox : Encodable {
24-
let emails:[Email]
24+
struct Inbox: Encodable {
25+
let emails: [Email]
2526
}
2627

27-
struct EmailEvent : Encodable {
28-
let email:Email
29-
let inbox:Inbox
28+
struct EmailEvent: Encodable {
29+
let email: Email
30+
let inbox: Inbox
3031
}
3132

3233
// MARK: Schema
34+
3335
let EmailType = try! GraphQLObjectType(
3436
name: "Email",
3537
fields: [
@@ -62,7 +64,7 @@ let InboxType = try! GraphQLObjectType(
6264
"unread": GraphQLField(
6365
type: GraphQLInt,
6466
resolve: { inbox, _, _, _ in
65-
(inbox as! Inbox).emails.filter({$0.unread}).count
67+
(inbox as! Inbox).emails.filter { $0.unread }.count
6668
}
6769
),
6870
]
@@ -75,15 +77,15 @@ let EmailEventType = try! GraphQLObjectType(
7577
),
7678
"inbox": GraphQLField(
7779
type: InboxType
78-
)
80+
),
7981
]
8082
)
8183
let EmailQueryType = try! GraphQLObjectType(
8284
name: "Query",
8385
fields: [
8486
"inbox": GraphQLField(
8587
type: InboxType
86-
)
88+
),
8789
]
8890
)
8991

@@ -95,40 +97,40 @@ class EmailDb {
9597
var emails: [Email]
9698
let publisher: PublishSubject<Any>
9799
let disposeBag: DisposeBag
98-
100+
99101
init() {
100102
emails = [
101103
Email(
102104
from: "joe@graphql.org",
103105
subject: "Hello",
104106
message: "Hello World",
105107
unread: false
106-
)
108+
),
107109
]
108110
publisher = PublishSubject<Any>()
109111
disposeBag = DisposeBag()
110112
}
111-
113+
112114
/// Adds a new email to the database and triggers all observers
113-
func trigger(email:Email) {
115+
func trigger(email: Email) {
114116
emails.append(email)
115117
publisher.onNext(email)
116118
}
117-
119+
118120
/// Returns the default email schema, with standard resolvers.
119121
func defaultSchema() -> GraphQLSchema {
120122
return emailSchemaWithResolvers(
121-
resolve: {emailAny, _, _, eventLoopGroup, _ throws -> EventLoopFuture<Any?> in
123+
resolve: { emailAny, _, _, eventLoopGroup, _ throws -> EventLoopFuture<Any?> in
122124
if let email = emailAny as? Email {
123125
return eventLoopGroup.next().makeSucceededFuture(EmailEvent(
124126
email: email,
125127
inbox: Inbox(emails: self.emails)
126128
))
127129
} else {
128-
throw GraphQLError(message: "\(type(of:emailAny)) is not Email")
130+
throw GraphQLError(message: "\(type(of: emailAny)) is not Email")
129131
}
130132
},
131-
subscribe: {_, args, _, eventLoopGroup, _ throws -> EventLoopFuture<Any?> in
133+
subscribe: { _, args, _, eventLoopGroup, _ throws -> EventLoopFuture<Any?> in
132134
let priority = args["priority"].int ?? 0
133135
let filtered = self.publisher.filter { emailAny throws in
134136
if let email = emailAny as? Email {
@@ -141,10 +143,10 @@ class EmailDb {
141143
}
142144
)
143145
}
144-
146+
145147
/// Generates a subscription to the database using the default schema and resolvers
146-
func subscription (
147-
query:String,
148+
func subscription(
149+
query: String,
148150
variableValues: [String: Map] = [:]
149151
) throws -> SubscriptionEventStream {
150152
return try createSubscription(schema: defaultSchema(), query: query, variableValues: variableValues)
@@ -163,11 +165,11 @@ func emailSchemaWithResolvers(resolve: GraphQLFieldResolve? = nil, subscribe: Gr
163165
args: [
164166
"priority": GraphQLArgument(
165167
type: GraphQLInt
166-
)
168+
),
167169
],
168170
resolve: resolve,
169171
subscribe: subscribe
170-
)
172+
),
171173
]
172174
)
173175
)
@@ -186,13 +188,13 @@ func createSubscription(
186188
instrumentation: NoOpInstrumentation,
187189
schema: schema,
188190
request: query,
189-
rootValue: Void(),
190-
context: Void(),
191+
rootValue: (),
192+
context: (),
191193
eventLoopGroup: eventLoopGroup,
192194
variableValues: variableValues,
193195
operationName: nil
194196
).wait()
195-
197+
196198
if let stream = result.stream {
197199
return stream
198200
} else {

0 commit comments

Comments
 (0)