Skip to content

Commit 02db7a9

Browse files
committed
add excludedIds to invalidateRecordsByIds
1 parent c46c03d commit 02db7a9

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# master
22

3-
- Add supprot for top level `@catch` on fragments on unions.
3+
- Add support for top level `@catch` on fragments on unions.
4+
- Add parameter `excludedIds: array<dataId>` to `invalidateRecordsByIds` to allow excluding a list of connection IDs from invalidation.
45

56
# 3.2.0
67

packages/rescript-relay/src/RescriptRelay.res

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,21 @@ module Environment = {
796796
ids
797797
}
798798

799-
let invalidateAllOfConnection = (environment: t, ~connectionKey: string, ~parentId: dataId) => {
799+
let invalidateAllOfConnection = (
800+
environment: t,
801+
~connectionKey: string,
802+
~parentId: dataId,
803+
~excludedIds=[],
804+
) => {
800805
environment->commitLocalUpdate(~updater=store => {
801806
environment
802807
->findAllConnectionIds(~connectionKey, ~parentId)
803808
->Js.Array2.forEach(dataId => {
804-
store
805-
->RecordSourceSelectorProxy.get(~dataId)
806-
->Belt.Option.forEach(r => r->RecordProxy.invalidateRecord)
809+
if !(excludedIds->Js.Array2.includes(dataId)) {
810+
store
811+
->RecordSourceSelectorProxy.get(~dataId)
812+
->Belt.Option.forEach(r => r->RecordProxy.invalidateRecord)
813+
}
807814
})
808815
})
809816
}

packages/rescript-relay/src/RescriptRelay.resi

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,46 @@ You should use the generated `Query.retain` function on your queries instead of
821821
/**Find all connection IDs for a specific connection and on a specific object. Useful together with `@deleteEdge` and similar where you want to remove something from all connection configurations. */
822822
let findAllConnectionIds: (t, ~connectionKey: string, ~parentId: dataId) => array<dataId>
823823

824-
/**Invalidates all connection configurations of `connectionKey` on `parentId`.*/
825-
let invalidateAllOfConnection: (t, ~connectionKey: string, ~parentId: dataId) => unit
824+
/**
825+
Invalidates all connection configurations of `connectionKey` on `parentId`.
826+
827+
This function invalidates all cached data for connections with the specified key on the given parent record.
828+
When connections are invalidated, any queries that depend on this connection data will be considered stale
829+
and will need to be refetched the next time they are accessed.
830+
831+
## Parameters
832+
- `environment`: The Relay environment
833+
- `connectionKey`: The connection key used in the `@connection(key: "...")` directive
834+
- `parentId`: The data ID of the parent record that holds the connection
835+
- `excludedIds`: Optional array of connection data IDs to exclude from invalidation
836+
837+
## Examples
838+
839+
### Basic Usage
840+
```rescript
841+
// Invalidate all connections for a user's friends
842+
environment->RescriptRelay.Environment.invalidateAllOfConnection(
843+
~connectionKey=UserProfile_friends_graphql.connectionKey,
844+
~parentId=user.__id,
845+
)
846+
```
847+
848+
### With Excluded IDs
849+
```rescript
850+
environment->RescriptRelay.Environment.invalidateAllOfConnection(
851+
~connectionKey=UserProfile_friends_graphql.connectionKey,
852+
~parentId=user.__id,
853+
// Invalidate all of this connection except for the currently rendered one.
854+
~excludedIds=[currentConnection.__id],
855+
)
856+
```
857+
*/
858+
let invalidateAllOfConnection: (
859+
t,
860+
~connectionKey: string,
861+
~parentId: dataId,
862+
~excludedIds: array<dataId>=?,
863+
) => unit
826864
}
827865

828866
/**fetchPolicy controls how you want Relay to resolve your data.*/

0 commit comments

Comments
 (0)