Swiftpack.co - Package - apollographql/apollo-ios

Apollo iOS

CircleCI GitHub license Swift 5 Supported Carthage compatible CocoaPods

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 12 and Swift 5.3.

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: 2792


Used By

Total: 0


Version 0.37.0 -

  • POSSIBLY BREAKING: Updated behavior of URLSessionClient when it's been invalidated to throw an error instead of crashing. If you were relying on this failing loudly before, please be aware it's going to fail a lot more quietly now. (#1489)
  • Improved performance of loadRecords for the SQLite cache. (#1519)
  • Added support for use of Apollo as a dynamic lib. (#1483)
  • Updated the legacy CLI to 2.31.0. (#1510)
  • Fixed some bugs in our JSONSerialization handling. (#1478)
  • Fixed an issue with callback queue handling for websockets. (#1507)
  • Fixed an issue with callback queue handling for errors. (#1468)
  • Removed a redundant nil check while clearing the cache. (#1508)

Version 0.36.0 -

  • POSSIBLY BREAKING: We removed some default parameters for the ApolloStore from ApolloClient and LegacyInterceptorProvider to prevent an issue where developers could accidentally create these objects with different caches. (#1461)
  • Added a new parameter to allow the option to not automatically connect a websocket on initialization. (#1458)

Version 0.35.0 -

  • BREAKING: Removed the now-unused-in-the-SDK GraphQLHTTPResponseError type. If you were relying on this class, please copy it out of v0.34.1. (#1437)
  • BREAKING: Removed default parameters from RequestBodyCreator's default implementation to fix an issue where when default parameters were passed, the compiler would always select the default implementation even if a full alternate implementation was provided. (#1450)
  • Removed unnecessary manual task clearing when invalidating a URLSession. (#1443)

Version 0.34.1 -

  • Fixes an issue that would cause headers to get lost when sending with useGETForQueries. (#1420)

Version 0.34.0 -

Version 0.34.0-rc.2 -

Networking Stack, Release Candidate 2

  • Made RequestChainNetworkTransport subclassable and changed two methods to be open so they can be subclassed in order to facilitate using subclasses of HTTPRequest when needed. (#1405)
  • Made numerous improvements to creating upload requests - all upload request setup is now happening through the UploadRequest class, which is now open for your subclassing funtimes. (#1405)
  • Renamed RequestCreator to RequestBodyCreator to more accurately reflect what it's doing (particularly in light of the fact that we didn't have a Request in the old networking stack, and now we do), and renamed associated properties and parameters. (#1405)

Version 0.34.0-rc.1 -

Networking Stack, Release Candidate

  • Added some final tweaks:

    • Updated ApolloStore to take a default cache of the InMemoryNormalizedCache.
    • Updated LegacyInterceptorProvider to take a default store of the ApolloStore with that default cache.
    • Added a method to InterceptorProvider to provide an error interceptor, along with a default implementation that returns nil.
    • Updated JSONRequest to be open so it can be subclassed.

    This is now at the point where if there are no further major bugs, I'd like to release this - get your bugs in ASAP! (#1399

Version 0.34.0-beta2 -

Networking Stack, Beta 2

  • Merges 0.33.0 changes into the networking stack for Swift 5.3 and Xcode 12.

Version 0.33.0 -

  • Adds support for Xcode 12 and Swift 5.3. (#1280)
  • Adds workaround script for Carthage support in Xcode 12. Please see Carthage-3019 for details. TL;DR: cd into [YourProject]/Carthage/Checkouts/apollo-ios/scripts and then run ./carthage-build-workaround.sh to actually get Carthage builds that work. (#yolo committed to main)

Version 0.33.0-beta1 -

First beta of our new networking stack.

  • SPECTACULARLY BREAKING: The networking stack for HTTP requests has been completely rewritten. This is described in great detail in the RFC for the networking changes, as well as the updated documentation for Advanced Client Creation. Please, please, please file bugs or requests for clarification of the docs as soon as possible. Note that all changes until the networking stack comes out of beta will live on the betas/networking-stack branch. (#1341)

Version 0.32.1 -

  • Improves invalidation of a URLSesionClient to include cancellation of in-flight operations. (#1376)

Version 0.32.0 -

  • Fixes an issue that would occur when a GraphQL query watcher's dependent keys would not get updated. (#1375)
  • Adds an extensions dictionary property to GraphQLResult. (#1370)
  • Makes a couple of response parsing helpers public for advanced use cases. (#1372)

Version 0.31.0 -

  • Adds the ability to pause and resume a WebSocket connection without dumping existing subscriptions. (#1335)

  • Adds an initializer to SQLiteNormalizedCache that takes a SQLite.swift DatabaseConnection to more easily allow setup of pre-configured connections. (#1330)

  • Addresses a retain cycle that could cause memory leaks when using multiple instances of HTTPNetworkTransport.

    NOTE: If you're using URLSessionClient outside the context of HTTPNetworkTransport, make sure to call invalidate() on it when whatever is holding onto it hits deinit() to prevent leaks. (#1366)

Version 0.30.0 -

  • BREAKING: Updates the CLI to 2.30.1 to fix a long-standing issue where when generating operation IDs and their related JSON file, the correct operations + fragments would be used in generating the operation ID, but not output with the JSON file. This will slightly change the output in API.swift, but it also means we can remove a related workaround from the iOS SDK. (#1316)
  • BREAKING: Removed the Cartfile which declared our dependencies, since we're now internally managing them with SPM, and newer versions of Carthage just use the SPM dependencies. Note that this can cause issues if you need to use a fork of dependencies, or if you're using an older version of Carthage. (#1311)
  • POSSIBLY BREAKING: Works around an issue that could cause some attempts to store untyped JSON dictionaries to throw unexpected errors about optional encoding. This also added handling of creating a dictionary from a JSONValue, which may cause problems if you've already implemented this yourself, but which should mostly just replace the need to implement it yourself. Please file issues ASAP if you run into problems here. (#1317)
  • Works around an issue causing some attempts to store arrays of JSON dictionaries to have arbitrary key ordering. (#1281)
  • Adds clearer error descriptions to a few errors. (#1295)

Version 0.29.1 -

Version 0.29.0 -

  • NEW: Swift scripting is officially out of Beta! Please check out our updated guide to integration. The tutorial should be updated to recommend using Swift Scripting within the next week or so. NOTE: The shell script is not deprecated yet, but will be shortly. (#1263)
  • BREAKING: Found some workarounds to conditional conformance and updated all extensions to use the apollo.extensionMethod syntax introduced in 0.28.0. (#1256)
  • BREAKING: Moved a few things into the new ApolloCore library. For CocoaPods and SPM users, this should be automatically picked up by your package manager. Carthage users, you will need to drag the new ApolloCore library into your project manually as you have with the other Apollo libs. (https://github.com/apollographql/apollo-ios/pull/1256)
  • BREAKING: Updated to version 2.28.0 of the Apollo JS CLI. This includes moving a bunch of static let allocations to computed static vars to prevent memory overuse. (#1246)
  • Made GraphQLGetTransformer and its methods public and made a couple more methods on MultipartFormData public. (#1273)
  • Fixes an issue when uploading multiple files for different variables. (#1279, special thanks to #1081)
  • Fixes a crash when encoding GraphQLVariable objects which conform to JSONEncodable. (#1262)

Version 0.28.0 -

  • 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 -

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

Version 0.25.1 -

  • Repoints download link to our CDN for the CLI.

Version 0.24.1 -

  • Repoints download link to our CDN for the CLI.

Version 0.23.3 -

  • Repoints download link to our CDN for the CLI.

Version 0.22.1 -

  • Repoints download link to our CDN for the CLI.

Version 0.21.1 -

  • Repoints download link to our CDN for the CLI.

Version 0.20.1 -

  • Repoints download link to our CDN for the CLI.

Version 0.19.1 -

  • Repoints download link to our CDN for the CLI.

Version 0.18.2 -

  • Repoints download link to our CDN for the CLI.

Version 0.27.0 -

  • 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 -

  • 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 -

  • 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 -

  • 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)