Apollo Client is a GraphQL client library for iOS that enables executing GraphQL operations and mapping responses to strongly typed Swift models.
Apollo acts as the bridge between the iOS app and a GraphQL server by:
.graphql filesApolloClient
Main entry point for executing GraphQL operations
Generated Models
Swift types generated from .graphql queries
Network Transport
Handles HTTP requests to the GraphQL endpoint
Apollo Store (optional)
Provides caching and normalized data storage
import Apollo
let apollo = ApolloClient(url: URL(string: "<https://countries.trevorblades.com/>")!)
apollo.fetch(query: GetCountriesQuery()) { result in
switch result {
case .success(let graphQLResult):
print(graphQLResult.data?.countries)
case .failure(let error):
print(error)
}
}