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
}
}
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