Lifecycle of a Request
A request goes down through a Resource to your data, and comes back up as a serialized response.
Graphiti is the highlighted part: the Resource, and the JSON:API it renders. The Endpoint is your Rails controller, which handles routing, response codes and MIME types. The Backend is yours too.
| Piece | What it does |
|---|---|
| Endpoint | Your controller. Graphiti registers its path and actions, which drives link generation and endpoint validation, and lets you vary a Resource's behavior per route. |
| Resource | Turns request params into a scope, resolves that scope into Models, and serializes them on the way back out. |
| Adapter | Reusable glue between a Resource and a Backend. Defaults to Graphiti::Adapters::ActiveRecord. |
| Backend | Whatever you query: a database, a search index, an HTTP service. |
| Model | What you return and serialize. With ActiveRecord, the same object as the Backend. |
The graph
Resources connect to other Resources:
- Sideloading: fetch an employee, her positions, and those positions' departments in one request
- Sideposting: save an employee and her positions in one request
- Links: a URL to lazy-load positions in a separate request
Query logic written for one Resource applies at every level of that graph, so you can ask for an employee and her last three positions ordered by created_at. That's deep querying.