Introduction to Apollo iOS
A strongly typed, Swift-first GraphQL client
Apollo iOS is an open-source GraphQL client for native client applications, written in Swift.
Apollo iOS executes queries and mutations using a GraphQL server and returns results as pre-generated and operation-specific Swift types. This means that Apollo iOS takes care of forming spec-compliant GraphQL requests, parsing JSON responses, and manually validating and type-casting response data for you!
Apollo iOS also includes caching mechanisms specifically for GraphQL data, enabling you to execute GraphQL queries against your locally cached data directly.
Key features
Apollo iOS has three key features:
Used together, these features dramatically improve the process of requesting, consuming, and persisting GraphQL data.
Code generation
Apollo iOS generates objects based on the GraphQL operations you define, providing a type-safe way to use operations in your code.
Each generated operation object contains a set of robust, strongly-typed models for that operation's response. These models enable you to access your GraphQL response data in a type-safe and flexible way.
Because generated response models are operation-specific, they only include properties for the GraphQL fields within that operation. This means you can rely on the Swift type checker to flag data access errors at compile time.
Apollo iOS also generates models for your GraphQL fragments. Using fragment models alongside your operation-specific models enables you to share common models across multiple GraphQL operations.
Apollo iOS additionally generates models for your schema's input, enum, and custom scalar types, all of which help improve your code's type-safety.
The normalized cache
Apollo iOS's normalized cache is designed specifically for GraphQL. It normalizes operation results to build a client-side cache of your data, updating with every operation you execute.
Apollo iOS's cache de-duplicates GraphQL responses, merging data from separate GraphQL operations into normalized objects. This enables your cache to stay up-to-date with your backend with as few operations as possible.
The normalization of objects across operations means that your cache acts as a source of truth for your graph, enabling your application to react to changes in real-time.
To learn more about the normalization process, see our blog post Demystifying Cache Normalization .
Networking and GraphQL execution
Apollo iOS provides a networking API that helps you execute GraphQL operations against any spec-compliant GraphQL server. The GraphQL execution pipeline automatically caches your response data in the normalized cache and returns the response data using your generated, type-safe operation models.
Apollo iOS handles all the heavy lifting of networking with GraphQL, including:
Constructing spec-compliant GraphQL network requests
Checking for existing data in the normalized cache
Executing network transport
Parsing and validating GraphQL network responses
Exposing GraphQL errors as type-safe Swift errors
Writing response data to the normalized cache
Mapping response data onto type-safe, generated operation models
Related libraries
Apollo Kotlin is a GraphQL client for native Android apps written in Java and Kotlin, and it also supports the Kotlin Multi-Platform integration.
Apollo Client's integration for React also works with React Native on both iOS and Android.