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

GraphQL on iOS With Apollo

GraphQL on iOS With Apollo

Learnings from using GraphQL with Swift in production. Plus an introduction to GraphQL and the Apollo toolchain.

Alek Åström

July 03, 2017
Tweet

More Decks by Alek Åström

Other Decks in Programming

Transcript

  1. /users/:id id: ID name: String repositories: [URL] /repositories/:id id: ID

    stars: Int issues: [URL] /issues/:id id: ID title: String comments: [URL] /issues/:id/comments id: ID body: String author: ID reactions: [Reaction] REST Endpoints API calls
  2. /users/:id id: ID name: String repositories: [URL] /repositories/:id id: ID

    stars: Int issues: [URL] /issues/:id id: ID title: String comments: [URL] /issues/:id/comments id: ID body: String author: ID reactions: [Reaction] REST Endpoints
  3. /users/:id id: ID name: String repositories: [URL] /repositories/:id id: ID

    stars: Int issues: [URL] /issues/:id id: ID title: String comments: [URL] /issues/:id/comments id: ID body: String author: ID reactions: [Reaction] GraphQL me (root) User id: ID name: String repositories: [Repository] Repository id: ID stars: Int issues: [Issue] Issue id: ID title: String comments: [Comment] Comment id: ID body: String author: User reactions: [Reaction]
  4. Query Response { "me": { "name": "Alek Åström", "age": 27,

    "twitterHandle": "@MisterAlek" } } query { me { name age twitterHandle } }
  5. Type safety! • Int, Float, String, Bool, Array, Object, Enum

    • Required: String, String! • Custom scalars: Date (”2017-01-01”) • Interfaces (Car implements Vehicle) • Unions (Cat|Dog|Turtle)
  6. GraphQL in short • Server exposes all of its capabilities

    • No more guesswork on client needs • Spec = implementation • Type safety
  7. Apollo iOS • Swift Client Framework • Codegen • Query

    validation • Typesafe parsing • Xcode Plugin – syntax highlighting
  8. To the skeptics • Expect to use forks & contribute

    back • Lacks multipart file uploads • Error handling on server end can improve • Apollo iOS moves fast
  9. Learnings • Not parsing JSON is bliss • API design

    has been democratised • Deprecations instead of v1, v2 • Mock on the server (if you want) • Start small
  10. Resources + extras • graphql.org • apollodata.com + GitHub &

    Youtube • Interfacing with GraphQL by Sommer Panage @ Swift Summit • GraphQL IDE • awesome-graphql on GitHub
  11. Image credits • Slide 5: https://apiblueprint.org • Slide 8: https://github.com/facebook/graphql/

    tree/master/resources • Slide 9: http://www.slidedeck.io/lowsky/deck- graphql-relay-talk • Slide 18: http://www.apollodata.com • Slide 23: http://justsomething.co/guy-replaced- guns-with-thumbs-up/