Swiftpack.co - GraphQLSwift/GraphQLRxSwift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by GraphQLSwift.
GraphQLSwift/GraphQLRxSwift 0.0.4
The Swift GraphQL RxSwift subscription driver
⭐️ 5
🕓 2 years ago
.package(url: "https://github.com/GraphQLSwift/GraphQLRxSwift.git", from: "0.0.4")

GraphQLRxSwift

GraphQLRxSwift is a small Swift GraphQL/Graphiti subscription driver that allows usage of RxSwift observables as subscription event streams.

Swift License

Looking for help? Find resources from the community.

Getting Started

Before using, it is best to familiarize yourself with the Swift GraphQL and Graphiti packages.

Usage

Add GraphQLRxSwift to your Package.swift

import PackageDescription

let 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:

func subscribeUser(context: HelloContext, arguments: NoArguments) -> EventStream<Any> {
    PublishSubject<Any>().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:

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 for details.

GitHub

link
Stars: 5
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.0.4 - Salamander Skin
2 years ago

Update to comply with Graphiti 1.0.0 EventStream changes

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics