rescript-relay 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # master
2
2
 
3
- **All work on version `2.x` is in the [2.x branch](https://github.com/zth/rescript-relay/tree/2.x).**
3
+ # 3.0.1
4
4
 
5
- # **Version 3**
5
+ - Add `Environment.findAllConnectionIds` for finding all IDs of all connection instances for a specific connection, regardless of what configs that connection has been fetched (and cached) with.
6
+ - Add `RecordSourceSelectorProxy.invalidateRecordsByIds` for invalidating multilple records at the same time.
7
+ - Allow configuring input unions via `inputUnions` in `relay.config.js` as an escape hatch for when `@oneOf` support on your server is tricky to set up.
8
+ - Move `@rescript/react` to `>=0.13.0`.
6
9
 
7
10
  # 3.0.0 stable
8
11
 
package/README.md CHANGED
@@ -103,8 +103,8 @@ let make = () => {
103
103
  There's plenty of work ongoing to bring RescriptRelay to full ReScript v11 support, including uncurried mode. Here's the versioning scheme that'll be followed going forward:
104
104
 
105
105
  - 1.x will receive critical bug fixes etc, but new features won't be added
106
- - 2.x will soon ship, and it'll focus on compatibility with ReScript v11, and uncurried mode (uncurried mode will be optional). This is intended to make the transition to v11+ smooth
107
- - 3.x will also soon ship, and that'll fully embrace uncurried mode (no curried mode available), and add a bunch of new stuff + change existing APIs to make them better and more ergonomic
106
+ - 2.x will focus on compatibility with ReScript v11, and uncurried mode (uncurried mode will be optional). This is intended to make the transition to v11+ smooth
107
+ - 3.x is fully embracing uncurried mode (no curried mode available), and adds a bunch of new stuff + change existing APIs to make them better and more ergonomic
108
108
 
109
109
  ## Examples
110
110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rescript-relay",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "main": "src/RescriptRelay.res",
5
5
  "license": "MIT",
6
6
  "author": "Gabriel Nordeborn",
@@ -54,7 +54,7 @@
54
54
  "rescript": "11.1.1"
55
55
  },
56
56
  "peerDependencies": {
57
- "@rescript/react": "^0.12.1",
57
+ "@rescript/react": ">=0.13.0",
58
58
  "react-relay": "17.0.0",
59
59
  "relay-runtime": "17.0.0",
60
60
  "rescript": "^11.0.0"
package/ppx-macos-arm64 CHANGED
Binary file
package/ppx-macos-latest CHANGED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -3,7 +3,9 @@
3
3
 
4
4
  var React = require("react");
5
5
  var Utils = require("./utils");
6
+ var Js_dict = require("rescript/lib/js/js_dict.js");
6
7
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
8
+ var Belt_Option = require("rescript/lib/js/belt_Option.js");
7
9
  var Caml_option = require("rescript/lib/js/caml_option.js");
8
10
  var ReactRelay = require("react-relay");
9
11
  var RelayRuntime = require("relay-runtime");
@@ -42,8 +44,17 @@ function getPluralRootField(t, fieldName) {
42
44
  return optArrayOfNullableToOptArrayOfOpt(Caml_option.nullable_to_opt(t.getPluralRootField(fieldName)));
43
45
  }
44
46
 
47
+ function invalidateRecordsByIds(store, recordIds) {
48
+ recordIds.forEach(function (dataId) {
49
+ Belt_Option.forEach(Caml_option.nullable_to_opt(store.get(dataId)), (function (r) {
50
+ r.invalidateRecord();
51
+ }));
52
+ });
53
+ }
54
+
45
55
  var RecordSourceSelectorProxy = {
46
- getPluralRootField: getPluralRootField
56
+ getPluralRootField: getPluralRootField,
57
+ invalidateRecordsByIds: invalidateRecordsByIds
47
58
  };
48
59
 
49
60
  var ReadOnlyRecordSourceProxy = {};
@@ -231,8 +242,35 @@ function make$1(network, store, getDataID, treatMissingFieldsAsNull, missingFiel
231
242
  });
232
243
  }
233
244
 
245
+ function findAllConnectionIds(environment, connectionKey, parentId) {
246
+ var ids = [];
247
+ var value = environment.getStore().getSource()._records.get(parentId);
248
+ if (value !== undefined) {
249
+ Js_dict.entries(value).forEach(function (param) {
250
+ if (param[0].startsWith("__" + connectionKey + "_connection")) {
251
+ ids.push(param[1].__ref);
252
+ return ;
253
+ }
254
+
255
+ });
256
+ }
257
+ return ids;
258
+ }
259
+
260
+ function invalidateAllOfConnection(environment, connectionKey, parentId) {
261
+ RelayRuntime.commitLocalUpdate(environment, (function (store) {
262
+ findAllConnectionIds(environment, connectionKey, parentId).forEach(function (dataId) {
263
+ Belt_Option.forEach(Caml_option.nullable_to_opt(store.get(dataId)), (function (r) {
264
+ r.invalidateRecord();
265
+ }));
266
+ });
267
+ }));
268
+ }
269
+
234
270
  var Environment = {
235
- make: make$1
271
+ make: make$1,
272
+ findAllConnectionIds: findAllConnectionIds,
273
+ invalidateAllOfConnection: invalidateAllOfConnection
236
274
  };
237
275
 
238
276
  function RescriptRelay$Context$Provider(props) {
@@ -312,6 +312,12 @@ module RecordSourceSelectorProxy = {
312
312
  getPluralRootField(t, ~fieldName)->optArrayOfNullableToOptArrayOfOpt
313
313
 
314
314
  @send external invalidateStore: t => unit = "invalidateStore"
315
+
316
+ let invalidateRecordsByIds: (t, array<dataId>) => unit = (store, recordIds) => {
317
+ recordIds->Js.Array2.forEach(dataId => {
318
+ store->get(~dataId)->Belt.Option.forEach(r => r->RecordProxy.invalidateRecord)
319
+ })
320
+ }
315
321
  }
316
322
 
317
323
  module ReadOnlyRecordSourceProxy = {
@@ -734,6 +740,43 @@ module Environment = {
734
740
  @send
735
741
  external commitPayload: (t, operationDescriptor, 'payload) => unit = "commitPayload"
736
742
  @send external retain: (t, operationDescriptor) => Disposable.t = "retain"
743
+
744
+ @module("relay-runtime")
745
+ external commitLocalUpdate: (t, ~updater: RecordSourceSelectorProxy.t => unit) => unit =
746
+ "commitLocalUpdate"
747
+
748
+ @send external mapGet: (Js.Map.t<'key, 'value>, 'key) => option<'value> = "get"
749
+
750
+ type recordValue = {__ref: dataId}
751
+ @get external _records: RecordSource.t => Js.Map.t<string, Js.Dict.t<recordValue>> = "_records"
752
+
753
+ let findAllConnectionIds = (environment: t, ~connectionKey: string, ~parentId: dataId) => {
754
+ let ids = []
755
+ switch environment->getStore->Store.getSource->_records->mapGet(parentId->dataIdToString) {
756
+ | Some(value) =>
757
+ value
758
+ ->Js.Dict.entries
759
+ ->Js.Array2.forEach(((key, v)) => {
760
+ if key->Js.String2.startsWith("__" ++ connectionKey ++ "_connection") {
761
+ let _ = ids->Js.Array2.push(v.__ref)
762
+ }
763
+ })
764
+ | _ => ()
765
+ }
766
+ ids
767
+ }
768
+
769
+ let invalidateAllOfConnection = (environment: t, ~connectionKey: string, ~parentId: dataId) => {
770
+ environment->commitLocalUpdate(~updater=store => {
771
+ environment
772
+ ->findAllConnectionIds(~connectionKey, ~parentId)
773
+ ->Js.Array2.forEach(dataId => {
774
+ store
775
+ ->RecordSourceSelectorProxy.get(~dataId)
776
+ ->Belt.Option.forEach(r => r->RecordProxy.invalidateRecord)
777
+ })
778
+ })
779
+ }
737
780
  }
738
781
 
739
782
  module Context = {
@@ -399,6 +399,9 @@ module RecordSourceSelectorProxy: {
399
399
  /**Invalidates the entire store. This means that _at the next render_, the entire store will be treated as empty, meaning Relay will refetch everything it needs to show the view it's to show.*/
400
400
  @send
401
401
  external invalidateStore: t => unit = "invalidateStore"
402
+
403
+ /**Invalidates each of the provided records by their ID, if they exist. */
404
+ let invalidateRecordsByIds: (t, array<dataId>) => unit
402
405
  }
403
406
 
404
407
  /**ReadOnlyRecordSourceProxy is the store, but in read-only mode.*/
@@ -785,6 +788,12 @@ module Environment: {
785
788
  You should use the generated `Query.retain` function on your queries instead of using this directly.*/
786
789
  @send
787
790
  external retain: (t, operationDescriptor) => Disposable.t = "retain"
791
+
792
+ /**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. */
793
+ let findAllConnectionIds: (t, ~connectionKey: string, ~parentId: dataId) => array<dataId>
794
+
795
+ /**Invalidates all connection configurations of `connectionKey` on `parentId`.*/
796
+ let invalidateAllOfConnection: (t, ~connectionKey: string, ~parentId: dataId) => unit
788
797
  }
789
798
 
790
799
  /**fetchPolicy controls how you want Relay to resolve your data.*/