32
GraphQL at the Financial Times

London React August - GraphQL at The Financial Times - Viktor Charypar

Embed Size (px)

Citation preview

Page 1: London React August - GraphQL at The Financial Times - Viktor Charypar

GraphQL at the Financial Times

Page 2: London React August - GraphQL at The Financial Times - Viktor Charypar

GraphQL

Page 3: London React August - GraphQL at The Financial Times - Viktor Charypar

RESTGET id data

Page 4: London React August - GraphQL at The Financial Times - Viktor Charypar

RESTGET id data

GET id2 moreData

GET data.id yetMoreData

Page 5: London React August - GraphQL at The Financial Times - Viktor Charypar

RESTGET id data

GET id2 moreData

GET data.id yetMoreData

ᐧᐧᐧ

Page 6: London React August - GraphQL at The Financial Times - Viktor Charypar

RESTGET id data

GET id2 moreData

GET data.id yetMoreData

ᐧᐧᐧ

Page 7: London React August - GraphQL at The Financial Times - Viktor Charypar

GraphQL• Query based: a single request fulfils exactly the

client’s data needs

• Query language specification

• Programming language agnostic

Page 8: London React August - GraphQL at The Financial Times - Viktor Charypar

{ article(id: 3500401) { id title mainImage(width: 50) { src alt } } }

{ “article”: { “id”: 3500401, “title”: “Hello World”, “mainImage”: { “src”: “http://…”, “alt”: “Hello” } } }

Example

Page 9: London React August - GraphQL at The Financial Times - Viktor Charypar

Viktor Charypar @charypar

github.com/charypar

Page 10: London React August - GraphQL at The Financial Times - Viktor Charypar

The problem with REST

Page 11: London React August - GraphQL at The Financial Times - Viktor Charypar

service service service service service service

client client client

Page 12: London React August - GraphQL at The Financial Times - Viktor Charypar

service service service service service service

client client client

Page 13: London React August - GraphQL at The Financial Times - Viktor Charypar

service service service service service service

client client client

Page 14: London React August - GraphQL at The Financial Times - Viktor Charypar

“I just have a website…”

Page 15: London React August - GraphQL at The Financial Times - Viktor Charypar

service service service service service service

/path /other/path /a/different/path

Page 16: London React August - GraphQL at The Financial Times - Viktor Charypar

It’s the backend complexity…

Page 17: London React August - GraphQL at The Financial Times - Viktor Charypar

service service service service service service

/path /other/path /a/different/path

GraphQL

Page 18: London React August - GraphQL at The Financial Times - Viktor Charypar

How GraphQL works• user-defined type system - “schema”

• server describes what data is available

• clients describe what data they require

• user-defined data fetching (“how do I get an article”)

• backend agnostic

Page 19: London React August - GraphQL at The Financial Times - Viktor Charypar

graphql-js• reference implementation built by Facebook

• github.com/graphql/graphql-js

• currently 0.2.x

• schema definition, query parsing and execution

• no network transport

Page 20: London React August - GraphQL at The Financial Times - Viktor Charypar

Financial Times

Page 21: London React August - GraphQL at The Financial Times - Viktor Charypar

Next FT• project to replace and improve the current ft.com

• displaying content from a set of REST APIs

• github.com/Financial-Times/next-front-page

Page 22: London React August - GraphQL at The Financial Times - Viktor Charypar

Demo

Page 23: London React August - GraphQL at The Financial Times - Viktor Charypar

Next FT backend• CAPIv1 & CAPIv2

• different content available (e.g. fastFT not in v2 yet)

• slightly different response format

• CAPIv1 through Elasticsearch as a feature toggle

Page 24: London React August - GraphQL at The Financial Times - Viktor Charypar

Front page data sources

• top stories & opinions: editorial driven CMS pages

• editor’s picks: mix of searches and pages, moving towards lists

• fastFT: CAPI content by concept + notification feed

• popular stories and live blogs not from CAPI

• related content = extra round of requests

Page 25: London React August - GraphQL at The Financial Times - Viktor Charypar
Page 26: London React August - GraphQL at The Financial Times - Viktor Charypar

API backends are complex

Page 27: London React August - GraphQL at The Financial Times - Viktor Charypar

backend APIs are storage-centric

front-end APIs are product-centric

Page 28: London React August - GraphQL at The Financial Times - Viktor Charypar

service service service service service service

/path /other/path /a/different/path

GraphQL

Page 29: London React August - GraphQL at The Financial Times - Viktor Charypar

Demo

Page 30: London React August - GraphQL at The Financial Times - Viktor Charypar

Practical problems• caching, Elasticsearch, mock data

• swappable backends

• first attempt: pass backend as a type parameter

• horrible hard to maintain monstrosity. Don’t.

• second attempt: execution context rootObject

• more flexible, keeps the schema clean

Page 31: London React August - GraphQL at The Financial Times - Viktor Charypar

Results• significantly simpler and cleaner

• very easy implementation (~3 days)

• starts a little tedious, rapidly speeds up

• still very early days for graphql-js

Page 32: London React August - GraphQL at The Financial Times - Viktor Charypar

Viktor Charypar @charypar

github.com/charypar