Giter Club home page Giter Club logo

apollocombine's Introduction

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.

apollocombine's People

Contributors

abdelmagied94 avatar af-cgi avatar freddy1h avatar joel-perry avatar mathieutozer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

apollocombine's Issues

Bug with version 0.4.0

Bug report

Hi. After upgrading ApolloCombine to version 0.4.0, an error appears in the PublishersExtensions.
Hope for any help.

Versions

  • ApolloCombine SDK version: 0.4.0
  • Xcode version: 12.5
  • Swift version: 5

Снимок экрана 2021-04-27 в 21 53 41

Watchers end when fetch return an error

Watchers end the Publisher when fetch returns an error, they shouldn't.

i.e watcher emits success -> error -> success

but publisher receives success -> error.

Supporting CocoaPods

There are some projects that installed apollo using Cocoapods so if it installed this package using SPM, it will have another version of apollo dependency. If you don't mind, I could make a PR supporting it.

Breaking change in Apollo 1.5.0

The context parameter added in Apollo 1.5.0 is breaking for this, would it be possible to update for this please as we use this in a few places, would be very helpful. Thank you!

ApolloSubscribeSubscription and Combine error type

Hi, thanks for the ApolloCombine library, saved me a lot of time. But i have a question, is there any reason why the ApolloSubscribeSubscription doesn't handle error like a ApolloFetchSubscription ? I think is really handy to propagate and handle the errors from Apollo through combine framework instead of returning a Publisher with error type NEVER.

If you need more details please tell me. Thanks again!

LATER EDIT: Found the answer in issue : "Watchers end when fetch return an error". Apollo keeps sending values even after an error occurs but Publisher stops.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.