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

GraphQL 101: What it is and why you do want it

GraphQL 101: What it is and why you do want it

An introductory talk on GraphQL and the benefits it brings, as presented on Amsterdam JavaScript Lab HackJam Meetup.

Avatar for Bojan Tomić

Bojan Tomić

June 27, 2017
Tweet

More Decks by Bojan Tomić

Other Decks in Technology

Transcript

  1. What? o Data  description  +  query  language o Server-­side  runtime

     for  executing  queries o Type system o Storage  /  language  independent  (think  REST) o Open  source  spec  (tnx Facebook!) (think  WSDL/SOAP) o Unrelated  to  graph  DBs  and  their  query  languages (Cypher,  Gremlin  etc)
  2. Why? Describe  data Predictable  results No  under/over-­fetch type Query {

    hero (episode: Int): Character } { hero (episode: 4) { name homeWorld { name type } } } { "data" : { "hero" : { "name" : "Luke Skywalker" "homeWorld" : { "name" : "Tatooine" "type" : "desert" } } } type Character { name: String friends: [Character] homeWorld: Planet } type Planet { name: String type: String }
  3. GraphQL  vs  REST /carts/1?expand=products Server Update  endpoints Update  models HATEOAS

    /carts/1?fields=products(name,   description,   price) /cart_with_all_the_stuff_i_need /cart_version_2_with_all_the_things /cart_with_all_the_stuff_i_need_but_not_description
  4. GraphQL  vs  REST { cart { total products { name

    price quantity } } } { "data": { "cart" : { "total" : 27.00 "products" : [ { "name" : "Mug Black" "price" : 12.00 "quantity" : 1 }, { "name" : "Octocat figurine" "price" : 15.00 "quantity" : 1 } ] } }