Docs
Launch GraphOS Studio

Introduction to Apollo iOS

A strongly typed, Swift-first GraphQL client


Apollo iOS is an open-source for native client applications, written in Swift.

executes queries and using a and returns results as pre-generated and -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!

also includes caching mechanisms specifically for data, enabling you to execute GraphQL queries against your locally cached data directly.

Installation

Key features

has three key features:

Used together, these features dramatically improve the process of requesting, consuming, and persisting data.

Code generation

generates objects based on the you define, providing a type-safe way to use operations in your code.

Each generated object contains a set of robust, strongly-typed models for that operation's response. These models enable you to access your response data in a type-safe and flexible way.

Because generated response models are -specific, they only include properties for the within that . This means you can rely on the Swift type checker to flag data access errors at compile time.

also generates models for your fragments. Using models alongside your -specific models enables you to share common models across multiple operations.

additionally generates models for your schema's input, enum, and custom types, all of which help improve your code's type-safety.

The normalized cache

's normalized cache is designed specifically for . It normalizes results to build a client-side cache of your data, updating with every operation you execute.

's cache de-duplicates responses, merging data from separate GraphQL into normalized objects. This enables your cache to stay up-to-date with your backend with as few operations as possible.

The of objects across means that your cache acts as a source of truth for your , enabling your application to react to changes in real-time.

To learn more about the process, see our blog post Demystifying Cache Normalization.

Networking and GraphQL execution

provides a networking API that helps you execute against any spec-compliant . 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.

handles all the heavy lifting of networking with , including:

  • Constructing spec-compliant network requests
  • Checking for existing data in the normalized cache
  • Executing network transport
  • Parsing and validating network responses
  • Exposing errors as type-safe Swift errors
  • Writing response data to the normalized cache
  • Mapping response data onto type-safe, generated models

Apollo Kotlin is a for native Android apps written in Java and Kotlin, and it also supports the Kotlin Multi-Platform integration.

's integration for React also works with React Native on both iOS and Android.

Next
Get Started
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company