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

Intro to GraphQL

Intro to GraphQL

GraphQL: What it is, how it works, how to use it

Avatar for Alex ✨🌱

Alex ✨🌱

August 15, 2018
Tweet

More Decks by Alex ✨🌱

Other Decks in Programming

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
  14. • http://graphql.org/ - GraphQL language spec and documentation • https://www.graphql.com/tutorials/

    - awesome guides and tutorials • https://www.graph.cool/docs/quickstart/ - probably the fastest way to get started with GraphQL • http://dev.apollodata.com/ - docs and tutorials for Apollo Client • https://github.com/chentsulin/awesome-graphql - Community list of awesome graphql related things • Me! ✨