Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Intro to GraphQL

Alex ✨🌱
August 22, 2017
140

Intro to GraphQL

High level introduction to GraphQL

Alex ✨🌱

August 22, 2017
Tweet

Transcript

  1. Client <-> GraphQL <-> Server <-> Datastore query { allEggs

    { totalCount } } { “data”: { “allEggs”: { “totalCount”: 4 } } }
  2. Schema Penguin type Apple type Relation between penguin and apple?

    type Penguin { id: ID name: String age: Int }
  3. Schema Penguin type Apple type Relation between penguin and apple?

    type Apple { id: ID size: Float colour: String }
  4. Schema Penguin type Apple type Relation between penguin and apple?

    type Penguin { id: ID name: String age: Int } type Apple { id: ID size: Float colour: String }
  5. Schema Penguin type Apple type Relation between penguin and apple?

    type Penguin { id: ID name: String age: Int apples: [Apple] } type Apple { id: ID size: Float colour: String owner: Penguin grower: Penguin }
  6. query { penguin(name: “Liz”) { id name } } {

    “data”: { “penguin”: { “id”: “1234”, “name”: “Liz” } } }
  7. query { penguin(name: “Liz”) { id name age } }

    { “data”: { “penguin”: { “id”: “1234”, “name”: “Liz” } } }
  8. query { penguin(name: “Liz”) { id name age } }

    { “data”: { “penguin”: { “id”: “1234”, “name”: “Liz”, “age”: 94 } } }
  9. query { penguin(name: “Liz”) { id name age apples }

    } { “data”: { “penguin”: { “id”: “1234”, “name”: “Liz”, “age”: 94 } } }
  10. query { penguin(name: “Liz”) { id name age apples {

    size colour } } } { “data”: { “penguin”: { “id”: “1234”, “name”: “Liz”, “age”: 94 } } }
  11. query { penguin(name: “Liz”) { id name age apples {

    size colour } } } { “data”: { “penguin”: { “id”: “1234”, “name”: “Liz”, “age”: 94, “apples”: [{ “size”: 5, “colour”: “red” }, { “size”: 8, “colour”: “red” }] } } }
  12. Cat egg mutation { createApple(size: 13) { id size colour

    } } { “data”: { “createApple”: { “id”: “3”, “size”: 13, “colour”: “red” } } }
  13. GQL vs REST • Get exactly what you need, in

    1 perfect request • Requires smart caching on client side • Powerful standard tooling + great usability out the box • New and shiny • Often several requests needed to get all data • Great caching solution by default • Also great tooling, but less awesome for free • Established standard