"api" object
We use a custom-built "api" object, which is essentially a wrapper over React Query (v3), and is tRPC-like in terms of usage.
The frontend routes line up with our backend routes according to our (v2) API schema. (in the comments in the second image below, you can see which backend/Rails controller actions are related to each frontend route)
Overview
Configuration
"api" object (holds "router" objects)

"router" objects (hold "procedures" -- e.g. getSingle, getMany, etc.)

Usage
Queries (e.g. getSingle, getMany) (useQuery-wrapped procedures)

Mutations (e.g. create, update, delete) (useMutation-wrapped procedures)

-- Top-level resource (e.g. projects):

mutationProjectUpdate.mutate({
id: doc.id,
payload: {
production_goal: requestData.production_goal,
},
});
-- Nested resource (e.g. production goals -- projects/production_goals)

mutationProductionUpdate.mutate({
parentResource: 'projects',
parentId: doc.id,
id: production.id,
payload: {
date: production.date,
goal: production.goal,
actual: production.actual,
},
});
Last updated