GraphQL

A query language for your API

(and how we could use it in SilverStripe)

Motivation

Schema smarts are built in

Self-documenting API

Flexible backend integration

Multiple "resources" in a single call

Enables co-location of API query with view

Context: Server

A specification created by Facebook

Alternative to REST and SOAP

GraphQL servers in many languages (Node, PHP, etc)

Used by the new Github API, Pinterest, Shopify, ...

Interest by Drupal Core

Context: Client

Relay is Facebook's GraphQL client (use with React)

Other GraphQL integrations exist (Angular2, VueJS)

Replacement of Redux (or addition, with Apollo)

Query Basics

Query Params

Query

Get exactly the data you need

Operates on types and a declarative schema

A type can be a scalar (Int) or complex (Film)

Nested Data

Types in PHP

Queries in PHP

Apollo Client

How about SilverStripe 4?

  • Early stage investigation!
  • Create a supported core API (easier than REST)
  • View performance: Load config, current user, menu items, page tree, form schemas, ... - in one request
  • Shift in dev thinking: Types and model constraints vs. getCMSFields()

Read more

Made with Slides.com