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

GraphQL à Shopify

GraphQL à Shopify

Marc-Andre Giroux

April 05, 2017
Tweet

More Decks by Marc-Andre Giroux

Other Decks in Programming

Transcript

  1. @__xuorig__ { "name": "Luke Skywalker", "height": "172", "mass": "77", "hair_color":

    "blond", "skin_color": "fair", "eye_color": "blue", "birth_year": "19BBY", "gender": "male", "homeworld": "http://swapi.co/api/ planets/1/", "films": [ "http://swapi.co/api/films/6/", "http://swapi.co/api/films/3/", "http://swapi.co/api/films/2/", "http://swapi.co/api/films/1/", "http://swapi.co/api/films/7/" ],
  2. @__xuorig__ { "name": "Luke Skywalker", "height": "172", "mass": "77", "hair_color":

    "blond", "skin_color": "fair", "eye_color": "blue", "birth_year": "19BBY", "gender": "male", "homeworld": "http://swapi.co/api/ planets/1/", "films": [ "http://swapi.co/api/films/6/", "http://swapi.co/api/films/3/", "http://swapi.co/api/films/2/", "http://swapi.co/api/films/1/", "http://swapi.co/api/films/7/" ],
  3. @__xuorig__ "data": { "film": { "title": "A New Hope", "characters":

    [ { "name": "Luke Skywalker" }, { "name": "Princess Leia" } ] } }
  4. @__xuorig__ curl -X POST -d '{"query": "query MyQuery { film

    { title } }"}' http:// mongraphql.com/api --header "Content-Type:application/json"
  5. @__xuorig__ curl -X POST -d '{"query": "query MyQuery { film

    { title } }"}' http:// mongraphql.com/api --header "Content-Type:application/json"
  6. @__xuorig__ { film(id: "123") { title characters { name }

    } } type QueryRoot { film(id: ID!): Film }
  7. @__xuorig__ { film(id: "123") { title characters { name }

    } } type Film { title: String! characters: [Character!]! }
  8. @__xuorig__ { film(id: "123") { title characters { name }

    } } type Character { name: String! }
  9. @__xuorig__ query { film(id: "123") { title characters { name

    } } bestRatedfilm { title characters { name } } }
  10. @__xuorig__ query { film(id: "123") { title characters { name

    } } bestRatedfilm { title characters { name } } }
  11. @__xuorig__ query { film(id: "123") { ...filmFragment } bestRatedfilm {

    ...filmFragment } } fragment filmFragment on Film { title characters { name } }
  12. @__xuorig__ Requêtes persistées query MyQuery { film { title }

    } Yo. c'est possible que j'utilise cette requête plus tard!
  13. @__xuorig__ Définir les types module GraphApi class Shop < GraphApi::ObjectType

    field :name, :string field :currency, :string, null: false field :products, [Product], resolve: ->(shop, _, _) { shop.products } end end