You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rescript-relay-documentation/docs/interacting-with-the-store.md
+76Lines changed: 76 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,6 +209,82 @@ A good strategy is to use `commitLocalPayload` to insert new entites, and then m
209
209
210
210
> Note: You must use `@raw_response_type` to get access to `commitLocalPayload`. RescriptRelay won't expose it unless you use that directive.
211
211
212
+
## Bulk connection operations
213
+
214
+
When working with connections, you often need to perform operations that affect multiple connection instances at once. RescriptRelay provides utility functions that make these operations easier and more efficient.
215
+
216
+
### Finding all connection instances with `findAllConnectionIds`
217
+
218
+
`Environment.findAllConnectionIds` helps you find all cached instances of a specific connection, regardless of what filters or arguments were used when fetching them. This is particularly useful when you want to update all instances of a connection after a mutation.
219
+
220
+
```rescript
221
+
// Find all instances of a user's posts connection
222
+
let connectionIds = environment->RescriptRelay.Environment.findAllConnectionIds(
// - UserProfile_user_postsConnection({}) // no filters
231
+
// etc.
232
+
```
233
+
234
+
### Bulk record invalidation with `invalidateRecordsByIds`
235
+
236
+
When you need to invalidate many records at once, `RecordSourceSelectorProxy.invalidateRecordsByIds` is more efficient than calling `invalidateRecord` on each record individually.
Copy file name to clipboardExpand all lines: rescript-relay-documentation/docs/mutations.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,6 +154,39 @@ The type safe connection id maker will make life _much_ easier when selecting an
154
154
155
155
All mutation functions you use take an optional prop called `updater`. `updater` is a function that receives the Relay store (`RecordSourceSelectorProxy.t`) and the `'response` from the mutation. It lets you apply any updates to the store in response to a mutation.
156
156
157
+
### Bulk connection operations in mutations
158
+
159
+
When working with mutations that affect connections, you often need to update multiple connection instances. RescriptRelay provides utility functions that make these operations efficient:
160
+
161
+
```rescript
162
+
// Using findAllConnectionIds to add a new item to all connection instances
> For more details on these functions, see [Bulk connection operations](interacting-with-the-store#bulk-connection-operations) and the [API Reference](api-reference#environmentfindallconnectionids).
189
+
157
190
## Declarative, optimistic updates
158
191
159
192
Optimistically updating your UI can do wonders for UX, and Relay provides all the primitives you need to do both simple and more advanced optimistic updates. Let's add a simple optimistic update to this mutation by giving Relay the response that we expect the server to return right away:
0 commit comments