Latest | 0.6.0 |
---|---|
Homepage | https://github.com/scottrhoyt/RxApollo |
License | MIT |
Platforms | ios 9.0 |
Dependencies | Apollo, RxSwift |
Authors |
RxSwift extensions for Apollo.
Installation
Carthage
github "scottrhoyt/RxApollo"
Manual
Add RxApollo.swift
to your project.
Usage
All the reactive extensions are encapsulated in the rx
property of an ApolloClient
.
import Apollo
import RxSwift
import RxApollo
let apollo: ApolloClient
let disposeBag = DisposeBag()
Fetch
Fetching works just how you would expect it to:
// Let's get our hero's name and print it or the error if there is one.
apollo.rx.fetch(query: HeroNameQuery())
.map { $0.hero?.name }
.subscribe(onNext: { heroName in
print("Our hero's name is (heroName).")
}, onError: { error in
print("Received error: (error).")
})
.disposed(by: disposeBag)
Watch
// Let's watch to see if our hero's name changes and print it or the error if there is one.
apollo.rx.watch(query: HeroNameQuery())
.map { $0.hero?.name }
.subscribe(onNext: { heroName in
print("Our hero's name is (heroName).")
}, onError: { error in
print("Received error: (error).")
})
.disposed(by: disposeBag)
Watching also works quite well with using RxCocoa
bindings:
import RxCocoa
let heroField: UITextField
// Let's watch to see if our hero's name changes and set a text field.
apollo.rx.watch(query: HeroNameQuery())
.map { $0.hero?.name }
.asDriver(onErrorJustReturn: nil)
.drive(heroField.rx.text)
.disposed(by: disposeBag)
Mutate
Mutations follow the same pattern as well:
// Let's upvote a post.
apollo.rx.perform(mutation: UpvotePostMutation(postId: postId))
.subscribe()
.disposed(by: disposeBag)
License
MIT
Latest podspec
{ "name": "RxApollo", "version": "0.6.0", "summary": "RxSwift extensions for Apollo.", "description": "This is an Rx extension that provides an easy and straight-forward waynto use Apollo requests (fetch, watch, mutate) as an Observable", "homepage": "https://github.com/scottrhoyt/RxApollo", "license": "MIT", "authors": { "Scott Hoyt": "[email protected]" }, "source": { "git": "https://github.com/scottrhoyt/RxApollo.git", "tag": "0.6.0" }, "platforms": { "ios": "9.0" }, "source_files": "RxApollo/*.swift", "dependencies": { "Apollo": [ "~> 0.7.0" ], "RxSwift": [ "~> 4.0" ] }, "pushed_with_swift_version": "4.0" }
Sun, 03 Dec 2017 12:40:12 +0000