Swiftpack.co -  joel-perry/ApolloCombine as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
joel-perry/ApolloCombine
A collection of Combine publishers for the Apollo iOS client
.package(url: "https://github.com/joel-perry/ApolloCombine.git", from: "0.5.0")

ApolloCombine

GitHub release (latest SemVer) Swift Package Manager Compatible Cocoapods GitHub

A collection of Combine publishers for the Apollo iOS client.

Usage

The extension to ApolloClientProtocol (in the aptly named ApolloClientExtensions) includes methods whose inputs mirror the existing ApolloClientProtocol operation methods. Instead of including a result handler, though, these methods return Combine publishers that deliver the results of the operation to subscribers.

When cancel() is invoked on a subscription, the underlying Apollo operation is also cancelled.

fetchPublisher, performPublisher, uploadPublisher, and clearCachePublisher will send a completion when the operation has completed.

import ApolloCombine

let client = ApolloClient(...)

let fetchSubscription = client.fetchPublisher(query: MyQuery(), cachePolicy: .fetchIgnoringCacheData)
  .sink(receiveCompletion: { completion in
    // handle .finished or .failure 
    }, receiveValue: { graphQLResult in
      // handle returned fetch data      
  })

// Cancelling the Combine subscription will also cancel the underlying Apollo operation
fetchSubscription.cancel()

watchPublisher and subscribePublisher will not send a completion, instead delivering data and errors as the value of the subscription. This allows these operations to remain open after an error has been encountered. As such, it is important to explicitly cancel these subscriptions when you are done with them to avoid memory leaks.

import ApolloCombine

let client = ApolloClient(...)

let watchSubscription = client.watchPublisher(query: MyQuery())
  .sink(receiveValue: { operationResult in
    switch operationResult {
    case .success(let graphQLResult):
      // handle returned data
    	
    case .failure(let error): 
      // handle error     
  })

// Don't forget to cancel when you're done
watchSubscription.cancel()

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. Use Xcode’s Swift Packages option, which is located within the File menu.

CocoaPods

ApolloCombine is available through CocoaPods. To install it, simply add the following line in your Podfile

pod 'ApolloCombine'

License

ApolloCombine is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 48
Last commit: 21 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

21 weeks ago
  • Updated method signatures to match current Apollo operation signatures. The main difference is the addition of callbackQueue to the watch publisher. This parameter was added in v0.43.0 of the Apollo iOS client, so dependencies have been changed to reflect this. Fixes #9

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