Skip to content

Commit b78ed04

Browse files
committed
basic resource client blurb
1 parent 2ed4c78 commit b78ed04

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

wiki/ResourceClients.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Resource Clients
2+
3+
We use Resource Clients to access Resources on the api.
4+
Internally it uses Effect RPC.
5+
6+
## Query
7+
8+
Queries are for reading data from the api. No writing/mutating allowed. Queries by default are deduplicated, shared between components, auto refreshed after stale time and user interaction with the tab/window.
9+
10+
## Mutation
11+
12+
Mutations are for writing data to the api, return values should at most include identifiers, and often `void`.
13+
Mutations auto invalidate Queries in their namespace, so that a Users.Index Query will be invalidated upon a Users.Delete or Update mutation.
14+
This only occurs within the same namespace, like "Users".
15+
If you need to invalidate queries in another namespace, you can pass the following option to the Mutation constructor:
16+
17+
```ts
18+
queryInvalidation: (queryKey) => [
19+
{ filters: { queryKey } },
20+
{ filters: { queryKey: makeQueryKey(meClient.GetMe) } }
21+
]
22+
```
23+
24+
## Command
25+
26+
A Command captures the start of a user interaction (e.g button click), procceses the input, performs side effects,
27+
all of this wrapped in a tracing span and defect reporting. To handle status updated to the UI, Commands return Results, and you can compose various handling like automatic Toast on Wait, Succeed and Failure.
28+
All queries and mutations have a strict namespace and name, which is then used for span names, i18n, etc.

0 commit comments

Comments
 (0)