The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very...
Transcript of The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very...
![Page 1: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/1.jpg)
BETTER APIS WITHThe Future of the Realtime Web
Josh Price @joshprice
GRAPHQL
![Page 2: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/2.jpg)
![Page 3: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/3.jpg)
STEPPING STONES TO FPLa
ngua
ge (E
lixir)
Strongly-Typed APIs (GraphQL)
![Page 4: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/4.jpg)
GRAPHQL WAS
HERE?
http://whiteafrican.com/2008/05/12/crossing-the-mapping-chasm/
![Page 5: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/5.jpg)
COMMON ISSUES WITH RESTA TAXONOMY OF
![Page 6: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/6.jpg)
PERFORMANCE
![Page 7: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/7.jpg)
UNDERFETCHING
![Page 8: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/8.jpg)
COMMON ISSUES WITH REST
UNDERFETCHING
▸ N + 1 HTTP request problem
▸ eg. Fetched a Blog Post but not Comments
▸ Must make more requests to fulfil data requirements
▸ For complex views we saw 6-7 requests (usually serial)
▸ Have seen up to 25+ requests in the wild
![Page 9: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/9.jpg)
OVERFETCHING
![Page 10: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/10.jpg)
COMMON ISSUES WITH REST
OVERFETCHING
▸ Client wants a small subset of data from endpoint
▸ But gets everything regardless
▸ The addition of fields to a endpoint bloats payloads
▸ Create more endpoints, but this means more roundtrips
▸ Could create a homepage specific endpoint for each device, but harder to manage
![Page 11: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/11.jpg)
BIG UPFRONT DESIGN
![Page 12: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/12.jpg)
COMMON ISSUES WITH REST
BIG UPFRONT DESIGN NEEDED
▸ Need to anticipate all current and future clients’ needs
▸ ie Mobile v Web clients
▸ Could have multiple representations/endpoints
▸ Divergence of server code
▸ Keeping everything in sync is hard
![Page 13: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/13.jpg)
HYPERMEDIA?
![Page 14: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/14.jpg)
COMMON ISSUES WITH REST
HYPERMEDIA ISN’T ALWAYS APPLICABLE
▸ If you control the clients and the server
▸ Less useful for your web or mobile app calling a known API 1000x / sec
▸ Semantics are communicated out of the
▸ A self-describing, well-typed API is an alternative approach
![Page 15: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/15.jpg)
GRAPHQL
![Page 16: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/16.jpg)
GRAPHQL HISTORY
WHAT IS GRAPHQL?
▸ Language for defining schemas, types & queries
▸ It’s a specification for that language (like OpenAPI, Swagger)
▸ Developed by Facebook in 2012
▸ Used internally to improve mobile app performance
▸ Served 300B+ requests per day (1.6B DAU on mobile)
▸ Open sourced spec in mid 2015
![Page 17: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/17.jpg)
DATA FETCHINGGENERALISED
![Page 18: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/18.jpg)
![Page 19: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/19.jpg)
EASIER TO BUILDGRAPHQL APIS ARE
![Page 20: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/20.jpg)
EASIER TO CONSUMEGRAPHQL APIS ARE
![Page 21: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/21.jpg)
PERFORMANCEBETTER
![Page 22: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/22.jpg)
SELF DOCUMENTINGSELF DESCRIBING AND
![Page 23: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/23.jpg)
CONSUMER DRIVEN CONTRACTS
EXPOSE YOUR DOMAIN MODEL VIA
![Page 24: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/24.jpg)
ISOMORPHICQUERIES AND RESPONSES ARE
![Page 25: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/25.jpg)
STRONGLY TYPED APISTYPES IN YOUR SCHEMA ==
![Page 26: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/26.jpg)
EASIER EVOLUTIONBUILT-IN FIELD DEPRECATION MEANS
![Page 27: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/27.jpg)
MYTHS & MISCONCEPTIONS
![Page 28: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/28.jpg)
GRAPH DATABASEYOU DO NOT NEED A
![Page 29: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/29.jpg)
QUERY LANGUAGETHIS IS NOT YOUR TYPICAL
![Page 30: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/30.jpg)
LANGUAGE AGNOSTICNOT ONLY FOR JAVASCRIPT
![Page 31: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/31.jpg)
HTTP OR JSONNOT DEPENDENT ON
![Page 32: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/32.jpg)
DOES NOT REPLACE REST IT’S EASIER TO WORK WITH BUT
![Page 33: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/33.jpg)
MAKES REST EASIERPOTENTIALLY
![Page 34: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/34.jpg)
GRAPHQL CONCEPTSLET’S LEARN SOME
![Page 35: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/35.jpg)
SCHEMAS, TYPES AND SCALARS
type Meetup { title: String! date: Date description: String url: URL! talks: [Talk!]! }
type Talk { title: String! description: Markdown presenter: Person! }
schema { query: Query mutation: Mutation }
GraphQL SDL
![Page 36: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/36.jpg)
SCHEMAS, TYPES AND SCALARS
type Meetup { title: String! date: Date description: String url: URL! talks: [Talk!]! }
type Talk { title: String! description: String presenter: Person! }
schema { query: Query mutation: Mutation }
@desc "A meetup” object :meetup do @desc "The title of the meetup" field :title, non_null(:string)
@desc "The date of the meetup" field :date, :date
@desc "The description of the meetup" field :description, :string
@desc "The Meetup.com url" field :url, :string
@desc "The talks at the meetup" field :talks, list_of(:talk) end
GraphQL SDL Elixir with Absinthe
![Page 37: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/37.jpg)
GRAPHQL CONCEPTS
RESOLVER FUNCTIONS FETCH YOUR DATA
▸ Resolver functions fetch (or update) data
▸ Called when query fields are matched against schema fields
▸ Return data or an error
▸ Can take arguments specified in schema
▸ Can take a context in from the query (ie current user for authentication and authorisation)
![Page 38: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/38.jpg)
GRAPHQL CONCEPTS
RESOLVER FUNCTIONS (ELIXIR EXAMPLE)defmodule GraphqlSydney.GraphQL.Schema do use Absinthe.Schema alias GraphqlSydney.Events
import_types Absinthe.Type.Custom
query do @desc "Get the next meetup" field :next_meetup, type: :meetup do resolve fn _, _ -> {:ok, Events.next_meetup} end end
@desc "Get the previous meetups" field :previous_meetups, type: list_of(:meetup) do resolve fn _, _ -> {:ok, Events.past_meetups} end end end end
![Page 39: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/39.jpg)
GRAPHQL CONCEPTS
QUERY PROCESSING PIPELINE
▸ Client send Query documents as Strings
▸ Server Parses into AST
▸ Validation of AST
▸ Query fields matched against Schema
▸ Matching resolver functions executed
▸ Data (and errors) returned to client as a Map
![Page 40: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/40.jpg)
1 2
34CLIENT
DB
CMS
SIMPLE QUERY LIFECYCLE
Query (String)
Response (Map)
Data Fetching
Run Resolver
Functions
![Page 41: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/41.jpg)
LET’S SEE IT IN ACTION!
![Page 42: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/42.jpg)
![Page 43: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/43.jpg)
QUERY: FETCH NEXT MEETUP
![Page 44: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/44.jpg)
QUERY: AUTOCOMPLETE / AUTOCORRECTION
![Page 45: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/45.jpg)
QUERY: FETCH NEXT MEETUP’S TALKS
![Page 46: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/46.jpg)
QUERY: INLINE DOCUMENTATION
![Page 47: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/47.jpg)
QUERY: MEETUP WITH TALKS AND PRESENTERS
![Page 48: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/48.jpg)
GETTING STARTED
![Page 49: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/49.jpg)
HOW TO GET STARTED WITH GRAPHQL
STEP 1: PICK A SERVER IMPLEMENTATION
▸ JavaScript reference implementation
▸ Apollo Server Tools
▸ Java / Scala (Sangria)
▸ .NET / F#
▸ Ruby / Python / PHP
▸ Elixir / Erlang
▸ Go / Rust / Haskell
![Page 50: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/50.jpg)
HOW TO GET STARTED WITH GRAPHQL
STEP 2: WRITE YOUR SCHEMA
▸ Figure out your domain types
▸ Write top level queries for reads
▸ Add mutations for writes
▸ Subscriptions for reactive data changes
▸ Don’t forget field descriptions!
![Page 51: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/51.jpg)
HOW TO GET STARTED WITH GRAPHQL
STEP 3: CHOOSE A CLIENT
▸ Relay Modern
▸ Declare data requirements of UI component as query fragments
▸ Sends a single query
▸ Render collects query fragments in the render tree
▸ Caches objects by unique ID
▸ Added graph convention of nodes and edges
▸ Pagination metadata, etc
▸ Not actually part of the spec and can be confusing
![Page 52: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/52.jpg)
HOW TO GET STARTED WITH GRAPHQL
STEP 3: CHOOSE A CLIENT
▸ Apollo 2.0
▸ Bit simpler than Relay, no graph conventions
▸ Hand rolled queries for each view
▸ Handles client side caching
▸ Probably easiest to start here
▸ Also has native iOS and Android client libs
![Page 53: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/53.jpg)
HOW TO GET STARTED WITH GRAPHQL
STEP 4: PROFIT
▸ Start with read only first
▸ Shim existing REST APIs
▸ Frontend and Backend need to be on board
▸ Easy to experiment
▸ Try it out on new non-critical path projects
![Page 54: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/54.jpg)
THINGS TO WATCH OUT FOR
![Page 55: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/55.jpg)
THINGS TO WATCH OUT FOR
COMPLEX AND PATHOLOGICAL QUERIES
▸ Denial of Service possible for slow queries
▸ Be careful with exposing sorting, filtering and aggregation
▸ ie Don’t expose a sort field without an index
▸ Limit query depth and/or complexity
▸ Not all implementations have this though
▸ Instrumentation can alleviate this
![Page 56: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/56.jpg)
THINGS TO WATCH OUT FOR
AVOID “STRINGLY TYPING”
▸ It’s very easy overuse plain String types
▸ You lose information: makes mocking harder
▸ There are no type aliases in the spec (yet)
▸ Can write your own custom Scalars (impl specific)
▸ Fine-grained “Micro-types” are useful
▸ ie URL, Email, Markdown, Name, Money, etc
![Page 57: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/57.jpg)
THINGS TO WATCH OUT FOR
NO HTTP CACHING
▸ Can send queries by GET
▸ POST is preferred
▸ Can’t use standard HTTP caching
▸ Varnish, Squid, etc
▸ Can cache elsewhere however
▸ Client, Resolvers, Data Store, etc
![Page 58: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/58.jpg)
RICH TOOLING ECOSYSTEM
![Page 59: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/59.jpg)
EXPORATION & VISUALISATION
![Page 60: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/60.jpg)
![Page 61: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/61.jpg)
![Page 62: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/62.jpg)
![Page 63: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/63.jpg)
![Page 64: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/64.jpg)
![Page 65: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/65.jpg)
![Page 66: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/66.jpg)
GRAPHQL SERVER ANALYTICS
![Page 67: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/67.jpg)
![Page 68: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/68.jpg)
QUERY EXECUTION TRACING
![Page 69: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/69.jpg)
INTEGRATED CACHE MANAGEMENT
![Page 70: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/70.jpg)
ERROR TRACKING
![Page 71: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/71.jpg)
SCHEMA ANALYSIS
![Page 72: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/72.jpg)
SCHEMA STITCHING AND COMPOSITION
![Page 73: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/73.jpg)
SCHEMA COMPOSITION
![Page 74: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/74.jpg)
![Page 75: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/75.jpg)
SCHEMA STITCHING
GRAFT
![Page 76: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/76.jpg)
TOOL ECOSYSTEM
SCHEMA COMPOSITION TOOLS
▸ Apollo Schema Stitching
▸ https://dev-blog.apollodata.com/graphql-schema-stitching-8af23354ac37
▸ Gramps the IBM microservice API composition framework
▸ https://github.com/gramps-graphql/gramps
▸ GraphQL Weaver
▸ https://github.com/AEB-labs/graphql-weaver
![Page 77: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/77.jpg)
API MOCKING
![Page 78: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/78.jpg)
![Page 79: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/79.jpg)
GRAPHQL STACKS
![Page 80: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/80.jpg)
![Page 81: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/81.jpg)
![Page 82: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/82.jpg)
![Page 83: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/83.jpg)
![Page 84: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/84.jpg)
CMS BACKENDS
![Page 85: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/85.jpg)
![Page 86: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/86.jpg)
![Page 87: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/87.jpg)
GRAPHQL BACKENDS AS A SERVICE
![Page 88: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/88.jpg)
![Page 89: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/89.jpg)
![Page 90: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/90.jpg)
![Page 91: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/91.jpg)
REALTIME APIS WITH SUBSCRIPTIONS
![Page 92: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/92.jpg)
REACTIVE BACKENDSHTTP/2 PUSH AND THE RISE OF
![Page 93: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/93.jpg)
HAS GRAPHQL CROSSED THE CHASM?
![Page 94: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/94.jpg)
![Page 95: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/95.jpg)
GRAPHQL IS
HERE
http://whiteafrican.com/2008/05/12/crossing-the-mapping-chasm/
![Page 96: The Future of the Realtime Web BETTER APIS WITH GRAPHQL · AVOID “STRINGLY TYPING” It’s very easy overuse plain String types You lose information: makes mocking harder There](https://reader030.fdocuments.in/reader030/viewer/2022040609/5ec9b4e8b9e5ba73c0184f29/html5/thumbnails/96.jpg)
NEXT STEPS
RESOURCES
▸ http://graphql.org/
▸ https://github.com/chentsulin/awesome-graphql
▸ https://www.apollographql.com/
▸ https://facebook.github.io/relay/
▸ GraphQL Summit Videos
▸ https://www.youtube.com/playlist?list=PLpi1lPB6opQywks7yYYs5jJAIRI3faRTm