Skip to content

Commit daa794b

Browse files
chore: Applies formatting to repo
1 parent 2405222 commit daa794b

File tree

5 files changed

+225
-224
lines changed

5 files changed

+225
-224
lines changed

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
)

Sources/GraphQLRxSwift/ObservableEventStream.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ import NIO
33
import RxSwift
44

55
// EventStream wrapper for Observable
6-
public class ObservableEventStream<Element> : EventStream<Element> {
6+
public class ObservableEventStream<Element>: EventStream<Element> {
77
public var observable: Observable<Element>
88
init(_ observable: Observable<Element>) {
99
self.observable = observable
1010
}
11+
1112
override open func map<To>(_ closure: @escaping (Element) throws -> To) -> EventStream<To> {
1213
return ObservableEventStream<To>(observable.map(closure))
1314
}
1415
}
16+
1517
// Convenience types
1618
public typealias ObservableSubscriptionEventStream = ObservableEventStream<Future<GraphQLResult>>
1719

18-
extension Observable {
20+
public extension Observable {
1921
// Convenience method for wrapping Observables in EventStreams
20-
public func toEventStream() -> ObservableEventStream<Element> {
22+
func toEventStream() -> ObservableEventStream<Element> {
2123
return ObservableEventStream(self)
2224
}
2325
}

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
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)