Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/GraphQLSwift/GraphQLRxSwift
The Swift GraphQL RxSwift subscription driver
https://github.com/GraphQLSwift/GraphQLRxSwift
graphiti graphql rxswift subscription swift swift-nio swiftpm
Last synced: 3 months ago
JSON representation
The Swift GraphQL RxSwift subscription driver
- Host: GitHub
- URL: https://github.com/GraphQLSwift/GraphQLRxSwift
- Owner: GraphQLSwift
- License: mit
- Created: 2021-03-11T02:42:28.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-07T17:07:28.000Z (4 months ago)
- Last Synced: 2024-11-07T18:23:04.974Z (4 months ago)
- Topics: graphiti, graphql, rxswift, subscription, swift, swift-nio, swiftpm
- Language: Swift
- Homepage:
- Size: 39.1 KB
- Stars: 5
- Watchers: 9
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GraphQLRxSwift
GraphQLRxSwift is a small Swift GraphQL/Graphiti subscription driver that allows usage of [RxSwift](https://github.com/ReactiveX/RxSwift) observables
as subscription event streams.[![Swift][swift-badge]][swift-url]
[![License][mit-badge]][mit-url]Looking for help? Find resources [from the community](http://graphql.org/community/).
## Getting Started
Before using, it is best to familiarize yourself with the Swift [GraphQL](https://github.com/GraphQLSwift/GraphQL) and
[Graphiti](https://github.com/GraphQLSwift/Graphiti) packages.## Usage
Add GraphQLRxSwift to your `Package.swift`
```swift
import PackageDescriptionlet package = Package(
dependencies: [
.Package(url: "https://github.com/GraphQLSwift/GraphQLRxSwift.git", .upToNextMinor(from: "0.0.1")),
]
)
```GraphQLRxSwift provides an `ObservableEventStream` wrapper class that can be used with an RxSwift `Observable` to satisfy
`EventStream` requirements. A convenience method `toEventStream` is added to all Observable instances.
This class is used when defining subscription resolvers, as shown below:```swift
func subscribeUser(context: HelloContext, arguments: NoArguments) -> EventStream {
PublishSubject().toEventStream()
}
```Also provided is a `ObservableSubscriptionEventStream` type alias that can be used to downcast the result of a subscribe execution.
It is guaranteed that the stream returned by any subscription query whose resolver returns an `ObservableEventStream` will be a
`ObservableSubscriptionEventStream`. For example:```swift
let subscriptionResult = try graphQLApi.subscribe(
request: request,
context: api.context,
on: group
).wait()
let subscription = subscriptionResult.stream as! ObservableSubscriptionEventStream? // Guaranteed
```## License
This project is released under the MIT license. See [LICENSE](LICENSE) for details.
[swift-badge]: https://img.shields.io/badge/Swift-5.2-orange.svg?style=flat
[swift-url]: https://swift.org[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat
[mit-url]: https://tldrlegal.com/license/mit-license