Skip to content

Latest commit

 

History

History
111 lines (82 loc) · 1.75 KB

PITCHME.md

File metadata and controls

111 lines (82 loc) · 1.75 KB
Error in user YAML: (<unknown>): mapping values are not allowed in this context at line 3 column 37
---

# Intro to GraphQL

<img style="width: 200px; box-shadow: none; border: 0;" id="graphql-logo" src="http://graphql.org/img/logo.svg"/>

---

Typical REST API

Note:

  • usually an arbitrary endpoint, in the wild most APIs are not truly RESTful
  • no standard way to control output of the endpoint
    • do you make another endpoint? special query params?

Problems

  • Over / Under Fetch |
    • endpoints giving too much/little data
  • Documentation |
    • Swagger, RAML
    • code comments?
  • Rigid |
    • versioning
    • frontend / backend coupling

What is GraphQL?

GraphQL is a query language for your API and a runtime for fulfilling those queries with your existing data

Note:

  • graphql itself is just a spec, countless implementations of graphql in many languages (python -> graphene)
    • main implementation just happens to be js
    • GraphQL was originally created in 2012 at Facebook

Describe your data

type Coupon {
  storeId: ID!
  code: String!
}

type Store {
  id: ID!
  name: String!
  coupons: [Coupon]
}

Note:

  • ! implies non-nullable
  • square bracket notation implies array

Ask for what you want

{
  store(id: "200") {
    name
    coupons {
      code
    }
  }
}

Get predictable results

{
  "store": {
    "name": "Macy's"
    "coupons": [
      {
        code: "10-OFF"
      },
      {
        code: "20-OFF"
      }
    ]
  }
}

Demo !


Topics to look into next

  • fragments / directives
  • mutations
  • caching
  • authentication
  • schema-stitching (graphql microservices)
  • apollo / relay