Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Apollo iOS

Apollo iOS

A brief introduction to the Apollo iOS library, a strongly-typed, caching GraphQL cliente for native iOS apps, written in Swift.

Ricardo Gherke Filho
github.com/ricardo0100
linkedin.com/in/ricardo0100/

Cheesecake Labs

August 24, 2017
Tweet

More Decks by Cheesecake Labs

Other Decks in Technology

Transcript

  1. Ricardo Gehrke Filho “Apollo iOS is a strongly-typed, caching GraphQL

    client for native iOS apps, written in Swift.”
  2. type Post { id: ID! title: String! content: String! comments:

    [Comment!]! } type Comment { id: ID! text: String! post: Post! } query getAllPosts { allPosts { title content comments { text } } }
  3. { "data": { "allPosts": [ { "title": “Mission Apollo", "content":

    "Apollo ran from 1961 to 1972.", "comments": [ { "text": "Nice article!" } ] }, { "title": "International Space Station”, "content": "Its first component launched into orbit in 1998.”, "comments": [] } ] } }
  4. query getAllPosts { allPosts { title content } } public

    struct PostDetails: GraphQLFragment { public var title: String public var content: String } } apolo_codegen Type Generation
  5. Cache • Cache first: show cached data while fetching •

    Prefetch data: prepare data that will probably be used before using it • Avoid heavy requests: Fetch only data that is not in cache
  6. Normalized Caching & Automatic UI updates apollo.fetch(query: HeroNameQuery(episode: .empire)) {

    (result, error) in print(data?.hero?.name) // Luke Skywalker } let watcher = apollo.watch(query: HeroNameQuery(episode: .empire)) { (result, error) in print(data?.hero?.name) // Luke Skywalker } Fetch Watch Mutation
  7. 1. Install the Apollo framework into your project and link

    it to your application target 2. Install apollo-codegen globally through npm 3. Add a code generation build step to your target 4. Add a schema file to your target directory 5. Build your target 6. Add the generated API file to your target 7. Install the Xcode add-ons to get syntax highlighting for your .graphql files (optional) 8. Create .graphql files with your queries or mutations and add them to your target Setup