Swiftpack.co - Package - apollographql/apollo-ios

Apollo iOS

CircleCI GitHub license Swift 5 Supported Carthage compatible CocoaPods Join the community on Spectrum

Apollo iOS is a strongly-typed, caching GraphQL client for iOS, written in Swift.

It allows you to execute queries and mutations against a GraphQL server, and returns results as query-specific Swift types. This means you don’t have to deal with parsing JSON, or passing around dictionaries and making clients cast values to the right type manually. You also don't have to write model types yourself, because these are generated from the GraphQL definitions your UI uses.

As the generated types are query-specific, you're only able to access data you actually specify as part of a query. If you don't ask for a field, you won't be able to access the corresponding property. In effect, this means you can now rely on the Swift type checker to make sure errors in data access show up at compile time. With our Xcode integration, you can conveniently work with your UI code and corresponding GraphQL definitions side by side, and it will even validate your query documents, and show errors inline.

Apollo iOS does more than simply run your queries against a GraphQL server: It normalizes query results to construct a client-side cache of your data, which is kept up to date as further queries and mutations are run. This means your UI is always internally consistent, and can be kept fully up-to-date with the state on the server with the minimum number of queries required.

This combination of models with value semantics, one way data flow, and automatic consistency management, leads to a very powerful and elegant programming model that allows you to eliminate common glue code and greatly simplifies app development.


Read the full docs at apollographql.com/docs/ios/


Read about the latest changes to the library


This project is being developed using Xcode 11 and Swift 5.0.

If you open Apollo.xcworkspace, you should be able to run the tests of the Apollo, ApolloSQLite, and ApolloWebSocket frameworks on your Mac or an iOS Simulator.

NOTE: Due to a change in behavior in Xcode 11's git integration, if you check this repo out using Xcode, please close the window Xcode automatically opens using the Swift Package manager structure, and open the Apollo.xcworkspace file instead.

Some of the tests run against a simple GraphQL server serving the Star Wars example schema (see installation instructions there).

If you'd like to contribute, please refer to the Apollo Contributor Guide.


Stars: 2519


Used By

Total: 0


Version 0.28.0 - 2020-05-28 00:54:49

  • BREAKING: Changed a few things in the ApolloCodegen library to use object.apollo.extensionMethod syntax rather than object.apollo_extensionMethod. There's a few things that are still using apollo_ notation due to constraints around conditional conformance, but you should particularly check your swift scripts for changes around FileManager APIs. (#1183)
  • BREAKING: NormalizedCache now has a method for explicitly clearing the cache synchronously, in addition to the existing method to clear it asynchronously. If you've got a custom NormalizedCache implementation, you'll need to add an implementation for this method. (#1186)
  • Fixed race conditions in URLSessionClient that were causing unexpected behavior. Turns out concurrency is hard! (#1227)
  • Improved handling of a dependent key update cancelling an in-flight server fetch on a watcher. (#1156)
  • Added option to Swift Codegen to pass in a prefix for custom scalars. (#1216)
  • Added ability to change a header on a websocket connection and automatically reconnect. (#1224)

Version 0.27.1 - 2020-05-04 19:27:47

  • Better defense against multithreading crashes in URLSessionClient. (#1184)
  • Fix for watchOS availability for URLSessionClient. (#1175)

Version 0.25.1 - 2020-05-01 00:57:51

  • Repoints download link to our CDN for the CLI.

Version 0.24.1 - 2020-05-01 00:49:14

  • Repoints download link to our CDN for the CLI.

Version 0.23.3 - 2020-05-01 00:40:18

  • Repoints download link to our CDN for the CLI.

Version 0.22.1 - 2020-05-01 00:31:13

  • Repoints download link to our CDN for the CLI.

Version 0.21.1 - 2020-05-01 00:22:38

  • Repoints download link to our CDN for the CLI.

Version 0.20.1 - 2020-05-01 00:15:52

  • Repoints download link to our CDN for the CLI.

Version 0.19.1 - 2020-05-01 00:08:49

  • Repoints download link to our CDN for the CLI.

Version 0.18.2 - 2020-05-01 00:03:06

  • Repoints download link to our CDN for the CLI.

Version 0.27.0 - 2020-04-28 04:22:37

  • BREAKING: Replaced calls directly into the closure based implementation of URLSession with a delegate-based implementation called URLSessionClient.
    • This (finally) allows background session configurations to be used with ApolloClient, since background session configurations immediately error out if you try to use the closure-based URLSession API.

    • This makes a significant change to the initialization of HTTPNetworkTransport if you're using a custom URLSession: Because URLSession must have its delegate set at the point of creation, URLSessionClient is now creating the URL session. You can initialize a URLSessionClient with a URLSessionConfiguration. if before you were using:

      let session = URLSession(configuration: myCustomConfiguration)
      let url = URL(string: "http://localhost:8080/graphql")!
      let transport = HTTPNetworkTransport(url: url,
                                           session: session)

      You will now need to use:

      let client = URLSessionClient(sessionConfiguration: myCustomConfiguration)
      let url = URL(string: "http://localhost:8080/graphql")!
      let transport = HTTPNetworkTransport(url: url,
                                           client: client)
    • If you were passing in a session you'd already set yourself up to be the delegate of to handle GraphQL requests, you'll need to subclass URLSessionClient and override any delegate methods off of URLSessionDelegate, URLSessionTaskDelegate, or URLSessionDataDelegate you need to handle. Unfortunately only one class can be a delegate at a time, and that class must be declared when the session is instantiated.

      Note that if you don't need your existing delegate-based session to do any handling for things touched by Apollo, you can keep it completely separate if you'd prefer.

    • This does not change anything at the point of calls - everything is still closure-based in the end

      Please file bugs on this ASAP if you run into problems. Thank you! (#1163)

Version 0.26.0 - 2020-04-21 03:12:58

  • BREAKING, though in a good way: Updated the typescript CLI to 2.27.2, and updated the script to pull from a CDN (currently backed by GitHub Releases) rather than old Circle images. This should significantly increase download performance and stability. (#1166)
  • BREAKING: Updated the retry delegate to allow more fine-grained control of what error to return if an operation fails in the process of retrying. (#1128, #1167)
  • Added support to the Swift scripting package to be able to use multiple headers when downloading a schema. (#1153)
  • Added the ability to set the SSL trust validator on a websocket. (#1124)
  • Fixed an issue deserializing custom scalars in ApolloSQLite. (#1144)

Version 0.25.0 - 2020-03-31 22:12:28

  • BREAKING: Updated the swift-tools version to 5.2 in Package.swift. Note that if you're using swift-tools 5.2, you'll need to update the syntax of your Package.swift file and specify the name of the library manually for Apollo. (#1099, #1106)
  • POSSIBLY BREAKING: Upgraded the typescript CLI to 2.26.0. No changes were found in test frameworks, but this could theoretically break some stuff. (#1107, #1113)
  • NEW: Added the ability to set Starscream's underlying enableSOCKSProxy to better allow debugging web sockets in tools like Charles Proxy. (#1108)
  • Fixed several issues using paths with spaces in the Swift Codegen. (#1092, #1097).
  • ApolloCodegenLib is now properly passing the header argument last when downloading a schema. (#1096)
  • Automatic Persisted Queries now also work with mutations. (#1110)

Version 0.24.0 - 2020-03-20 01:08:26

  • BREAKING: Updated GraphQLResponse to be generic over the response type rather than the operation type. This will allow more flexibility for generic modifications to methods that need to use GraphQLResponse. (#1061)
  • BREAKING: Updated the file URL-based initializer of GraphQL to throw with a clear error instead of failing silently. Removed the ability to pass in an input stream since that can't be recreated on a failure. Updated initializers take either raw Data or a file URL so that the input stream can be recreated on a retry. (#1086, #1089)
  • In the Swift Package Manager based codegen, made sure that the folder the CLI will be downloaded to is created if it doesn't exist. (#1069)

Version 0.23.2 - 2020-03-05 21:12:52

  • Changed the @available flags added in 0.23.1 to #if os(macOS), since the former is runtime and the latter is compile time, to work around a bug where SwiftUI compiles the ApolloCodegenLib library even if it's not included in the target being previewed. (#1066)
  • Added support for omitDeprecatedEnumCases command line option I missed for ApolloCodegenOptions (#1053)

Version 0.23.1 - 2020-02-27 18:36:53

  • Added some @available flags to prevent accidental compilation of ApolloCodegenLib on platforms other than macOS. (#1041)
  • Made the Query on GraphQLQueryWatcher public so it can be referenced. (#1037)

Version 0.23.0 - 2020-02-21 03:04:31


  • BETA: Now available, SPM-based code generation, Phase 0 of our transition to Swift Codegen.

    Note that the underlying codegen is still using apollo-tooling, but that will change as we proceed with Phase 1 of the Swift Codegen Project, generating the code in Swift.

    Documentation is available at our Swift Scripting page.

    When this gets to the final version this will supersede existing codegen, so please file bugs galore on this so we can get it good to go as quickly as possible. Thank you! (#940, #1033)

  • Fixed some memory leaks in our internal Promises implementation. (#1016)

Version 0.22.0 - 2020-02-13 20:43:44

  • BREAKING: Updated CLI to v2.22.1, including a bunch of fixes on the Swift side:
    • Marked files which are generated as @generated
    • Added documentation to the constructors of input structs
    • Added additional type annotations to improve compile times.
  • BREAKING: Updated delegate in HTTPNetworkTransport to be a weak var and to not be passed in as a parameter to the initializer. (#990, #1002)
  • Added a lock to InMemoryNormalizedCache to reduce possible race conditions. (#552)
  • Added the ability to not send duplicates on a websocket. (#1004)
  • Fixed an issue that could lead to an undefined cache key in the SQLite library. (#991)
  • Fixed an issue where existing fetch operations in a watcher would not be canceled before a new one was started. (#1012)

Version 0.21.0 - 2019-12-19 22:03:26

  • BREAKING, but by popular request: Removed the requirement that the clientName and clientVersion on NetworkTransport, and added a default implementation so custom implementations don't need to set these up themselves. (#954)

Version 0.20.0 - 2019-11-16 22:34:24

  • Fixed a bunch of data races in ApolloWebSocket. (#880)
  • Updated ApolloWebSocket to depend on Apollo in Package.swift since there is a dependency there. (#906)
  • POSSIBLY BREAKING Updated Swift tools verson in package declaration to 5.1. (#883)

Version 0.19.0 - 2019-10-29 22:29:01

  • NEW: Added a retry delegate to allow retries based on GraphQL errors returned from your server, not just network-level errors. NOTE: Be careful with which errors you retry for - the mere presence of an error doesn't necessarily indicate a full failure since GraphQL queries can return partial results. (#770)
  • NEW: Automatically generates ApolloEngine/ApolloGraphManager headers based on your main bundle's ID and version number. These can also be configured when you set up your NetworkTransport if you need something more granular for different versions of your application. (#858)
  • POSSIBLY BREAKING: The NetworkTransport protocol is now class-bound. If you built your own NetworkTransport implementation instead of one of the ones included with the library, this now must be a class instead of a struct. (#770)
  • POSSIBLY BREAKING: Removed an unzip method for arrays of arrays which we were not using. However, since it was public, we figured we should let you know. (#872)
  • Bumped Starscream dependency to 3.1.1. (#873)

Version 0.18.1 - 2019-10-24 16:12:51

  • Removes TSAN from run on schemes to fix Carthage issue. (#862)

Version 0.18.0 - 2019-10-23 00:56:14

  • POSSIBLY BREAKING: Updated CLI to no longer be directly bundled, but to be downloaded if needed. This allows us to avoid bloating the iOS repo with the CLI zip, and to make it easier to test different versions of the CLI in the future. This change should automatically download the updated CLI version for you.

    Note one significant change from prior bundled versions: If you are connected to the internet when you download the iOS dependency through SPM/Carthage/CocoaPods, you will now need to build your target while still connected to the internet in order to download the proper version of the CLI. Once the correct version of the CLI is downloaded, internet access should no longer be necessary to build. If you disconnect from the internet before the correct version downloads, you will not be able to build. (#855)

  • Updated version of CLI to download to 2.21.0. (#855) This includes:

    • Ability to have the codegen ignore deprecated enum cases by using the --omitDeprecatedEnumCases flag
    • Fix for generating input fields for null values
  • Fixes a number of weak references with closures. Note that this may reveal some places you weren't hanging onto a strong reference to your ApolloClient object, which will cause it to get deallocated. (#854)

Version 0.17.0 - 2019-10-16 03:40:03

  • NEW: Support for Automatic Persisted Queries. This feature allows you to send the hash of a query to your server, and if the server recognizes the hash, it can perform the whole query without you having to send it again. This is particularly useful for large queries, since it can reduce the amount of data you have to send from your user's device pretty significantly. (#767)
  • BREAKING: Removed old script files which have been deprecated. If you were still using these, please check out the updated codegen build step setup instructions to get up and running with the run-bundled-codegen script. (#820)
  • POSSIBLY BREAKING: Updated bundled CLI to v2.19.1. Please check out the CLI changelog for full details, but this version actually moves to using multi-line Swift strings for queries. If you prefer to have condensed queries, it also introduces a --suppressSwiftMultilineStringLiterals flag which produces single-line queries stripped of whitespace. (#831)
  • Fixed a couple places we were not using LocalizedError properly. (#818)

Version 0.16.1 - 2019-10-03 14:57:54

  • Updated the way run-bundled-codegen checks whether the bundled codegen has already been unzipped and has node locally. (#806)
  • Updated how default parameters are provided for RequestCreatorProtocol. (#804)

Version 0.16.0 - 2019-09-24 22:48:22

  • BREAKING: We've switched to a much simpler setup which does not involve NPM in order to use our CLI. This requires updating your build scripts. Please follow the updated instructions for setting up the build script here. The existing build script will continue to work until the next minor release, at which point it will be removed. (#766)
  • Included CLI version fixes issues which showed up in 0.15.2.
  • BREAKING: We've removed all public references to our internal Promise implementation, which was never intended to be public. (#709)
  • Fixed a deadlock in a transaction. (#763, #365)
  • Added a RequestCreatorProtocol to allow you to more easily muck with and/or mock creating multipart requests. (#771)
  • Fixed an issue causing problems building with SPM in Xcode 11. (#784)

Version 0.15.3 - 2019-09-13 01:50:41

  • Revert CLI update from 0.15.2 due to unexpected build issues.

Version 0.15.2 - 2019-09-12 23:56:32

  • Update Apollo CLI requirement to 2.18. This should pull in a couple fixes to the CLI:

    • Way better escaping of identifiers, types, and strings (Tooling #1515)
    • Fix compiler warning when an optional has a .none case (Tooling #1482)

    If you run into any weird build issues after this update, try deleting your local node_modules folder and rebuilding before filing an issue. (#760)

  • Better handling of the localizedDescription for HTTPResponseError. (#756)

Version 0.15.1 - 2019-09-04 16:49:39

  • Add platform name to framework bundle identifier to work around a change to app store submission. Please see the PR for more details. (#751)
  • Expose the initializer for GraphQLQueryWatcher so it can actually be instantiated. (#750)

Version 0.15.0 - 2019-08-16 09:12:56

  • BREAKING: Finally swapped out URLSessionConfiguration on initializer for HTTPNetworkTransport to use URLSession directly instead. If you were previously passing in a configuration, first hand it to a URLSession instance and then pass that instance into the initializer.

    This allows many new things including:

    • Support for background sessions
    • Easier mocking through NSURLProtocol
    • Certificate pinning
    • Self-signed certificates
    • Metrics inspection
    • Authentication challenge handling

All these are pretty much entirely through the ability to use URLSessionDelegate directly since we're now accepting a URLSession you can declare yourself to be the delegate of rather than just the configuration. (#699, inspired by #265)

  • BREAKING, though hopefully in a good way: Significant updates to the Upload functionality to make it conform more closely to the GraphQL Upload Spec. Also added a goodly bit of documentation around this functionality. (#707)
  • Way better support for Swift Package Manager, especially for ApolloSQLite and ApolloWebSocket. (#674)
  • Created ApolloClientProtocol to match all public methods of ApolloClient for easier mocking. (#715, inspired by #693)