GraphQL

Sebastian Siemssen

Prerequisites

  • Node 7.0.0+
  • Yarn (preferred) or npm
  • Drupal development environment
  • The editor of your choice

https://github.com/AmazeeLabs/mountaincamp-graphql

https://swapi.co/

GET api/people/1

{
      "name": "Luke Skywalker",
      "height": "1.72 m",
      "mass": "77 Kg",
      "hair_color": "Blond",
      "skin_color": "Caucasian",
      "eye_color": "Blue",
      "birth_year": "19 BBY",
      "gender": "Male",
      "homeworld": "http://swapi.co/api/planets/1/",
      "films": [
          "http://swapi.co/api/films/1/",
          "http://swapi.co/api/films/2/",
          "http://swapi.co/api/films/3/"
      ],
      "species": [
          "http://swapi.co/api/species/1/"
      ],
      "vehicles": [
          "http://swapi.co/api/vehicles/14/",
          "http://swapi.co/api/vehicles/30/"
      ],
      "starships": [
          "http://swapi.co/api/starships/12/",
          "http://swapi.co/api/starships/22/"
      ],
      "created": "2014-12-09T13:50:51.644000Z",
      "edited": "2014-12-10T13:52:43.172000Z",
      "url": "http://swapi.co/api/people/1/"
}

GET api/films/1

GET api/films/2

GET api/films/3

Often we are overfetching and underfetching at the same time causing bloated payloads and additional roundtrips

Often we are overfetching and underfetching at the same time causing bloated payloads and additional roundtrips

We can solve that

GET api/persons-with-films/1

GET api/persons/1?include-films

GET api/persons/1?include=films,...

App #1

App #2

App #3

App #4

Multiple apps

App #1

App #2

App #3

App #4

Multiple versions of multiple apps

Complexity and code debt spiraling out of control

A data querying language

Runs on arbitrary code ...

Backed by a schema ...

Based on a type system ...

Making it fully introspective ...

It runs on arbitrary code.

It is completely agnostic of your storage layer and can potentially support any backend architecture.

Anatomy of a GraphQL Server

GraphQL

Your application code

Database

Internal APIs

Remote APIs

Type definitions

Evolving the server–client relationship

Server publishes possibilities

Client specifies concrete data requirements

Schema

Each schema is an arbitrarily nested hierarchy of type definitions.

Introspection

Exposing your own schema through the type system.

Made with Slides.com