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

DroidCon IT - GraphQL on the JVM and beyond

DroidCon IT - GraphQL on the JVM and beyond

mbonnin

May 19, 2020
Tweet

More Decks by mbonnin

Other Decks in Programming

Transcript

  1. 1

  2. REST: GET /feed 8 { "feed": [ { "type": "post",

    "title": "My cat is so funny :-P", "text": "Pancake loves to lay in the sun!", "thumbnail": "/img/fe3c57178.jpg" }, { "type": "post", "title": "My first homemade bread!", "text": "Using only flour and water", "thumbnail": "/img/85511bbb2.jpg" }, { "type": "ad", "title": "50 bread recipes" } ] }
  3. GraphQL 10 • Product oriented • Exposes a Graph Feed

    Post Post Ad Title Text XL Thumbnail S Thumbnail
  4. GraphQL 11 Feed Post Post Ad Title Text XL Thumbnail

    S Thumbnail • Product oriented • Exposes a Graph
  5. GraphQL 12 Feed Post Post Ad Title Text XL Thumbnail

    S Thumbnail • Product oriented • Exposes a Graph
  6. GraphQL 13 Feed Post Post Ad Title Text XL Thumbnail

    S Thumbnail • Product oriented • Exposes a Graph
  7. Hello GraphQL 14 query { feed { post { title

    text thumbnail } } } { "feed": { "post": { "title": "My cat is so funny :-P", "text": "Pancake loves to lay in the sun", "thumbnail": "/img/fe3c57178.jpg" } } }
  8. Principles 15 • Client requests the data. • Data is

    strongly typed. • The api is introspectable.
  9. GraphQL 16 • 2012: Facebook • 2015: Open Source release

    • 2018: Linux Foundation • https://github.com/graphql/graphql-spec
  10. Type system 18 type User { login: String bio: String

    isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github • Objects • Scalars ◦ Boolean ◦ Int ◦ Float ◦ String • Lists
  11. Type system 19 type User { login: String bio: String

    isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github • Objects • Scalars ◦ Boolean ◦ Int ◦ Float ◦ String • Lists
  12. Type system 20 type User { login: String bio: String

    isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github • Objects • Scalars ◦ Boolean ◦ Int ◦ Float ◦ String • Lists
  13. Type system 21 type User { login: String bio: String

    isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github • Objects • Scalars ◦ Boolean ◦ Int ◦ Float ◦ String • Lists
  14. • Objects • Scalars ◦ Boolean ◦ Int ◦ Float

    ◦ String • Lists Type system 22 type User { login: String bio: String isBountyHunter: Boolean status: UserStatus issueComments: List<IssueComment> } User Github
  15. • Interfaces • Enums • Unions Type system 23 type

    User implements Node { id: ID! login: String bio: String [...] } User Github
  16. Null safety ❗ 24 type User { login: String❗ bio:

    String isBountyHunter: Boolean❗ status: UserStatus issueComments: List<IssueComment>❗ }
  17. Hello GraphQL 26 query GetViewer { viewer { login bio

    status { emoji message } } } { "data": { "viewer": { "login": "martinbonnin", "bio": "Lorem Ipsum", "status": { "emoji": ":smileyface:", "message": "Foo" } } } }
  18. Passing parameters 27 query GetViewer { viewer { login bio

    avatarUrl(size: 500) status { emoji message } } }
  19. Schema 30 { "data" { "__schema": { "types": [ {

    "kind": "OBJECT", "name": "User", "description": "A user is an individual..", "fields": [...], "interfaces": [...], }, [...] ] } }
  20. Apollo-Android 32 • https://github.com/apollographql/apollo-android • Doesn’t require Android! • Java

    & Kotlin codegen. • Strong typing. • Reflection-free json parsing. • HTTP & Normalized cache. • RxJava & Coroutines support.
  21. Authentication 36 • We use a separate Oauth endpoint. •

    Leverage the “Authorization” header. • Can be done with a OkHttp interceptor.
  22. Persisted queries 37 query { viewer { login bio status

    { emoji message } } } “OperationId”: viewerQuery
  23. Versioning 38 • Versioning is fluid. • Easy to add

    new fields, hard to remove. • Do not modify types. • Monitor your backend.
  24. Use deprecation 39 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
  25. 46