Skip to content

Commit 93fcea3

Browse files
authored
Merge pull request #52 from NeedleInAJayStack/subscription
Subscription
2 parents 35cf75f + 9813c75 commit 93fcea3

File tree

9 files changed

+536
-4
lines changed

9 files changed

+536
-4
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git",
1616
"state": {
1717
"branch": null,
18-
"revision": "69f2cd4835ff60b5fae841a680abdc1d56592dd4",
19-
"version": "1.1.7"
18+
"revision": "abf41c20c79331444ee3a290373d7c647c244383",
19+
"version": "1.2.0"
2020
}
2121
},
2222
{

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
.library(name: "Graphiti", targets: ["Graphiti"]),
88
],
99
dependencies: [
10-
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", .upToNextMajor(from: "1.1.8")),
10+
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", .upToNextMajor(from: "1.2.0"))
1111
],
1212
targets: [
1313
.target(name: "Graphiti", dependencies: ["GraphQL"]),

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ struct Resolver {
152152
}
153153
```
154154

155+
#### Subscription
156+
157+
This library supports GraphQL subscriptions. To use them, you must create a concrete subclass of the `EventStream` class that implements event streaming
158+
functionality.
159+
160+
If you don't feel like creating a subclass yourself, you can use the [GraphQLRxSwift](https://github.com/GraphQLSwift/GraphQLRxSwift) repository
161+
to integrate [RxSwift](https://github.com/ReactiveX/RxSwift) observables out-of-the-box. Or you can use that repository as a reference to connect a different
162+
stream library like [ReactiveSwift](https://github.com/ReactiveCocoa/ReactiveSwift), [OpenCombine](https://github.com/OpenCombine/OpenCombine), or
163+
one that you've created yourself.
164+
155165
## Star Wars API example
156166

157167
Check the [Star Wars API](Tests/GraphitiTests/StarWarsAPI/StarWarsAPI.swift) for a more complete example.

Sources/Graphiti/API/API.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,21 @@ extension API {
2525
operationName: operationName
2626
)
2727
}
28+
29+
public func subscribe(
30+
request: String,
31+
context: ContextType,
32+
on eventLoopGroup: EventLoopGroup,
33+
variables: [String: Map] = [:],
34+
operationName: String? = nil
35+
) -> EventLoopFuture<SubscriptionResult> {
36+
return schema.subscribe(
37+
request: request,
38+
resolver: resolver,
39+
context: context,
40+
eventLoopGroup: eventLoopGroup,
41+
variables: variables,
42+
operationName: operationName
43+
)
44+
}
2845
}

Sources/Graphiti/Schema/Schema.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,27 @@ public extension Schema {
5656
return eventLoopGroup.next().makeFailedFuture(error)
5757
}
5858
}
59+
60+
func subscribe(
61+
request: String,
62+
resolver: Resolver,
63+
context: Context,
64+
eventLoopGroup: EventLoopGroup,
65+
variables: [String: Map] = [:],
66+
operationName: String? = nil
67+
) -> EventLoopFuture<SubscriptionResult> {
68+
do {
69+
return try graphqlSubscribe(
70+
schema: schema,
71+
request: request,
72+
rootValue: resolver,
73+
context: context,
74+
eventLoopGroup: eventLoopGroup,
75+
variableValues: variables,
76+
operationName: operationName
77+
)
78+
} catch {
79+
return eventLoopGroup.next().makeFailedFuture(error)
80+
}
81+
}
5982
}

0 commit comments

Comments
 (0)