ApolloCombine

0.8.0

A collection of Combine publishers for the Apollo iOS client
joel-perry/ApolloCombine

What's New

2024-03-07T14:41:06Z
  • Updated method signatures to match current Apollo operation signatures, specifically the addition of a contextIdentifier parameter to mutate calls. This parameter was added in v1.9.1 of the Apollo iOS client, so dependencies have been changed to reflect this. #19 Thanks, @AF-cgi !

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.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

Last updated: Thu Apr 04 2024 15:42:47 GMT-0900 (Hawaii-Aleutian Daylight Time)