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

Kotlin + GraphQL

Kotlin + GraphQL

Arnab Datta

April 09, 2021
Tweet

More Decks by Arnab Datta

Other Decks in Programming

Transcript

  1. ABOUT ME As a teenager, Arnab dreamt of being a

    standup comedian, but somehow ended up finding the world of programming instead. He can be found coding away on his mac or dancing (sometimes both at the same time). Feel free to grab him and ask him any questions you want, especially if they involve fan theories about Game of Thrones.
  2. • First and foremost: fixes so many of the problems

    that Java suffered from • Null safety built in the type safety • Just…so many small utilities everywhere • Functions are first class citizens
  3. • First choice language for all Android development at Google

    since 2019 • #4 on Stackoverflow’s list of most loved languages • 2nd most popular language on the JVM in 2020
  4. LETS EXPAND Arnab Datta Friends: Kim, Jessica GET people/1 {

    “id": “1”, “name”: “Arnab Datta”, “friends”: [“2”, “3”] } GET people/2 { “id”: “2”, “name”: “Kim”, “friends”: [“1”] } GET people/3 { “id": “1”, “name”: “Jessica”, “friends”: [“1”] }
  5. • Multiple requests for one view • What happens if

    the IDs provided by the first endpoint are incorrect? • No guarantee that we can access the IDs provided by the first endpoint • We are wasting bandwidth on getting the friends of people we only need the name of.
  6. Arnab Datta Friends: Kim, Jessica GET personWithFriends/1 { “id": “1”,

    “name”: “Arnab Datta”, “friendNames”: [“Kim”, “Jessica”] } LETS “FIX” IT
  7. Frontend dev: What was the name of the endpoint for

    people? Backend dev: /people/:id
  8. Frontend dev: What was the name of the endpoint for

    people? Backend dev: /people/:id Frontend dev: It only supplies the friends names. I want to create a link to their friends, so I need their IDs too Backend dev: Okay, I’ll make a PR.
  9. Frontend dev: What was the name of the endpoint for

    people? Backend dev: /people/:id Frontend dev: It only supplies the friends names. I want to create a link to their friends, so I need their IDs too Backend dev: Okay, I’ll make a PR. Frontend dev: Do you mind adding their phone numbers too? Backend dev: Okay, I’ll make a PR.
  10. WHAT IS A PERSON? data class Person( val name: String,

    val id: UUID, val friends: List<Person> )
  11. WHAT ABOUT PETS? sealed class Pet( abstract val name: String,

    abstract val id: UUID, abstract fun makeSound(): String ) data class Dog(override val name: String, override val id: UUID): Pet() { override fun makeSound() = “woof” } …
  12. WHAT ABOUT PETS? sealed class Pet( abstract val name: String,

    abstract val id: UUID, abstract fun makeSound(): String ) data class Dog(override val name: String, override val id: UUID): Pet() { override fun makeSound() = “woof” } … This can be your API code.
  13. TO SUM UP • GraphQL + Kotlin allows your backend

    developers to just worry about the data model • Put the client first without continuously poking your backend developers for every view • Flexibility without sacrificing simplicity • The same type-safety that Kotlin offers
  14. Slides can be found at https://speakerdeck.com/arnabkd/ Code can be found

    at https://github.com/arnabkd/graphql-kotlin- presentation Learn GraphQL at https://www.howtographql.com GraphQL documentary: https://www.youtube.com/watch? v=783ccP__No8