Digging In To The Apollo iOS SDK - GraphQL Summit, San Francisco, October 2019

Digging In To The Apollo iOS SDK - GraphQL Summit, San Francisco, October 2019

Learn about the what and why of recent updates to ApolloGraphQL’s Swift iOS SDK, including updates to code generation, get a few concepts on the iOS side more clearly explained, and learn about where we're going with the iOS SDK!

(Will link to video as soon as it's up!)

C4861b1dfdf3bbb21faec4a1acdf183d?s=128

Ellen Shapiro

October 31, 2019
Tweet

Transcript

  1. 1.

    ⚒ Digging in to the Apollo iOS SDK GraphQL Summit

    | San Francisco, CA | October 2019 by Ellen Shapiro | @DesignatedNerd | apollographql.com
  2. 2.

    !

  3. 3.

    !

  4. 4.

    !

  5. 5.

    !

  6. 6.

    !

  7. 7.

    !

  8. 8.

    !

  9. 9.

    ! "

  10. 10.

    !

  11. 11.

    !

  12. 12.
  13. 13.
  14. 14.

  15. 15.
  16. 16.
  17. 18.
  18. 19.

    !

  19. 20.
  20. 21.

    !

  21. 22.
  22. 23.
  23. 27.

    Adding an iOS library, normally 1. Install dependency using one

    of: → pod install → carthage checkout → swift build
  24. 28.

    Adding an iOS library, normally 1. Install dependency using one

    of: → pod install → carthage checkout → swift build 2. Use library.
  25. 35.
  26. 36.

    Codegen needs to know → Where is the schema file?

    → Where are the query files? → Where should generated code be output?
  27. 37.

    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
  28. 39.
  29. 44.

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

    3. npm install apollo 4. brew install npm
  30. 45.

    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
  31. 46.

    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.
  32. 48.

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

    3. npm install apollo 4. Wait, what version of the CLI is this?
  33. 49.

    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?
  34. 50.

    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.
  35. 51.

    !

  36. 52.

    !

  37. 53.
  38. 54.
  39. 55.
  40. 56.
  41. 60.

    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.
  42. 61.

    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.
  43. 62.

    !

  44. 65.
  45. 67.
  46. 71.
  47. 72.
  48. 73.
  49. 74.
  50. 75.
  51. 76.
  52. 79.
  53. 80.

    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 }
  54. 81.

    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 }
  55. 82.

    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 }
  56. 83.

    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 }
  57. 84.

    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 }
  58. 85.

    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 }
  59. 86.
  60. 90.
  61. 91.
  62. 92.
  63. 93.
  64. 94.
  65. 95.
  66. 96.
  67. 97.
  68. 98.
  69. 104.

    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] }
  70. 105.

    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] }
  71. 106.

    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 }
  72. 107.

    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] }
  73. 114.

    Episode Stars Commentary Empire ̣̣̣̣̣ This movie rocks! New Hope

    ̣̣̣̣̤ This is the first movie, why is it episode 4?
  74. 115.

    Episode Stars Commentary Empire ̣̣̣̣̣ This movie rocks! New Hope

    ̣̣̣̣̤ This is the first movie, why is it episode 4? Jedi ̣̣̤̤̤ Needs more ewoks.
  75. 118.

    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 } }
  76. 119.

    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 } }
  77. 120.

    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 } }
  78. 121.

    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 } }
  79. 122.

    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() }
  80. 123.

    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() }
  81. 124.

    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() }
  82. 125.

    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() }
  83. 126.

    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() }
  84. 127.
  85. 129.
  86. 130.
  87. 134.

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

    on uploading techniques, caching, and background communication."
  88. 135.

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

    on uploading techniques, caching, and background communication." → "Expand documentation on SQLiteNormalizedCache"
  89. 150.

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

    conformance → xcfilelists of inputs and outputs
  90. 151.

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

    conformance → xcfilelists of inputs and outputs → Fragments as protocols
  91. 152.

    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*
  92. 153.

    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*
  93. 154.

    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
  94. 155.
  95. 165.

    !

  96. 168.
  97. 171.

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

    way easier → Docs have been significantly improved
  98. 172.

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

    way easier → Docs have been significantly improved → New sample app and tutorial coming soon!
  99. 173.

    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
  100. 174.

    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
  101. 175.

    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!