rescript-relay 3.1.0 → 3.2.0

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,7 +1,17 @@
1
1
  # master
2
2
 
3
+ # 3.2.0
4
+
5
+ - Add support for the new Relay `@catch` directive. https://github.com/zth/rescript-relay/pull/549
6
+ - Add support for `usePrefetchableForwardPagination`. https://github.com/zth/rescript-relay/pull/551
7
+ - Remove `useBlockingPagination` since it's being removed from Relay.
8
+
3
9
  # 3.1.0
4
10
 
11
+ This brings the Relay version to `18.2.0`.
12
+
13
+ If you have enabled the feature flags in `relay.config.js` for aliased fragments or Relay resolvers you'll need to remove them from the config file as they are now on by default, and not removing them will cause the compiler to fail with a non super helpful error message.
14
+
5
15
  - **Upgrade versions**: `react-relay` and `relay-runtime` to `18.2.0`.
6
16
  - Add support for `Fragment.waitForFragmentData`, a new API in Relay 18.2 that lets you wait for fragment data outside of React.
7
17
  - Experimental: Add a "non React" mode to the PPX, which makes sure only APIs that don't rely on React directly are exposed. This is intended to be a way to simplify using RescriptRelay without React. Activate by passing `-non-react` to the PPX, like `"ppx-flags": [["rescript-relay/ppx", "-non-react"]]`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rescript-relay",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "main": "src/RescriptRelay.res",
5
5
  "license": "MIT",
6
6
  "author": "Gabriel Nordeborn",
package/ppx-linux CHANGED
Binary file
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
@@ -13,6 +13,32 @@ var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
13
13
  var LiveResolverStore = require("relay-runtime/lib/store/live-resolvers/LiveResolverStore").default;
14
14
  var LiveResolverStore$1 = require("relay-runtime/lib/store/live-resolvers/LiveResolverStore");
15
15
 
16
+ function toOption(t) {
17
+ if (t.ok === true) {
18
+ return Caml_option.some(t.value);
19
+ }
20
+
21
+ }
22
+
23
+ function toResult(t) {
24
+ if (t.ok === true) {
25
+ return {
26
+ TAG: "Ok",
27
+ _0: t.value
28
+ };
29
+ } else {
30
+ return {
31
+ TAG: "Error",
32
+ _0: t.errors
33
+ };
34
+ }
35
+ }
36
+
37
+ var CatchResult = {
38
+ toOption: toOption,
39
+ toResult: toResult
40
+ };
41
+
16
42
  var SuspenseSentinel = {};
17
43
 
18
44
  function convertObj(prim0, prim1, prim2, prim3) {
@@ -345,6 +371,7 @@ function MakeLoadQuery(C) {
345
371
 
346
372
  var Mutation_failed = /* @__PURE__ */Caml_exceptions.create("RescriptRelay.Mutation_failed");
347
373
 
374
+ exports.CatchResult = CatchResult;
348
375
  exports.SuspenseSentinel = SuspenseSentinel;
349
376
  exports.convertObj = convertObj;
350
377
  exports.RecordProxy = RecordProxy;
@@ -17,6 +17,25 @@ type dataIdObject = {id: dataId}
17
17
  type recordSourceRecords = Js.Json.t
18
18
  type uploadables
19
19
 
20
+ module CatchResult = {
21
+ type catchError = Js.Json.t
22
+
23
+ @tag("ok")
24
+ type t<'value> = | @as(true) Ok({value: 'value}) | @as(false) Error({errors: array<catchError>})
25
+
26
+ let toOption = (t: t<'value>) =>
27
+ switch t {
28
+ | Ok({value}) => Some(value)
29
+ | Error(_) => None
30
+ }
31
+
32
+ let toResult = (t: t<'value>): result<'value, array<catchError>> =>
33
+ switch t {
34
+ | Ok({value}) => Ok(value)
35
+ | Error({errors}) => Error(errors)
36
+ }
37
+ }
38
+
20
39
  module SuspenseSentinel = {
21
40
  type t
22
41
 
@@ -41,6 +41,24 @@ type dataId
41
41
 
42
42
  type dataIdObject = {id: dataId}
43
43
 
44
+ /** A module for results originating from the @catch directive. */
45
+ module CatchResult: {
46
+ /** The shape of an error caught via @catch. */
47
+ type catchError = Js.Json.t
48
+
49
+ /** The result type for @catch. */
50
+ @tag("ok")
51
+ type t<'value> =
52
+ | @as(true) Ok({value: 'value})
53
+ | @as(false) Error({errors: array<catchError>})
54
+
55
+ /** Convert a @catch result to option. */
56
+ let toOption: t<'value> => option<'value>
57
+
58
+ /** Convert a @catch result to result. */
59
+ let toResult: t<'value> => result<'value, array<catchError>>
60
+ }
61
+
44
62
  module SuspenseSentinel: {
45
63
  type t
46
64
 
@@ -7,7 +7,6 @@ var ReactRelay = require("react-relay");
7
7
  var RescriptRelay_Internal = require("./RescriptRelay_Internal.bs.js");
8
8
  var Experimental = require("relay-runtime/experimental");
9
9
  var ResolverFragments = require("relay-runtime/lib/store/ResolverFragments");
10
- var UseBlockingPaginationFragment = require("react-relay/lib/relay-hooks/legacy/useBlockingPaginationFragment").default;
11
10
 
12
11
  function useFragment(node, convertFragment, fRef) {
13
12
  var __x = ReactRelay.useFragment(node, fRef);
@@ -70,11 +69,13 @@ function usePaginationFragment(node, fRef, convertFragment, convertRefetchVariab
70
69
  };
71
70
  }
72
71
 
73
- function useBlockingPaginationFragment(node, fRef, convertFragment, convertRefetchVariables) {
74
- var p = UseBlockingPaginationFragment(node, fRef);
72
+ function usePrefetchableForwardPagination(node, fRef, convertEdges, convertFragment, convertRefetchVariables, bufferSize, initialSize, prefetchingLoadMoreOptions, minimumFetchSize) {
73
+ var p = ReactRelay.usePrefetchableForwardPaginationFragment_EXPERIMENTAL(node, fRef, bufferSize, initialSize !== undefined ? Caml_option.valFromOption(initialSize) : undefined, prefetchingLoadMoreOptions !== undefined ? Caml_option.valFromOption(prefetchingLoadMoreOptions) : undefined, minimumFetchSize !== undefined ? Caml_option.valFromOption(minimumFetchSize) : undefined);
75
74
  var data = RescriptRelay_Internal.internal_useConvertedValue(convertFragment, p.data);
75
+ var edges = RescriptRelay_Internal.internal_useConvertedValue(convertEdges, p.edges);
76
76
  return {
77
77
  data: data,
78
+ edges: edges,
78
79
  loadNext: React.useMemo((function () {
79
80
  return function (count, onComplete) {
80
81
  return p.loadNext(count, {
@@ -82,15 +83,8 @@ function useBlockingPaginationFragment(node, fRef, convertFragment, convertRefet
82
83
  });
83
84
  };
84
85
  }), [p.loadNext]),
85
- loadPrevious: React.useMemo((function () {
86
- return function (count, onComplete) {
87
- return p.loadPrevious(count, {
88
- onComplete: RescriptRelay_Internal.internal_nullableToOptionalExnHandler(onComplete)
89
- });
90
- };
91
- }), [p.loadPrevious]),
92
86
  hasNext: p.hasNext,
93
- hasPrevious: p.hasPrevious,
87
+ isLoadingNext: p.isLoadingNext,
94
88
  refetch: React.useMemo((function () {
95
89
  return function (variables, fetchPolicy, onComplete) {
96
90
  return p.refetch(RescriptRelay_Internal.internal_cleanObjectFromUndefinedRaw(convertRefetchVariables(variables)), internal_makeRefetchableFnOpts(fetchPolicy, onComplete, undefined));
@@ -123,7 +117,7 @@ exports.useFragmentOpt = useFragmentOpt;
123
117
  exports.readInlineData = readInlineData;
124
118
  exports.read = read;
125
119
  exports.usePaginationFragment = usePaginationFragment;
126
- exports.useBlockingPaginationFragment = useBlockingPaginationFragment;
120
+ exports.usePrefetchableForwardPagination = usePrefetchableForwardPagination;
127
121
  exports.useRefetchableFragment = useRefetchableFragment;
128
122
  exports.waitForFragmentData = waitForFragmentData;
129
123
  /* react Not a pure module */
@@ -84,18 +84,6 @@ type paginationFragmentReturnRaw<'fragment, 'refetchVariables> = {
84
84
  isLoadingPrevious: bool,
85
85
  refetch: ('refetchVariables, refetchableFnOpts) => Disposable.t,
86
86
  }
87
- type paginationBlockingFragmentReturn<'fragment, 'refetchVariables> = {
88
- data: 'fragment,
89
- loadNext: paginationLoadMoreFn,
90
- loadPrevious: paginationLoadMoreFn,
91
- hasNext: bool,
92
- hasPrevious: bool,
93
- refetch: (
94
- ~variables: 'refetchVariables,
95
- ~fetchPolicy: fetchPolicy=?,
96
- ~onComplete: option<Js.Exn.t> => unit=?,
97
- ) => Disposable.t,
98
- }
99
87
  type paginationFragmentReturn<'fragment, 'refetchVariables> = {
100
88
  data: 'fragment,
101
89
  loadNext: paginationLoadMoreFn,
@@ -117,10 +105,7 @@ external usePaginationFragment_: (
117
105
  'fragmentRef,
118
106
  ) => paginationFragmentReturnRaw<'fragment, 'refetchVariables> = "usePaginationFragment"
119
107
 
120
- /** React hook for paginating a fragment. Paginating with \
121
- this hook will _not_ cause your component to suspend. \
122
- If you want pagination to trigger suspense, look into \
123
- using `Fragment.useBlockingPagination`.*/
108
+ /** React hook for paginating a fragment. Paginating with this hook will _not_ cause your component to suspend. */
124
109
  let usePaginationFragment = (
125
110
  ~node,
126
111
  ~fRef,
@@ -158,39 +143,71 @@ let usePaginationFragment = (
158
143
  }
159
144
  }
160
145
 
161
- @module("react-relay/lib/relay-hooks/legacy/useBlockingPaginationFragment")
162
- external useBlockingPaginationFragment_: (
146
+ type prefetchableForwardPaginationFragmentReturnRaw<'fragment, 'edges, 'refetchVariables> = {
147
+ data: 'fragment,
148
+ edges: 'edges,
149
+ loadNext: (int, paginationLoadMoreOptions) => Disposable.t,
150
+ hasNext: bool,
151
+ isLoadingNext: bool,
152
+ refetch: ('refetchVariables, refetchableFnOpts) => Disposable.t,
153
+ }
154
+ type prefetchableForwardPaginationFragmentReturn<'fragment, 'edges, 'refetchVariables> = {
155
+ data: 'fragment,
156
+ edges: 'edges,
157
+ loadNext: paginationLoadMoreFn,
158
+ hasNext: bool,
159
+ isLoadingNext: bool,
160
+ refetch: (
161
+ ~variables: 'refetchVariables,
162
+ ~fetchPolicy: fetchPolicy=?,
163
+ ~onComplete: option<Js.Exn.t> => unit=?,
164
+ ) => Disposable.t,
165
+ }
166
+
167
+ @module("react-relay")
168
+ external usePrefetchableForwardPaginationFragment_: (
163
169
  fragmentNode<'node>,
164
170
  'fragmentRef,
165
- ) => paginationFragmentReturnRaw<'fragment, 'refetchVariables> = "default"
171
+ ~bufferSize: int,
172
+ ~initialSize: int=?,
173
+ ~prefetchingLoadMoreOptions: paginationLoadMoreOptions=?,
174
+ ~minimumFetchSize: int=?,
175
+ ) => prefetchableForwardPaginationFragmentReturnRaw<'fragment, 'edges, 'refetchVariables> =
176
+ "usePrefetchableForwardPaginationFragment_EXPERIMENTAL"
166
177
 
167
- /** Like `Fragment.usePagination`, but calling the \
168
- pagination function will trigger suspense. Useful for \
169
- all-at-once pagination.*/
170
- let useBlockingPaginationFragment = (
178
+ /** React hook for paginating a fragment. Paginating with this hook will _not_ cause your component to suspend. */
179
+ let usePrefetchableForwardPagination = (
171
180
  ~node,
172
181
  ~fRef,
182
+ ~convertEdges: 'edges => 'edges,
173
183
  ~convertFragment: 'fragment => 'fragment,
174
184
  ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
185
+ ~bufferSize: int,
186
+ ~initialSize: option<int>=?,
187
+ ~prefetchingLoadMoreOptions: option<paginationLoadMoreOptions>=?,
188
+ ~minimumFetchSize: option<int>=?,
175
189
  ) => {
176
- let p = useBlockingPaginationFragment_(node, fRef)
190
+ let p = usePrefetchableForwardPaginationFragment_(
191
+ node,
192
+ fRef,
193
+ ~bufferSize,
194
+ ~initialSize?,
195
+ ~prefetchingLoadMoreOptions?,
196
+ ~minimumFetchSize?,
197
+ )
177
198
  let data = RescriptRelay_Internal.internal_useConvertedValue(convertFragment, p.data)
199
+ let edges = RescriptRelay_Internal.internal_useConvertedValue(convertEdges, p.edges)
178
200
  {
179
201
  data,
202
+ edges,
180
203
  loadNext: React.useMemo1(() => (~count, ~onComplete=?) => {
181
204
  p.loadNext(
182
205
  count,
183
206
  {onComplete: ?onComplete->RescriptRelay_Internal.internal_nullableToOptionalExnHandler},
184
207
  )
185
208
  }, [p.loadNext]),
186
- loadPrevious: React.useMemo1(() => (~count, ~onComplete=?) => {
187
- p.loadPrevious(
188
- count,
189
- {onComplete: ?onComplete->RescriptRelay_Internal.internal_nullableToOptionalExnHandler},
190
- )
191
- }, [p.loadPrevious]),
192
209
  hasNext: p.hasNext,
193
- hasPrevious: p.hasPrevious,
210
+ isLoadingNext: p.isLoadingNext,
194
211
  refetch: React.useMemo1(() => (~variables, ~fetchPolicy=?, ~onComplete=?) => {
195
212
  p.refetch(
196
213
  RescriptRelay_Internal.internal_cleanObjectFromUndefinedRaw(
@@ -28,12 +28,14 @@ type paginationLoadMoreOptions = {onComplete?: Js.Nullable.t<Js.Exn.t> => unit}
28
28
 
29
29
  type paginationLoadMoreFn = (~count: int, ~onComplete: option<Js.Exn.t> => unit=?) => Disposable.t
30
30
 
31
- type paginationBlockingFragmentReturn<'fragment, 'refetchVariables> = {
31
+ type paginationFragmentReturn<'fragment, 'refetchVariables> = {
32
32
  data: 'fragment,
33
33
  loadNext: paginationLoadMoreFn,
34
34
  loadPrevious: paginationLoadMoreFn,
35
35
  hasNext: bool,
36
36
  hasPrevious: bool,
37
+ isLoadingNext: bool,
38
+ isLoadingPrevious: bool,
37
39
  refetch: (
38
40
  ~variables: 'refetchVariables,
39
41
  ~fetchPolicy: fetchPolicy=?,
@@ -41,14 +43,19 @@ type paginationBlockingFragmentReturn<'fragment, 'refetchVariables> = {
41
43
  ) => Disposable.t,
42
44
  }
43
45
 
44
- type paginationFragmentReturn<'fragment, 'refetchVariables> = {
46
+ let usePaginationFragment: (
47
+ ~node: fragmentNode<'a>,
48
+ ~fRef: 'b,
49
+ ~convertFragment: 'fragment => 'fragment,
50
+ ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
51
+ ) => paginationFragmentReturn<'fragment, 'refetchVariables>
52
+
53
+ type prefetchableForwardPaginationFragmentReturn<'fragment, 'edges, 'refetchVariables> = {
45
54
  data: 'fragment,
55
+ edges: 'edges,
46
56
  loadNext: paginationLoadMoreFn,
47
- loadPrevious: paginationLoadMoreFn,
48
57
  hasNext: bool,
49
- hasPrevious: bool,
50
58
  isLoadingNext: bool,
51
- isLoadingPrevious: bool,
52
59
  refetch: (
53
60
  ~variables: 'refetchVariables,
54
61
  ~fetchPolicy: fetchPolicy=?,
@@ -56,19 +63,17 @@ type paginationFragmentReturn<'fragment, 'refetchVariables> = {
56
63
  ) => Disposable.t,
57
64
  }
58
65
 
59
- let usePaginationFragment: (
60
- ~node: fragmentNode<'a>,
61
- ~fRef: 'b,
62
- ~convertFragment: 'fragment => 'fragment,
63
- ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
64
- ) => paginationFragmentReturn<'fragment, 'refetchVariables>
65
-
66
- let useBlockingPaginationFragment: (
66
+ let usePrefetchableForwardPagination: (
67
67
  ~node: fragmentNode<'a>,
68
68
  ~fRef: 'b,
69
+ ~convertEdges: 'edges => 'edges,
69
70
  ~convertFragment: 'fragment => 'fragment,
70
71
  ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
71
- ) => paginationBlockingFragmentReturn<'fragment, 'refetchVariables>
72
+ ~bufferSize: int,
73
+ ~initialSize: int=?,
74
+ ~prefetchingLoadMoreOptions: paginationLoadMoreOptions=?,
75
+ ~minimumFetchSize: int=?,
76
+ ) => prefetchableForwardPaginationFragmentReturn<'fragment, 'edges, 'refetchVariables>
72
77
 
73
78
  let useRefetchableFragment: (
74
79
  ~node: fragmentNode<'a>,