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

GraphQL with Kotlin

Mohit S
April 26, 2017

GraphQL with Kotlin

How to query and build a schema with GraphQL using Kotlin.

Mohit S

April 26, 2017
Tweet

More Decks by Mohit S

Other Decks in Programming

Transcript

  1. — Query Language for your API developed at Facebook. —

    Polyglot implementation for client and server - Java, Javascript, Python, etc… — Reduces API requests needed and only gives you that data you asked for. What is GraphQL?
  2. Problem — Too many API requests per month. — Would

    be good to get data for a 
 month in request.
  3. GraphQL Overview query GetMonthData { campaign { date range posts

    { title created date } … } } Return Result Fetches Data Validates Client Server
  4. GraphQL Overview query GetMonthData { campaigns { title posts {

    title } … } } Return Result Fetches Data Validates Query Result { campaigns { [ { title: “Campaign 1” posts: [ title: “Post 1” ] } … ] } }
  5. Star Wars Database Droids (R2D2, C3PO,…) — name, height, friends,

    
 primary function.. Humans (Luke, Leia, Solo,…) — name, height, friends, planet…
  6. Simple Query query Hero { hero { name } }

    GraphQL Object defined in schema. Field on hero object.
  7. Simple Query query Hero { hero { name } }

    { data: { hero: { name: “R2 -D2” } } } Query Result
  8. 1. Add Gradle Plugin. 2. Add schema definition to app

    in a JSON file. 3. Add queries to files with a “.graphql” file extension. 4. Use autogenerate classes from the “.graphql” files to make calls. Integrating Apollo Android Client
  9. — GraphQL Object type — Scalar types (String, Int, Float,

    Boolean) — List type — Interface type — Enum type — Union type — Input Object type GraphQL Type System
  10. Star Wars Database Droids (R2D2, C3PO,…) — name, height, friends,

    
 primary function.. Humans (Luke, Leia, Solo,…) — name, height, friends, planet…
  11. — Common fields between Human and Droid — name —

    height — friends — appearsIn Create an interface
  12. — Client and server Java GraphQL implementations are not stable.

    — No Kotlin only GraphQL implementation. — Learning curve. — Need to setup GraphQL server on top of your infrastructure. This requires more work. Disadvantages