Tabs or spaces
ⓘ Start presenting to display the poll results on this slide.
Vim or Emacs
ⓘ Start presenting to display the poll results on this slide.
Summary
Should you use GraphQL?
Brief intro to GraphQL, its key differences with REST, pros and cons of both, and ultimately some examples and hints showing when and when NOT to use GraphQL.
GraphQL
a brief intro
GraphQL
a brief intro
GraphQL
a brief intro
GraphQL
a brief intro
GraphQL
a brief intro
GraphQL foundation
GraphQL foundation
Query
Response
{
allVehicles(first: 2) {
vehicles {
name
model
}
}
}
{
"data": {
"allVehicles": {
"vehicles": [
{
"name": "Sand Crawler",
"model": "Digger Crawler"
},
{
"name": "T-16 skyhopper",
"model": "T-16 skyhopper"
}
]
}
}
}
Code-completion
Schema
The cost of DX
type Root {
allVehicles(
after: String, first: Int,
before: String, last: Int
): VehiclesConnection
}
"""
A single transport craft that does not have hyperdrive capability
"""
type Vehicle {
"""
The name of this vehicle. The common name, such
as "Sand Crawler" or "Speeder bike".
"""
name: String
"""
The model or official name of this vehicle.
Such as "All-Terrain Attack Transport".
"""
model: String
}
... 1168 lines in total ...
REST
GraphQL
1 network call per query
1 network call per entity
single HTTP endpoint
multiple HTTP endpoints
client-defined response content
server-defined response content
no built-in access control
access control on HTTP level
strictly typed / schema is required
schema is optional
supports real-time data
–
more complex server-side code
simpler server-side code
vs
Use REST if…
Client views map 1-to-1 to REST endpoints
e.g. CRUDs
Use REST if…
The same team works on the backend and the frontend
Use REST if…
The data comes from many sources AND there is no team / budget to federate it into a single GraphQL schema.
Use GraphQL if…
Complex and / or varying data requirements across the client
Use GraphQL if…
Frontend and backend teams are separate
Use GraphQL if…
You can externalise the cost of creating the GraphQL server
(or you have in-house experience)
Use GraphQL if…
There is a need for real-time data as well.
Use GraphQL if…
You can benefit from strong typing
(e.g. client in TypeScript)
Demo time
REST or GraphQL
ⓘ Start presenting to display the poll results on this slide.