Table of Contents

1 Concepts

GraphQL is a specification for an API query language and server engine capable of executing such queries.

  • Document has many operations or fragments (executables) or type system information
  • Operation types may be queries, mutations, and subscriptions

1.1 Contrasting REST

  • partials
  • versions
  • fields

1.2 Parsing

  • Whitespace and line terminations are as expected
  • Tokens
  • The "query" keyword and name may not be present for [{ field }]

1.3 Operations

  • query: read-only fetch
  • mutation: write + fetch
  • subscription: response to source events

1.4 Selection Sets

{
  id
  firstName
  lastName
}
  • Can contain aliases

1.5 Types

  • ID
  • String
  • DateTime

1.6 Schemas

The SDL provides a language for describing the type system for GraphQL.

1.7 Schema Root

1.8 Fragments

query withFragments {
  user(id: 4) {
    friends(first: 10) {
      ...friendFields
    }
    mutualFriends(first: 10) {
      ...friendFields
    }
  }
}

fragment friendFields on User {
  id
  name
  profilePic(size: 50)
}

1.9 Queries

1.9.1 Variables

1.10 Mutations

1.11 Enums

1.12 Abstract Types

interface Animal {
  name: String!
}

interface Plant {
  genus: String!
  species: String!
}

1.13 Unions

union Entity = Plant | Animal

2 Maintaining GraphQL

3 Tools

3.1 GraphQL Playground

3.3 Mocking

npm install -g get-graphql-schema graphql-cli graphql-faker
mkdir t && cd t
# graphql init

get-graphql-schema https://$HOST/graphql/ > schema.graphql
graphql-faker schema.graphql
open http://localhost:9002/editor

4 Reading

  • Production Ready GraphQL

5 Videos

Author: Jason Walsh

Created: 2020-07-31 Fri 11:28

Validate