SlideShare a Scribd company logo
1 of 49
Download to read offline
Interfacing with GraphQL in Swift
Sommer Panage • @sommer
1 — Sommer Panage • @sommer • Swift Summit 2016
Hello!
2 — Sommer Panage • @sommer • Swift Summit 2016
What is GraphQL?
3 — Sommer Panage • @sommer • Swift Summit 2016
The GraphQL Schema
type User {
name: String!
id: Int!
email: String
twitter: String
}
4 — Sommer Panage • @sommer • Swift Summit 2016
Instead of hitting a REST endpoint like...
https://mybackend.com/api/user?id=1
5 — Sommer Panage • @sommer • Swift Summit 2016
I write a query like...
{
user(id: 1) {
name
email
twitter
}
}
And send it to my GraphQL endpoint
https://mybackend.com/graphql
6 — Sommer Panage • @sommer • Swift Summit 2016
And I get back a JSON response like...
{
"data": {
"name": "Sommer Panage",
"email": "sommer@panage.org",
"twitter": "@sommer"
}
}
7 — Sommer Panage • @sommer • Swift Summit 2016
Why is GraphQL such a
big deal for mobile?
8 — Sommer Panage • @sommer • Swift Summit 2016
Let's write an app
9 — Sommer Panage • @sommer • Swift Summit 2016
In a REST world, we'd hit this endpoint:
http://swapi.co/api/people/1/
And we'd get back...
10 — Sommer Panage • @sommer • Swift Summit 2016
{
"name": "Luke Skywalker",
"height": "1.72 m",
"mass": "77 Kg",
"hair_color": "Blond",
"skin_color": "Caucasian",
"eye_color": "Blue",
"birth_year": "19 BBY",
"gender": "Male",
"homeworld": "http://swapi.co/api/planets/1/",
"films": [
"http://swapi.co/api/films/1/",
"http://swapi.co/api/films/2/",
"http://swapi.co/api/films/3/"
],
"species": [
"http://swapi.co/api/species/1/"
],
"vehicles": [
"http://swapi.co/api/vehicles/14/",
"http://swapi.co/api/vehicles/30/"
],
"starships": [
"http://swapi.co/api/starships/12/",
"http://swapi.co/api/starships/22/"
],
"created": "2014-12-09T13:50:51.644000Z",
"edited": "2014-12-10T13:52:43.172000Z",
"url": "http://swapi.co/api/people/1/",
"image_url": "http://static.srcdn.com/wp-content/uploads/luke-skywalker-star-wars-a-new-hope.jpg"
}
11 — Sommer Panage • @sommer • Swift Summit 2016
And then...we'd make two more calls to...
http://swapi.co/api/starships/12/
and
http://swapi.co/api/starships/22/
12 — Sommer Panage • @sommer • Swift Summit 2016
{
"name": "X-wing",
"model": "T-65 X-wing",
"manufacturer": "Incom Corporation",
"cost_in_credits": "149999",
"length": "12.5",
"max_atmosphering_speed": "1050",
"crew": "1",
"passengers": "0",
"cargo_capacity": "110",
"consumables": "1 week",
"hyperdrive_rating": "1.0",
"MGLT": "100",
"starship_class": "Starfighter",
"pilots": [
"http://swapi.co/api/people/1/",
"http://swapi.co/api/people/9/",
"http://swapi.co/api/people/18/",
"http://swapi.co/api/people/19/"
],
"films": [
"http://swapi.co/api/films/3/",
"http://swapi.co/api/films/2/",
"http://swapi.co/api/films/1/"
],
"created": "2014-12-12T11:19:05.340000Z",
"edited": "2014-12-22T17:35:44.491233Z",
"url": "http://swapi.co/api/starships/12/"
}
13 — Sommer Panage • @sommer • Swift Summit 2016
{
"name": "Imperial shuttle",
"model": "Lambda-class T-4a shuttle",
"manufacturer": "Sienar Fleet Systems",
"cost_in_credits": "240000",
"length": "20",
"max_atmosphering_speed": "850",
"crew": "6",
"passengers": "20",
"cargo_capacity": "80000",
"consumables": "2 months",
"hyperdrive_rating": "1.0",
"MGLT": "50",
"starship_class": "Armed government transport",
"pilots": [
"http://swapi.co/api/people/1/",
"http://swapi.co/api/people/13/",
"http://swapi.co/api/people/14/"
],
"films": [
"http://swapi.co/api/films/3/",
"http://swapi.co/api/films/2/"
],
"created": "2014-12-15T13:04:47.235000Z",
"edited": "2014-12-22T17:35:44.795405Z",
"url": "http://swapi.co/api/starships/22/"
}
14 — Sommer Panage • @sommer • Swift Summit 2016
That's 3 calls and a whole lot of data for 1 little VC
15 — Sommer Panage • @sommer • Swift Summit 2016
Now in GraphQL, instead we'd write the following query:
{
person(personID: 1) {
name,
height,
mass,
hairColor,
eyeColor,
imageURL,
starshipConnection {
edges {
node {
name
}
}
}
}
}
16 — Sommer Panage • @sommer • Swift Summit 2016
And, I'd get back exactly what I wanted!
{
"data": {
"person": {
"name": "Luke Skywalker",
"height": 172,
"mass": 77,
"hairColor": "blond",
"eyeColor": "blue",
"imageURL": "http://static.srcdn.com/wp-content/uploads/luke-skywalker-star-wars-a-new-hope.jpg",
"starshipConnection": {
"edges": [
{
"node": {
"name": "X-wing"
}
},
{
"node": {
"name": "Imperial shuttle"
}
}
]
}
}
}
}
17 — Sommer Panage • @sommer • Swift Summit 2016
So, why is GraphQL such a big deal for mobile?
1. Ask and ye shall receive!
2. Fewer round trips!
3. Less client logic around data!
18 — Sommer Panage • @sommer • Swift Summit 2016
Wait just a minute...
19 — Sommer Panage • @sommer • Swift Summit 2016
Our Star Wars Character model
struct SWCharacter {
let name: String
let heightInCm: Int
let massInKg: Int
let hairColorDescriptor: String
let skinColorDescriptor: String
let eyeColorDescriptor: String
let birthYear: StarWarsUniverse.Year
let gender: StarWarsUniverse.Gender
let homeworld: StarWarsUniverse.Planet
let films: [SWFilm]
let species: [StarWarsUniverse.Species]
let vehicles: [StarWarsUniverse.Vehicle]
let starships: [StarWarsUniverse.Starship]
let imageURL: URL?
}
20 — Sommer Panage • @sommer • Swift Summit 2016
Our Star Wars Character model
struct SWCharacter {
let name: String?
let heightInCm: Int?
let massInKg: Int?
let hairColorDescriptor: String?
let skinColorDescriptor: String?
let eyeColorDescriptor: String
let birthYear: StarWarsUniverse.Year?
let gender: StarWarsUniverse.Gender?
let homeworld: StarWarsUniverse.Planet?
let films: [SWFilm]?
let species: [StarWarsUniverse.Species]?
let vehicles: [StarWarsUniverse.Vehicle]?
let starships: [StarWarsUniverse.Starship]?
let imageURL: URL?
}
21 — Sommer Panage • @sommer • Swift Summit 2016
Swift, No!!!!
struct SWCharacter {
let name: String?
let heightInCm: Int?
let massInKg: Int?
let hairColorDescriptor: String?
let skinColorDescriptor: String?
let eyeColorDescriptor: String
let birthYear: StarWarsUniverse.Year?
let gender: StarWarsUniverse.Gender?
let homeworld: StarWarsUniverse.Planet?
let films: [SWFilm]?
let species: [StarWarsUniverse.Species]?
let vehicles: [StarWarsUniverse.Vehicle]?
let starships: [StarWarsUniverse.Starship]?
let imageURL: URL?
}
22 — Sommer Panage • @sommer • Swift Summit 2016
23 — Sommer Panage • @sommer • Swift Summit 2016
Let's model the data how we want it, not how it is
→ 1 View Controller
→ 1 Query
→ 1 Data Model
24 — Sommer Panage • @sommer • Swift Summit 2016
25 — Sommer Panage • @sommer • Swift Summit 2016
query AllCharacters {
allPeople {
edges {
node {
id
name
homeworld {
name
}
}
}
}
}
26 — Sommer Panage • @sommer • Swift Summit 2016
struct AllCharactersData {
let people: [Person]
struct Person {
let id: String
let name: String
let homeworld: Homeworld
struct Homeworld {
let name: String
}
}
}
27 — Sommer Panage • @sommer • Swift Summit 2016
query Character($id: ID) {
person (id: $id) {
id
height,
mass,
hairColor,
eyeColor,
imageURL,
starshipConnection {
edges {
node {
name
}
}
}
}
}
28 — Sommer Panage • @sommer • Swift Summit 2016
struct CharacterData {
struct Person {
let id: String
let height: Int
let mass: Int
let hairColor: String
let eyeColor: String
let imageURL: URL?
let starshipConnect: [Starship]
struct Starship {
let name: String
}
}
}
29 — Sommer Panage • @sommer • Swift Summit 2016
By having query / view-
data based models, we
no longer need optionals
everywhere!
30 — Sommer Panage • @sommer • Swift Summit 2016
But our parsing code still looks like...
let parsedData = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
self.id = parsedData["id"] as! String
self.name = parsedData["name"] as! String
self.homeworld = Homeworld(dict: parsedData["homeworld"] as! [String : Any])
Ugh!
31 — Sommer Panage • @sommer • Swift Summit 2016
Code Gen!
32 — Sommer Panage • @sommer • Swift Summit 2016
33 — Sommer Panage • @sommer • Swift Summit 2016
Apollo's iOS GraphQL Client for Swift
→ Compile-time safety
→ Inline validation errors for GraphQL
→ No wasted cycles on query-gen
34 — Sommer Panage • @sommer • Swift Summit 2016
What about...?
35 — Sommer Panage • @sommer • Swift Summit 2016
Versioning
→ "Version-Free"
→ Easy to test for backwards compatability
36 — Sommer Panage • @sommer • Swift Summit 2016
Caching
37 — Sommer Panage • @sommer • Swift Summit 2016
Simple Caching
Query-based, not object based
38 — Sommer Panage • @sommer • Swift Summit 2016
Advanced Caching
Flattened results, id-record mapped
39 — Sommer Panage • @sommer • Swift Summit 2016
Aren't you supposed to
use GraphQL with React
Native?
40 — Sommer Panage • @sommer • Swift Summit 2016
GraphQL + Swift
-> GraphQL shines on mobile
-> Swift gives us types and compile time safety
-> React Native is new and exciting, but that comes
with challenges too
41 — Sommer Panage • @sommer • Swift Summit 2016
In
Conclusion...
42 — Sommer Panage • @sommer • Swift Summit 2016
Pros to GraphQL + Swift
→ Fewer requests for data
→ Getting the exact data you need
→ Code gen -> no janky parsing code
→ Models that are reflective of your views
→ A strongly typed backend schema
43 — Sommer Panage • @sommer • Swift Summit 2016
Cons to GraphQL + Swift
→ Not a lot of tooling yet
→ Best practices still emerging
→ Poorly defined schema becomes a big client
problem
→ Not as good for endpoints requiring heavy logic
44 — Sommer Panage • @sommer • Swift Summit 2016
tldr: It's worth
it!
45 — Sommer Panage • @sommer • Swift Summit 2016
Check out
→ Apollo iOS Client: Documentation and info on
Apollo's awesome Swift iOS GraphQL client
→ 5 benefits of static GraphQL Queries: Blog post
from Apollo
→ Bringing GraphQL to iOS: Blog post from Apollo
→ GraphQL First: A better way to build modern apps:
Blog post from Apollo
46 — Sommer Panage • @sommer • Swift Summit 2016
Check out...con’t
→ GraphQL for mobile: Blog post from Artsy
→ Relay: Thinking in GraphQL: Post from FB on
Caching
47 — Sommer Panage • @sommer • Swift Summit 2016
Thank you!!
Come ask me questions about GraphQL + Swift
or about Accessibility!
48 — Sommer Panage • @sommer • Swift Summit 2016
Credits
Images
GediminasTurbo Baltaduonis, Danil Polshin, Apple,
Facebook, Apollo, Lucasfilm
General
Chorus Fitness, Apollo, Facebook
49 — Sommer Panage • @sommer • Swift Summit 2016

More Related Content

What's hot

What's hot (20)

How to build a social network on Serverless (AWS Community Summit)
How to build a social network on Serverless (AWS Community Summit)How to build a social network on Serverless (AWS Community Summit)
How to build a social network on Serverless (AWS Community Summit)
 
Infrastructure as code
Infrastructure as codeInfrastructure as code
Infrastructure as code
 
Agile Development with OSGi
Agile Development with OSGiAgile Development with OSGi
Agile Development with OSGi
 
How to build observability into a serverless application
How to build observability into a serverless applicationHow to build observability into a serverless application
How to build observability into a serverless application
 
Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020
 
Integrating-Cloud-Development-Security-And-Operations.pdf
Integrating-Cloud-Development-Security-And-Operations.pdfIntegrating-Cloud-Development-Security-And-Operations.pdf
Integrating-Cloud-Development-Security-And-Operations.pdf
 
Concourse x Spinnaker #concourse_tokyo
Concourse x Spinnaker #concourse_tokyoConcourse x Spinnaker #concourse_tokyo
Concourse x Spinnaker #concourse_tokyo
 
Developer Experience at the Guardian, Equal Experts Sept 2021
Developer Experience at the Guardian, Equal Experts Sept 2021Developer Experience at the Guardian, Equal Experts Sept 2021
Developer Experience at the Guardian, Equal Experts Sept 2021
 
Spring ❤️ Kotlin #jjug
Spring ❤️ Kotlin #jjugSpring ❤️ Kotlin #jjug
Spring ❤️ Kotlin #jjug
 
Secure Architecture and Programming 101
Secure Architecture and Programming 101Secure Architecture and Programming 101
Secure Architecture and Programming 101
 
Istio By Example (extended version)
Istio By Example (extended version)Istio By Example (extended version)
Istio By Example (extended version)
 
Serverless Media Workflow
Serverless Media WorkflowServerless Media Workflow
Serverless Media Workflow
 
Integrating_Cloud_Development_Security_And_Operations.pdf
Integrating_Cloud_Development_Security_And_Operations.pdfIntegrating_Cloud_Development_Security_And_Operations.pdf
Integrating_Cloud_Development_Security_And_Operations.pdf
 
Secured API Acceleration with Engineers from Amazon CloudFront and Slack
Secured API Acceleration with Engineers from Amazon CloudFront and SlackSecured API Acceleration with Engineers from Amazon CloudFront and Slack
Secured API Acceleration with Engineers from Amazon CloudFront and Slack
 
Fluent 2018: When third parties stop being polite... and start getting real
Fluent 2018: When third parties stop being polite... and start getting realFluent 2018: When third parties stop being polite... and start getting real
Fluent 2018: When third parties stop being polite... and start getting real
 
Where Node.JS Meets iOS
Where Node.JS Meets iOSWhere Node.JS Meets iOS
Where Node.JS Meets iOS
 
Serverless in production, an experience report (Going Serverless)
Serverless in production, an experience report (Going Serverless)Serverless in production, an experience report (Going Serverless)
Serverless in production, an experience report (Going Serverless)
 
Patterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesPatterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservices
 
Managing your Docker image continuously with Concourse CI
Managing your Docker image continuously with Concourse CIManaging your Docker image continuously with Concourse CI
Managing your Docker image continuously with Concourse CI
 
Remove Undifferentiated Heavy Lifting from Jenkins (DEV201-R1) - AWS re:Inven...
Remove Undifferentiated Heavy Lifting from Jenkins (DEV201-R1) - AWS re:Inven...Remove Undifferentiated Heavy Lifting from Jenkins (DEV201-R1) - AWS re:Inven...
Remove Undifferentiated Heavy Lifting from Jenkins (DEV201-R1) - AWS re:Inven...
 

Viewers also liked

Viewers also liked (20)

Writing Your App Swiftly
Writing Your App SwiftlyWriting Your App Swiftly
Writing Your App Swiftly
 
GraphQL IndyJS April 2016
GraphQL IndyJS April 2016GraphQL IndyJS April 2016
GraphQL IndyJS April 2016
 
Graphql
GraphqlGraphql
Graphql
 
Zensations Drupal 8 GraphQL Presentation 2015
Zensations Drupal 8 GraphQL Presentation 2015Zensations Drupal 8 GraphQL Presentation 2015
Zensations Drupal 8 GraphQL Presentation 2015
 
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
 
GraphQL Relay Introduction
GraphQL Relay IntroductionGraphQL Relay Introduction
GraphQL Relay Introduction
 
Relay: Seamless Syncing for React (VanJS)
Relay: Seamless Syncing for React (VanJS)Relay: Seamless Syncing for React (VanJS)
Relay: Seamless Syncing for React (VanJS)
 
Work with V8 memory leaks
Work with V8 memory leaksWork with V8 memory leaks
Work with V8 memory leaks
 
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_techはじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
 
あなたのオブジェクト指向はオブジェクト指向ではないかもしれない
あなたのオブジェクト指向はオブジェクト指向ではないかもしれないあなたのオブジェクト指向はオブジェクト指向ではないかもしれない
あなたのオブジェクト指向はオブジェクト指向ではないかもしれない
 
#yidev 第25回勉強会 オープニング
#yidev 第25回勉強会 オープニング#yidev 第25回勉強会 オープニング
#yidev 第25回勉強会 オープニング
 
みんなで Swift 復習会での談笑用スライド – 3rd #minna_de_swift
みんなで Swift 復習会での談笑用スライド – 3rd #minna_de_swiftみんなで Swift 復習会での談笑用スライド – 3rd #minna_de_swift
みんなで Swift 復習会での談笑用スライド – 3rd #minna_de_swift
 
勉強会のこちら側とあちら側
勉強会のこちら側とあちら側勉強会のこちら側とあちら側
勉強会のこちら側とあちら側
 
Introduction to GraphQL at API days
Introduction to GraphQL at API daysIntroduction to GraphQL at API days
Introduction to GraphQL at API days
 
JVM言語を使ってみようの歌
JVM言語を使ってみようの歌JVM言語を使ってみようの歌
JVM言語を使ってみようの歌
 
Migration microservices to GraphQL
Migration microservices to GraphQLMigration microservices to GraphQL
Migration microservices to GraphQL
 
Java in the Past, Java in the Future
Java in the Past, Java in the FutureJava in the Past, Java in the Future
Java in the Past, Java in the Future
 
みんなで Swift 復習会での談笑用スライド – 5th #minna_de_swift
みんなで Swift 復習会での談笑用スライド – 5th #minna_de_swiftみんなで Swift 復習会での談笑用スライド – 5th #minna_de_swift
みんなで Swift 復習会での談笑用スライド – 5th #minna_de_swift
 
みんなで Swift 復習会での談笑用スライド – in 札幌 1st′ #minna_de_swift
みんなで Swift 復習会での談笑用スライド – in 札幌 1st′ #minna_de_swiftみんなで Swift 復習会での談笑用スライド – in 札幌 1st′ #minna_de_swift
みんなで Swift 復習会での談笑用スライド – in 札幌 1st′ #minna_de_swift
 
GraphQL vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs REST
 

Similar to Swift + GraphQL

Spark and MongoDB
Spark and MongoDBSpark and MongoDB
Spark and MongoDB
Norberto Leite
 
Sparkling Water 5 28-14
Sparkling Water 5 28-14Sparkling Water 5 28-14
Sparkling Water 5 28-14
Sri Ambati
 
In graph we trust: Microservices, GraphQL and security challenges
In graph we trust: Microservices, GraphQL and security challengesIn graph we trust: Microservices, GraphQL and security challenges
In graph we trust: Microservices, GraphQL and security challenges
Mohammed A. Imran
 

Similar to Swift + GraphQL (20)

SETCON'18 - Ilya labacheuski - GraphQL adventures
SETCON'18 - Ilya labacheuski - GraphQL adventuresSETCON'18 - Ilya labacheuski - GraphQL adventures
SETCON'18 - Ilya labacheuski - GraphQL adventures
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 
Symfony + GraphQL
Symfony + GraphQLSymfony + GraphQL
Symfony + GraphQL
 
Graphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiDGraphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiD
 
Web development with Lua @ Bulgaria Web Summit 2016
Web development with Lua @ Bulgaria Web Summit 2016Web development with Lua @ Bulgaria Web Summit 2016
Web development with Lua @ Bulgaria Web Summit 2016
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...
 
Into to GraphQL
Into to GraphQLInto to GraphQL
Into to GraphQL
 
Document Model for High Speed Spark Processing
Document Model for High Speed Spark ProcessingDocument Model for High Speed Spark Processing
Document Model for High Speed Spark Processing
 
Spark and MongoDB
Spark and MongoDBSpark and MongoDB
Spark and MongoDB
 
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
 
Sparkling Water 5 28-14
Sparkling Water 5 28-14Sparkling Water 5 28-14
Sparkling Water 5 28-14
 
Modernizes your objective C - Oliviero
Modernizes your objective C - OlivieroModernizes your objective C - Oliviero
Modernizes your objective C - Oliviero
 
Sparkling Water Webinar October 29th, 2014
Sparkling Water Webinar October 29th, 2014Sparkling Water Webinar October 29th, 2014
Sparkling Water Webinar October 29th, 2014
 
OpenAPI development with Python
OpenAPI development with PythonOpenAPI development with Python
OpenAPI development with Python
 
DevSecCon Singapore 2018 - in graph we trust By Imran Mohammed
DevSecCon Singapore 2018 - in graph we trust By Imran MohammedDevSecCon Singapore 2018 - in graph we trust By Imran Mohammed
DevSecCon Singapore 2018 - in graph we trust By Imran Mohammed
 
In graph we trust: Microservices, GraphQL and security challenges
In graph we trust: Microservices, GraphQL and security challengesIn graph we trust: Microservices, GraphQL and security challenges
In graph we trust: Microservices, GraphQL and security challenges
 
Testing API platform with Behat BDD tests
Testing API platform with Behat BDD testsTesting API platform with Behat BDD tests
Testing API platform with Behat BDD tests
 
Big Data Processing with .NET and Spark (SQLBits 2020)
Big Data Processing with .NET and Spark (SQLBits 2020)Big Data Processing with .NET and Spark (SQLBits 2020)
Big Data Processing with .NET and Spark (SQLBits 2020)
 

Recently uploaded

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 

Recently uploaded (20)

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 

Swift + GraphQL

  • 1. Interfacing with GraphQL in Swift Sommer Panage • @sommer 1 — Sommer Panage • @sommer • Swift Summit 2016
  • 2. Hello! 2 — Sommer Panage • @sommer • Swift Summit 2016
  • 3. What is GraphQL? 3 — Sommer Panage • @sommer • Swift Summit 2016
  • 4. The GraphQL Schema type User { name: String! id: Int! email: String twitter: String } 4 — Sommer Panage • @sommer • Swift Summit 2016
  • 5. Instead of hitting a REST endpoint like... https://mybackend.com/api/user?id=1 5 — Sommer Panage • @sommer • Swift Summit 2016
  • 6. I write a query like... { user(id: 1) { name email twitter } } And send it to my GraphQL endpoint https://mybackend.com/graphql 6 — Sommer Panage • @sommer • Swift Summit 2016
  • 7. And I get back a JSON response like... { "data": { "name": "Sommer Panage", "email": "sommer@panage.org", "twitter": "@sommer" } } 7 — Sommer Panage • @sommer • Swift Summit 2016
  • 8. Why is GraphQL such a big deal for mobile? 8 — Sommer Panage • @sommer • Swift Summit 2016
  • 9. Let's write an app 9 — Sommer Panage • @sommer • Swift Summit 2016
  • 10. In a REST world, we'd hit this endpoint: http://swapi.co/api/people/1/ And we'd get back... 10 — Sommer Panage • @sommer • Swift Summit 2016
  • 11. { "name": "Luke Skywalker", "height": "1.72 m", "mass": "77 Kg", "hair_color": "Blond", "skin_color": "Caucasian", "eye_color": "Blue", "birth_year": "19 BBY", "gender": "Male", "homeworld": "http://swapi.co/api/planets/1/", "films": [ "http://swapi.co/api/films/1/", "http://swapi.co/api/films/2/", "http://swapi.co/api/films/3/" ], "species": [ "http://swapi.co/api/species/1/" ], "vehicles": [ "http://swapi.co/api/vehicles/14/", "http://swapi.co/api/vehicles/30/" ], "starships": [ "http://swapi.co/api/starships/12/", "http://swapi.co/api/starships/22/" ], "created": "2014-12-09T13:50:51.644000Z", "edited": "2014-12-10T13:52:43.172000Z", "url": "http://swapi.co/api/people/1/", "image_url": "http://static.srcdn.com/wp-content/uploads/luke-skywalker-star-wars-a-new-hope.jpg" } 11 — Sommer Panage • @sommer • Swift Summit 2016
  • 12. And then...we'd make two more calls to... http://swapi.co/api/starships/12/ and http://swapi.co/api/starships/22/ 12 — Sommer Panage • @sommer • Swift Summit 2016
  • 13. { "name": "X-wing", "model": "T-65 X-wing", "manufacturer": "Incom Corporation", "cost_in_credits": "149999", "length": "12.5", "max_atmosphering_speed": "1050", "crew": "1", "passengers": "0", "cargo_capacity": "110", "consumables": "1 week", "hyperdrive_rating": "1.0", "MGLT": "100", "starship_class": "Starfighter", "pilots": [ "http://swapi.co/api/people/1/", "http://swapi.co/api/people/9/", "http://swapi.co/api/people/18/", "http://swapi.co/api/people/19/" ], "films": [ "http://swapi.co/api/films/3/", "http://swapi.co/api/films/2/", "http://swapi.co/api/films/1/" ], "created": "2014-12-12T11:19:05.340000Z", "edited": "2014-12-22T17:35:44.491233Z", "url": "http://swapi.co/api/starships/12/" } 13 — Sommer Panage • @sommer • Swift Summit 2016
  • 14. { "name": "Imperial shuttle", "model": "Lambda-class T-4a shuttle", "manufacturer": "Sienar Fleet Systems", "cost_in_credits": "240000", "length": "20", "max_atmosphering_speed": "850", "crew": "6", "passengers": "20", "cargo_capacity": "80000", "consumables": "2 months", "hyperdrive_rating": "1.0", "MGLT": "50", "starship_class": "Armed government transport", "pilots": [ "http://swapi.co/api/people/1/", "http://swapi.co/api/people/13/", "http://swapi.co/api/people/14/" ], "films": [ "http://swapi.co/api/films/3/", "http://swapi.co/api/films/2/" ], "created": "2014-12-15T13:04:47.235000Z", "edited": "2014-12-22T17:35:44.795405Z", "url": "http://swapi.co/api/starships/22/" } 14 — Sommer Panage • @sommer • Swift Summit 2016
  • 15. That's 3 calls and a whole lot of data for 1 little VC 15 — Sommer Panage • @sommer • Swift Summit 2016
  • 16. Now in GraphQL, instead we'd write the following query: { person(personID: 1) { name, height, mass, hairColor, eyeColor, imageURL, starshipConnection { edges { node { name } } } } } 16 — Sommer Panage • @sommer • Swift Summit 2016
  • 17. And, I'd get back exactly what I wanted! { "data": { "person": { "name": "Luke Skywalker", "height": 172, "mass": 77, "hairColor": "blond", "eyeColor": "blue", "imageURL": "http://static.srcdn.com/wp-content/uploads/luke-skywalker-star-wars-a-new-hope.jpg", "starshipConnection": { "edges": [ { "node": { "name": "X-wing" } }, { "node": { "name": "Imperial shuttle" } } ] } } } } 17 — Sommer Panage • @sommer • Swift Summit 2016
  • 18. So, why is GraphQL such a big deal for mobile? 1. Ask and ye shall receive! 2. Fewer round trips! 3. Less client logic around data! 18 — Sommer Panage • @sommer • Swift Summit 2016
  • 19. Wait just a minute... 19 — Sommer Panage • @sommer • Swift Summit 2016
  • 20. Our Star Wars Character model struct SWCharacter { let name: String let heightInCm: Int let massInKg: Int let hairColorDescriptor: String let skinColorDescriptor: String let eyeColorDescriptor: String let birthYear: StarWarsUniverse.Year let gender: StarWarsUniverse.Gender let homeworld: StarWarsUniverse.Planet let films: [SWFilm] let species: [StarWarsUniverse.Species] let vehicles: [StarWarsUniverse.Vehicle] let starships: [StarWarsUniverse.Starship] let imageURL: URL? } 20 — Sommer Panage • @sommer • Swift Summit 2016
  • 21. Our Star Wars Character model struct SWCharacter { let name: String? let heightInCm: Int? let massInKg: Int? let hairColorDescriptor: String? let skinColorDescriptor: String? let eyeColorDescriptor: String let birthYear: StarWarsUniverse.Year? let gender: StarWarsUniverse.Gender? let homeworld: StarWarsUniverse.Planet? let films: [SWFilm]? let species: [StarWarsUniverse.Species]? let vehicles: [StarWarsUniverse.Vehicle]? let starships: [StarWarsUniverse.Starship]? let imageURL: URL? } 21 — Sommer Panage • @sommer • Swift Summit 2016
  • 22. Swift, No!!!! struct SWCharacter { let name: String? let heightInCm: Int? let massInKg: Int? let hairColorDescriptor: String? let skinColorDescriptor: String? let eyeColorDescriptor: String let birthYear: StarWarsUniverse.Year? let gender: StarWarsUniverse.Gender? let homeworld: StarWarsUniverse.Planet? let films: [SWFilm]? let species: [StarWarsUniverse.Species]? let vehicles: [StarWarsUniverse.Vehicle]? let starships: [StarWarsUniverse.Starship]? let imageURL: URL? } 22 — Sommer Panage • @sommer • Swift Summit 2016
  • 23. 23 — Sommer Panage • @sommer • Swift Summit 2016
  • 24. Let's model the data how we want it, not how it is → 1 View Controller → 1 Query → 1 Data Model 24 — Sommer Panage • @sommer • Swift Summit 2016
  • 25. 25 — Sommer Panage • @sommer • Swift Summit 2016
  • 26. query AllCharacters { allPeople { edges { node { id name homeworld { name } } } } } 26 — Sommer Panage • @sommer • Swift Summit 2016
  • 27. struct AllCharactersData { let people: [Person] struct Person { let id: String let name: String let homeworld: Homeworld struct Homeworld { let name: String } } } 27 — Sommer Panage • @sommer • Swift Summit 2016
  • 28. query Character($id: ID) { person (id: $id) { id height, mass, hairColor, eyeColor, imageURL, starshipConnection { edges { node { name } } } } } 28 — Sommer Panage • @sommer • Swift Summit 2016
  • 29. struct CharacterData { struct Person { let id: String let height: Int let mass: Int let hairColor: String let eyeColor: String let imageURL: URL? let starshipConnect: [Starship] struct Starship { let name: String } } } 29 — Sommer Panage • @sommer • Swift Summit 2016
  • 30. By having query / view- data based models, we no longer need optionals everywhere! 30 — Sommer Panage • @sommer • Swift Summit 2016
  • 31. But our parsing code still looks like... let parsedData = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any] self.id = parsedData["id"] as! String self.name = parsedData["name"] as! String self.homeworld = Homeworld(dict: parsedData["homeworld"] as! [String : Any]) Ugh! 31 — Sommer Panage • @sommer • Swift Summit 2016
  • 32. Code Gen! 32 — Sommer Panage • @sommer • Swift Summit 2016
  • 33. 33 — Sommer Panage • @sommer • Swift Summit 2016
  • 34. Apollo's iOS GraphQL Client for Swift → Compile-time safety → Inline validation errors for GraphQL → No wasted cycles on query-gen 34 — Sommer Panage • @sommer • Swift Summit 2016
  • 35. What about...? 35 — Sommer Panage • @sommer • Swift Summit 2016
  • 36. Versioning → "Version-Free" → Easy to test for backwards compatability 36 — Sommer Panage • @sommer • Swift Summit 2016
  • 37. Caching 37 — Sommer Panage • @sommer • Swift Summit 2016
  • 38. Simple Caching Query-based, not object based 38 — Sommer Panage • @sommer • Swift Summit 2016
  • 39. Advanced Caching Flattened results, id-record mapped 39 — Sommer Panage • @sommer • Swift Summit 2016
  • 40. Aren't you supposed to use GraphQL with React Native? 40 — Sommer Panage • @sommer • Swift Summit 2016
  • 41. GraphQL + Swift -> GraphQL shines on mobile -> Swift gives us types and compile time safety -> React Native is new and exciting, but that comes with challenges too 41 — Sommer Panage • @sommer • Swift Summit 2016
  • 42. In Conclusion... 42 — Sommer Panage • @sommer • Swift Summit 2016
  • 43. Pros to GraphQL + Swift → Fewer requests for data → Getting the exact data you need → Code gen -> no janky parsing code → Models that are reflective of your views → A strongly typed backend schema 43 — Sommer Panage • @sommer • Swift Summit 2016
  • 44. Cons to GraphQL + Swift → Not a lot of tooling yet → Best practices still emerging → Poorly defined schema becomes a big client problem → Not as good for endpoints requiring heavy logic 44 — Sommer Panage • @sommer • Swift Summit 2016
  • 45. tldr: It's worth it! 45 — Sommer Panage • @sommer • Swift Summit 2016
  • 46. Check out → Apollo iOS Client: Documentation and info on Apollo's awesome Swift iOS GraphQL client → 5 benefits of static GraphQL Queries: Blog post from Apollo → Bringing GraphQL to iOS: Blog post from Apollo → GraphQL First: A better way to build modern apps: Blog post from Apollo 46 — Sommer Panage • @sommer • Swift Summit 2016
  • 47. Check out...con’t → GraphQL for mobile: Blog post from Artsy → Relay: Thinking in GraphQL: Post from FB on Caching 47 — Sommer Panage • @sommer • Swift Summit 2016
  • 48. Thank you!! Come ask me questions about GraphQL + Swift or about Accessibility! 48 — Sommer Panage • @sommer • Swift Summit 2016
  • 49. Credits Images GediminasTurbo Baltaduonis, Danil Polshin, Apple, Facebook, Apollo, Lucasfilm General Chorus Fitness, Apollo, Facebook 49 — Sommer Panage • @sommer • Swift Summit 2016