Slide 1

Slide 1 text

⚒ Digging in to the Apollo iOS SDK GraphQL Summit | San Francisco, CA | October 2019 by Ellen Shapiro | @DesignatedNerd | apollographql.com

Slide 2

Slide 2 text

!

Slide 3

Slide 3 text

!

Slide 4

Slide 4 text

!

Slide 5

Slide 5 text

!

Slide 6

Slide 6 text

!

Slide 7

Slide 7 text

!

Slide 8

Slide 8 text

!

Slide 9

Slide 9 text

! "

Slide 10

Slide 10 text

!

Slide 11

Slide 11 text

!

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

! ☠

Slide 14

Slide 14 text

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

May 1, 2019

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

!

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

!

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

October 30, 2019

Slide 25

Slide 25 text

What Changed?

Slide 26

Slide 26 text

Getting Started

Slide 27

Slide 27 text

Adding an iOS library, normally 1. Install dependency using one of: → pod install → carthage checkout → swift build

Slide 28

Slide 28 text

Adding an iOS library, normally 1. Install dependency using one of: → pod install → carthage checkout → swift build 2. Use library.

Slide 29

Slide 29 text

Code Generation

Slide 30

Slide 30 text

schema + queries = code

Slide 31

Slide 31 text

schema + queries + = code

Slide 32

Slide 32 text

! Type Safety through the whole stack

Slide 33

Slide 33 text

Codegen needs to know

Slide 34

Slide 34 text

Codegen needs to know → Where is the schema file?

Slide 35

Slide 35 text

Codegen needs to know → Where is the schema file? → Where are the query files?

Slide 36

Slide 36 text

Codegen needs to know → Where is the schema file? → Where are the query files? → Where should generated code be output?

Slide 37

Slide 37 text

Codegen needs to know → Where is the schema file? → Where are the query files? → Where should generated code be output? → Any other options which are available from the codegen library

Slide 38

Slide 38 text

Node + TypeScript

Slide 39

Slide 39 text

! " !

Slide 40

Slide 40 text

Adding apollo-ios before

Slide 41

Slide 41 text

Adding apollo-ios before 1. Install dependency

Slide 42

Slide 42 text

Adding apollo-ios before 1. Install dependency 2. Add build script

Slide 43

Slide 43 text

Adding apollo-ios before 1. Install dependency 2. Add build script 3. npm install apollo

Slide 44

Slide 44 text

Adding apollo-ios before 1. Install dependency 2. Add build script 3. npm install apollo 4. brew install npm

Slide 45

Slide 45 text

Adding apollo-ios before 1. Install dependency 2. Add build script 3. npm install apollo 4. brew install npm 5. Google how to install Homebrew

Slide 46

Slide 46 text

Adding apollo-ios before 1. Install dependency 2. Add build script 3. npm install apollo 4. brew install npm 5. Google how to install Homebrew 6.

Slide 47

Slide 47 text

Adding apollo-ios before 1. Install dependency 2. Add build script 3. npm install apollo

Slide 48

Slide 48 text

Adding apollo-ios before 1. Install dependency 2. Add build script 3. npm install apollo 4. Wait, what version of the CLI is this?

Slide 49

Slide 49 text

Adding apollo-ios before 1. Install dependency 2. Add build script 3. npm install apollo 4. Wait, what version of the CLI is this? 5. How do I tell what's installed globally vs locally?

Slide 50

Slide 50 text

Adding apollo-ios before 1. Install dependency 2. Add build script 3. npm install apollo 4. Wait, what version of the CLI is this? 5. How do I tell what's installed globally vs locally? 6.

Slide 51

Slide 51 text

!

Slide 52

Slide 52 text

!

Slide 53

Slide 53 text

! ⬇ npm

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Adding apollo-ios now

Slide 58

Slide 58 text

Adding apollo-ios now 1. Install dependency

Slide 59

Slide 59 text

Adding apollo-ios now 1. Install dependency 2. Add build script that calls run-bundled-codegen.sh

Slide 60

Slide 60 text

Adding apollo-ios now 1. Install dependency 2. Add build script that calls run-bundled-codegen.sh 3. Apollo downloads and unzips the correct version of the CLI, all dependencies, and a node runtime.

Slide 61

Slide 61 text

Adding apollo-ios now 1. Install dependency 2. Add build script that calls run-bundled-codegen.sh 3. Apollo downloads and unzips the correct version of the CLI, all dependencies, and a node runtime. 4. Use library.

Slide 62

Slide 62 text

!

Slide 63

Slide 63 text

Difficult Concepts need better explanations

Slide 64

Slide 64 text

Double Optionals??

Slide 65

Slide 65 text

public struct ReviewInput: GraphQLMapConvertible { public init(stars: Int, commentary: Optional = nil, favoriteColor: Optional = nil) { // code } }

Slide 66

Slide 66 text

Optional

Slide 67

Slide 67 text

String??

Slide 68

Slide 68 text

Optional>

Slide 69

Slide 69 text

Optional> Outer optional: "Is a value even being included for this?"

Slide 70

Slide 70 text

Optional> Inner optional: "A value was included. Is it nil or String?"

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

public struct ReviewInput: GraphQLMapConvertible { public init(stars: Int, commentary: Optional = nil, favoriteColor: Optional = nil) { // code } }

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

GraphQL fields are nullable by default

Slide 78

Slide 78 text

A nullable field can be absent

Slide 79

Slide 79 text

public struct ReviewInput: GraphQLMapConvertible { public init(stars: Int, commentary: Optional = nil, favoriteColor: Optional = nil) { // code } }

Slide 80

Slide 80 text

ReviewInput(stars: 5) // { "stars": 5 } ReviewInput(stars: 2, commentary: "Needs more ewoks") // { "stars": 2, "commentary": "Needs more ewoks" } ReviewInput(stars: 3, commentary: nil) // { "stars": 3 } ReviewInput(stars: 4, commentary: .some(nil)) // { "stars": 4, "commentary": null }

Slide 81

Slide 81 text

ReviewInput(stars: 5) // { "stars": 5 } ReviewInput(stars: 2, commentary: "Needs more ewoks") // { "stars": 2, "commentary": "Needs more ewoks" } ReviewInput(stars: 3, commentary: nil) // { "stars": 3 } ReviewInput(stars: 4, commentary: .some(nil)) // { "stars": 4, "commentary": null }

Slide 82

Slide 82 text

ReviewInput(stars: 5) // { "stars": 5 } ReviewInput(stars: 2, commentary: "Needs more ewoks") // { "stars": 2, "commentary": "Needs more ewoks" } ReviewInput(stars: 3, commentary: nil) // { "stars": 3 } ReviewInput(stars: 4, commentary: .some(nil)) // { "stars": 4, "commentary": null }

Slide 83

Slide 83 text

ReviewInput(stars: 5) // { "stars": 5 } ReviewInput(stars: 2, commentary: "Needs more ewoks") // { "stars": 2, "commentary": "Needs more ewoks" } ReviewInput(stars: 3, commentary: nil) // { "stars": 3 } ReviewInput(stars: 4, commentary: .some(nil)) // { "stars": 4, "commentary": null }

Slide 84

Slide 84 text

ReviewInput(stars: 5) // { "stars": 5 } ReviewInput(stars: 2, commentary: "Needs more ewoks") // { "stars": 2, "commentary": "Needs more ewoks" } ReviewInput(stars: 3, commentary: nil) // { "stars": 3 } ReviewInput(stars: 4, commentary: .some(nil)) // { "stars": 4, "commentary": null }

Slide 85

Slide 85 text

ReviewInput(stars: 5) // { "stars": 5 } ReviewInput(stars: 2, commentary: "Needs more ewoks") // { "stars": 2, "commentary": "Needs more ewoks" } ReviewInput(stars: 3, commentary: nil) // { "stars": 3 } ReviewInput(stars: 4, commentary: .some(nil)) // { "stars": 4, "commentary": null }

Slide 86

Slide 86 text

Caching

Slide 87

Slide 87 text

Caching NormalizedCache

Slide 88

Slide 88 text

With what shall we normalize it?

Slide 89

Slide 89 text

By default: The path of the query

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

GraphQLID

Slide 98

Slide 98 text

ISBN

Slide 99

Slide 99 text

ISBN + UUID

Slide 100

Slide 100 text

¯\_(ϑ)_/¯

Slide 101

Slide 101 text

cacheKeyForObject

Slide 102

Slide 102 text

cacheKeyForObject (_ object: JSONObject) -> JSONValue?

Slide 103

Slide 103 text

apollo.cacheKeyForObject = { $0["id"] }

Slide 104

Slide 104 text

apollo.cacheKeyForObject = { guard let id = $0["id"], let typename = $0["__typename"] else { // Not enough info to uniquely identify the object return nil } return [id, typename] }

Slide 105

Slide 105 text

apollo.cacheKeyForObject = { guard let id = $0["id"], let typename = $0["__typename"] else { // Not enough info to uniquely identify the object return nil } return [id, typename] }

Slide 106

Slide 106 text

apollo.cacheKeyForObject = { guard let id = $0["id"] as? String, let typename = $0["__typename"] as? String else { // Not enough info to uniquely identify the object return nil } return id + typename }

Slide 107

Slide 107 text

apollo.cacheKeyForObject = { guard let isbn = $0["isbn"], let uuid = $0["uuid"] else { // Not enough info to uniquely identify the object return nil } return [isbn, uuid] }

Slide 108

Slide 108 text

In-memory Caching

Slide 109

Slide 109 text

In-memory Caching InMemoryNormalizedCache

Slide 110

Slide 110 text

Supplementary libraries

Slide 111

Slide 111 text

SQLite Caching

Slide 112

Slide 112 text

SQLite Caching ApolloSQLite

Slide 113

Slide 113 text

Subscriptions

Slide 114

Slide 114 text

Episode Stars Commentary Empire ̣̣̣̣̣ This movie rocks! New Hope ̣̣̣̣̤ This is the first movie, why is it episode 4?

Slide 115

Slide 115 text

Episode Stars Commentary Empire ̣̣̣̣̣ This movie rocks! New Hope ̣̣̣̣̤ This is the first movie, why is it episode 4? Jedi ̣̣̤̤̤ Needs more ewoks.

Slide 116

Slide 116 text

Subscriptions ApolloWebSocket

Slide 117

Slide 117 text

Subscriptions ApolloWebSocket (based on Starscream)

Slide 118

Slide 118 text

client.subscribe(subscription: ReviewAddedSubscription()) { result in switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } }

Slide 119

Slide 119 text

client.subscribe(subscription: ReviewAddedSubscription()) { result in switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } }

Slide 120

Slide 120 text

client.subscribe(subscription: ReviewAddedSubscription()) { result in switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } }

Slide 121

Slide 121 text

client.subscribe(subscription: ReviewAddedSubscription()) { result in switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } }

Slide 122

Slide 122 text

var subscription: Cancellable? self.subscription = client .subscribe(subscription: ReviewAddedSubscription()) { [weak self] result in guard let self = self else { return } switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } } dealloc { self.subscription?.cancel() }

Slide 123

Slide 123 text

var subscription: Cancellable? self.subscription = client .subscribe(subscription: ReviewAddedSubscription()) { [weak self] result in guard let self = self else { return } switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } } dealloc { self.subscription?.cancel() }

Slide 124

Slide 124 text

var subscription: Cancellable? self.subscription = client .subscribe(subscription: ReviewAddedSubscription()) { [weak self] result in guard let self = self else { return } switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } } dealloc { self.subscription?.cancel() }

Slide 125

Slide 125 text

var subscription: Cancellable? self.subscription = client .subscribe(subscription: ReviewAddedSubscription()) { [weak self] result in guard let self = self else { return } switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } } dealloc { self.subscription?.cancel() }

Slide 126

Slide 126 text

var subscription: Cancellable? self.subscription = client .subscribe(subscription: ReviewAddedSubscription()) { [weak self] result in guard let self = self else { return } switch result { case .success(let graphQLResult): if let review = graphQLResult.data?.reviewAdded { // Handle review being added. } if let errors = graphQLResult.errors { // Handle error from the server } case .failure(let error): // Handle networking error } } dealloc { self.subscription?.cancel() }

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

! The Future

Slide 129

Slide 129 text

No content

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

! Free-form responses

Slide 132

Slide 132 text

→ "Poor tutorial support"

Slide 133

Slide 133 text

→ "Poor tutorial support" → "Better documentation."

Slide 134

Slide 134 text

→ "Poor tutorial support" → "Better documentation." → "More documentation on uploading techniques, caching, and background communication."

Slide 135

Slide 135 text

→ "Poor tutorial support" → "Better documentation." → "More documentation on uploading techniques, caching, and background communication." → "Expand documentation on SQLiteNormalizedCache"

Slide 136

Slide 136 text

Better Documentation

Slide 137

Slide 137 text

More Comprehensive Tutorial

Slide 138

Slide 138 text

I have IDEAS!

Slide 139

Slide 139 text

I have IDEAS! ...Are these good ideas?

Slide 140

Slide 140 text

I have IDEAS! ...Are these good ideas?

Slide 141

Slide 141 text

Use Codable instead of custom parsing to the extent that this is possible

Slide 142

Slide 142 text

Use Codable instead of custom parsing

Slide 143

Slide 143 text

Contributing to codegen when it's written in Typescript is hard

Slide 144

Slide 144 text

Swift Codegen

Slide 145

Slide 145 text

Swift Codegen (with parsing and validation still via TypeScript, probably)

Slide 146

Slide 146 text

Generating Swift Code in Swift

Slide 147

Slide 147 text

As part of Swift Codegen:

Slide 148

Slide 148 text

As part of Swift Codegen: → Codable conformance

Slide 149

Slide 149 text

As part of Swift Codegen: → Codable conformance → Equatable/Hashable conformance

Slide 150

Slide 150 text

As part of Swift Codegen: → Codable conformance → Equatable/Hashable conformance → xcfilelists of inputs and outputs

Slide 151

Slide 151 text

As part of Swift Codegen: → Codable conformance → Equatable/Hashable conformance → xcfilelists of inputs and outputs → Fragments as protocols

Slide 152

Slide 152 text

As part of Swift Codegen: → Codable conformance → Equatable/Hashable conformance → xcfilelists of inputs and outputs → Fragments as protocols → Get rid of double-optionals for clearer type*

Slide 153

Slide 153 text

As part of Swift Codegen: → Codable conformance → Equatable/Hashable conformance → xcfilelists of inputs and outputs → Fragments as protocols → Get rid of double-optionals for clearer type* → Identifiable auto-conformance*

Slide 154

Slide 154 text

As part of Swift Codegen: → Codable conformance → Equatable/Hashable conformance → xcfilelists of inputs and outputs → Fragments as protocols → Get rid of double-optionals for clearer type* → Identifiable auto-conformance* * - I hope

Slide 155

Slide 155 text

No content

Slide 156

Slide 156 text

"Version x.y.z breaks on ________"

Slide 157

Slide 157 text

Dependency Manager Test Suite

Slide 158

Slide 158 text

"Version x.y.z breaks on NOTHING"

Slide 159

Slide 159 text

Better Caching

Slide 160

Slide 160 text

Moar ! Libraries!

Slide 161

Slide 161 text

Conucrrency is hard

Slide 162

Slide 162 text

Concurrency is hard

Slide 163

Slide 163 text

Wrappers for RxSwift, Combine, and PromiseKit

Slide 164

Slide 164 text

LIST SUBJECT TO CHANGE Combine, PromiseKit,

Slide 165

Slide 165 text

!

Slide 166

Slide 166 text

Stuff you contribute!

Slide 167

Slide 167 text

Stuff you contribute! (seriously though, I would love your help)

Slide 168

Slide 168 text

No content

Slide 169

Slide 169 text

Obligatory Summary Slide

Slide 170

Slide 170 text

Obligatory Summary Slide → Check out updated build setup, it's way easier

Slide 171

Slide 171 text

Obligatory Summary Slide → Check out updated build setup, it's way easier → Docs have been significantly improved

Slide 172

Slide 172 text

Obligatory Summary Slide → Check out updated build setup, it's way easier → Docs have been significantly improved → New sample app and tutorial coming soon!

Slide 173

Slide 173 text

Obligatory Summary Slide → Check out updated build setup, it's way easier → Docs have been significantly improved → New sample app and tutorial coming soon! → Swift Codegen is coming

Slide 174

Slide 174 text

Obligatory Summary Slide → Check out updated build setup, it's way easier → Docs have been significantly improved → New sample app and tutorial coming soon! → Swift Codegen is coming → Check out the ROADMAP.md

Slide 175

Slide 175 text

Obligatory Summary Slide → Check out updated build setup, it's way easier → Docs have been significantly improved → New sample app and tutorial coming soon! → Swift Codegen is coming → Check out the ROADMAP.md → Contribute!

Slide 176

Slide 176 text

! Thank you!

Slide 177

Slide 177 text

Links! → Main Repo: https://github.com/apollographql/apollo-ios → Prettily rendered documentation: https://apollographql.com/docs/ios/