GraphQL

1. GraphQL basics

2. Demo

3. Tooling

4. Sums up

AGENDA

GraphQL is first

of all a spec

Basics

  • GraphQL has only one official implementation - NodeJS SDK. The rest is 3rd party
  • performance can be blazing fast or slow
  • spec totals 8k lines (JSON:API 2k)

GraphQL requires

a schema

Basics

  • one or multiple .graphql files
  • types & fields
  • queries, mutations, subscriptions

Basics

Queries, mutations

  • call any query or mutation
  • select any fields on response
  • must specify which fields to select
  • can accept parameters

Basics

Multiple operations

  • select multiple queries concurrently
  • execute multiple mutations in order
  • split big mutations into smaller chunks,
    making them easy to reuse

Basics

Fragments

  • share selected fields across requests
  • specify needed fields on component level

Basics

Subscriptions

  • select fields, same as on queries and mutations
  • subscribe to "subscriptions" - similar to Pusher's channels
  • use any implementation - WS, HTTP, Pusher

Basics

Schema split across

multiple files

DEMO

Let's see how it works

Tooling

Document

  • describe all types with fields
    & their types
  • enums, enum values
  • "endpoints" - queries, mutations,
    websocket subscriptions
  • scalars - special primitives, like datetime, email, IP address, currency
  • custom descriptions
  • field deprecations

Tooling

Explore in web

  • test queries/mutations
  • use auto-complete to find queries, mutations, types and fields
  • validate your fields selection

Tooling

Track

  • track breaking changes with Slack notifications
  • store all versions of a schema
  • highlight schema changes on pull requests
  • generate changelog

Tooling

Fedarate

  • generate GraphQL APIs
    based on other APIs
  • combine multiple GraphQL APIs in one
  • transform for specific use - rename, replace, extend, merge fields & types
  • turn existing REST APIs into GraphQL

Tooling

Generate code

  • convert whole schema into code - types, enums, queries
  • generate inputs & responses for queries & mutations
  • injectable services for Angular
  • supports TypeScript, Java, Kotlin & C#

Tooling

GraphQL is growing

  • 174 tools, libraries, SDKs listed on official GraphQL site
  • 330 on "awesome GraphQL" list
  • used by GitHub, Facebook, PayPal and Twitter

Sums up

GraphQL (PHP lib and code generator only): 250k lines

Our whole app (with tests): 700k lines

Building APIs properly is a lot of effort

Sums up

GraphQL does a lot:

  • statically types the API, making it more error-prone
  • makes the code much simpler to write, understand and support
  • has subscription, rendering Pusher useless
  • allows multiple queries/mutations in single request
  • generates ready-to-use client code, saving time and mistakes of frontend & mobile
  • boosts productivity by providing user-friendly tools
  • provides documentation, not only for "REST" API, but for websockets too
  • opens up possibilities of exposing API to the public
  • allows automatically tracking (possibly breaking) changes in APIs for both clients & backend developers
  • has a huge ecosystem of tools and libraries

Sums up

Questions?

GraphQL

By TenantCloud