GraphQL vs REST strategy
This course weighs GraphQL against REST for Rails teams. It starts from the client inventory that decides the question: several heterogeneous clients you don't control or can't deploy with the server. It covers what GraphQL solves, namely over-fetching, under-fetching and one round trip for a whole graph. It then covers what it costs: N+1 by default, lost HTTP caching, unbounded query cost, field-level authorization and errors returned with 200. It also covers what REST provides for free, middle-ground options, graphql-ruby in a Rails application and a four-question decision framework.
What you'll learn
- ✓The client condition under which GraphQL is worth its cost
- ✓The costs of GraphQL: N+1, lost HTTP caching, query limits and errors with 200
- ✓What REST provides through URLs, logs, one authorization gate and path versioning
- ✓Middle-ground options: sparse fieldsets, composite endpoints and a backend-for-frontend
- ✓How graphql-ruby, Dataloader, complexity limits and trusted documents fit in Rails
- ✓A four-question framework for deciding and for saying no
The question behind GraphQL vs REST
Someone in a planning meeting says "we should move to GraphQL". Nobody in the room wants to be the person who says no to a newer thing, so the team spends a quarter on it. Eighteen months later, there are two ways to read a Course out of the same table, and neither can be deleted.
Read the full lesson free →Curriculum
7 lessonsThe question behind GraphQL vs REST
Why most Hotwire-first Rails teams should answer no, and the client condition that changes the answer.
What GraphQL actually solves
How over-fetching and under-fetching form one trade, and the three conditions under which GraphQL pays off.
What GraphQL costs
The costs of GraphQL: default N+1, lost HTTP caching, unbounded queries, field authorization and errors with 200.
What REST quietly gives you
What REST provides without extra code: URL cache keys, path-based logs and APM, simple authorization and versioning.
The middle ground most teams need
Sparse fieldsets, composite endpoints and a backend-for-frontend as cheaper fixes for fat endpoints and chatty screens.
graphql-ruby in a Rails application
How graphql-ruby fits in Rails, with one POST route, required limits, Dataloader batching and trusted documents.
Deciding, and the honest default
A four-question decision framework, the honest default for Rails teams and how to argue for a cheaper option.