Slide 1

Slide 1 text

iOS GraphQL in Practice Or why you should finally let REST in Peace

Slide 2

Slide 2 text

Hello, I’m @MisterAlek

Slide 3

Slide 3 text

Bye bookkeeping. Hello Dooer! WE’RE LIVE!

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Specification Implementation Theory

Slide 6

Slide 6 text

Specification Implementation Theory

Slide 7

Slide 7 text

Specification Implementation The great divide

Slide 8

Slide 8 text

GraphQL

Slide 9

Slide 9 text

2012

Slide 10

Slide 10 text

Alternative to REST

Slide 11

Slide 11 text

/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

Slide 12

Slide 12 text

/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

Slide 13

Slide 13 text

/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]

Slide 14

Slide 14 text

query { me { name age twitterHandle } }

Slide 15

Slide 15 text

Query Response { "me": { "name": "Alek Åström", "age": 27, "twitterHandle": "@MisterAlek" } } query { me { name age twitterHandle } }

Slide 16

Slide 16 text

Demo GitHub API

Slide 17

Slide 17 text

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)

Slide 18

Slide 18 text

GraphQL in short • Server exposes all of its capabilities • No more guesswork on client needs • Spec = implementation • Type safety

Slide 19

Slide 19 text

How come we aren’t using this already?

Slide 20

Slide 20 text

Apollo

Slide 21

Slide 21 text

Apollo iOS

Slide 22

Slide 22 text

Apollo iOS • Swift Client Framework • Codegen • Query validation • Typesafe parsing • Xcode Plugin – syntax highlighting

Slide 23

Slide 23 text

Demo

Slide 24

Slide 24 text

To the skeptics • Expect to use forks & contribute back • Lacks multipart file uploads • Error handling on server end can improve • Apollo iOS moves fast

Slide 25

Slide 25 text

Is it ready for production?

Slide 26

Slide 26 text

Is it ready for production? YES

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

Resources + extras • graphql.org • apollodata.com + GitHub & Youtube • Interfacing with GraphQL by Sommer Panage @ Swift Summit • GraphQL IDE • awesome-graphql on GitHub

Slide 29

Slide 29 text

@MisterAlek @enhorn @_fwal You? #mobile ✌

Slide 30

Slide 30 text

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/

Slide 31

Slide 31 text

Thank you!

Slide 32

Slide 32 text

No content