Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Du GraphQL 100% Kotlin avec Apollo-Android

Du GraphQL 100% Kotlin avec Apollo-Android

mbonnin

March 05, 2020
Tweet

More Decks by mbonnin

Other Decks in Programming

Transcript

  1. Kotlin 3 Graphql Moderne Typage fort Null safe Des outils

    Moderne Typage fort Null safe Des outils ❤
  2. Moderne 4 • Query Language • 2012: Facebook • 2015:

    Release publique • 2018: Linux Foundation • https://github.com/graphql/graphql-spec
  3. • Objets • Scalaires ◦ Boolean ◦ Int ◦ Float

    ◦ String Typage fort 5 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github
  4. • Objets • Scalaires ◦ Boolean ◦ Int ◦ Float

    ◦ String Typage fort 6 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github
  5. • Objets • Scalaires ◦ Boolean ◦ Int ◦ Float

    ◦ String Typage fort 7 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github
  6. • Objets • Scalaires ◦ Boolean ◦ Int ◦ Float

    ◦ String Typage fort 8 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github
  7. • Objets • Scalaires ◦ Boolean ◦ Int ◦ Float

    ◦ String Typage fort 9 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github
  8. • Mais aussi: ◦ Interfaces ◦ Listes ◦ Enums ◦

    Unions Typage fort 10 type User implements Node { id: ID! login: String bio: String [...] } User Github
  9. Null safety ❗ 11 type User { login: String❗ bio:

    String isBountyHunter: Boolean❗ status: UserStatus issueComments: List<IssueComment>❗ }
  10. Schema 12 { "data" { "__schema": { "types": [ {

    "kind": "OBJECT", "name": "User", "description": "A user is an individual..", "fields": [...], "interfaces": [...], }, [...] ] } }
  11. Apollo-Android 16 query { viewer { login bio status {

    emoji message } } } data class Viewer( val __typename: String = "User", /** * The username used to login. */ val login: String, /** * The user's public profile bio. */ val bio: String?, /** * The user's description of what they're currently doing. */ val status: UserQuery.Status? )
  12. Depreciation 17 query { pinnedRepositories { nodes { id }

    } } /** * A list of repositories this user has pinned to their profile */ @Deprecated(message = "pinnedRepositories will be removed Use ProfileOwner.pinnedItems instead. Removal on 2019-10-01 UTC.") val pinnedRepositories: PinnedRepositories
  13. Runtime 18 val client = ApolloClient.builder() .serverUrl("https://api.github.com/graphql") .build() val viewer

    = runBlocking { client.query(UserQuery()) .toDeferred() .await() .data() .viewer() }
  14. • Compatibilité source/binaire ◦ Checked exception ◦ Methodes et classes

    finales ◦ Optionel par defaut ◦ Les data class explosent la surface d’API ◦ @JvmField • Japicmp Java -> Kotlin MPP 21