rescript-relay 0.0.0-autocodesplit-09ee6f6c

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +942 -0
  2. package/README.md +111 -0
  3. package/cli/cli.js +472 -0
  4. package/compiler.js +11 -0
  5. package/package.json +65 -0
  6. package/postinstall.js +189 -0
  7. package/ppx-linux +0 -0
  8. package/ppx-macos-arm64 +0 -0
  9. package/ppx-macos-latest +0 -0
  10. package/ppx-windows-latest +0 -0
  11. package/relay-compiler-linux-musl/relay +0 -0
  12. package/relay-compiler-linux-x64/relay +0 -0
  13. package/relay-compiler-macos-arm64/relay +0 -0
  14. package/relay-compiler-macos-x64/relay +0 -0
  15. package/relay-compiler-win-x64/relay.exe +0 -0
  16. package/rescript.json +19 -0
  17. package/src/ReactDOMExperimental.bs.js +23 -0
  18. package/src/ReactDOMExperimental.res +16 -0
  19. package/src/ReactExperimental.bs.js +23 -0
  20. package/src/ReactExperimental.res +21 -0
  21. package/src/ReactExperimental.resi +18 -0
  22. package/src/RescriptRelay.bs.js +329 -0
  23. package/src/RescriptRelay.res +858 -0
  24. package/src/RescriptRelay.resi +897 -0
  25. package/src/RescriptRelayUtils.bs.js +76 -0
  26. package/src/RescriptRelayUtils.res +89 -0
  27. package/src/RescriptRelayUtils.resi +36 -0
  28. package/src/RescriptRelay_Fragment.bs.js +122 -0
  29. package/src/RescriptRelay_Fragment.res +243 -0
  30. package/src/RescriptRelay_Fragment.resi +85 -0
  31. package/src/RescriptRelay_Internal.bs.js +102 -0
  32. package/src/RescriptRelay_Internal.res +71 -0
  33. package/src/RescriptRelay_Internal.resi +20 -0
  34. package/src/RescriptRelay_Mutation.bs.js +57 -0
  35. package/src/RescriptRelay_Mutation.res +144 -0
  36. package/src/RescriptRelay_Mutation.resi +52 -0
  37. package/src/RescriptRelay_Query.bs.js +101 -0
  38. package/src/RescriptRelay_Query.res +177 -0
  39. package/src/RescriptRelay_Query.resi +62 -0
  40. package/src/RescriptRelay_RelayResolvers.bs.js +13 -0
  41. package/src/RescriptRelay_RelayResolvers.res +21 -0
  42. package/src/RescriptRelay_RelayResolvers.resi +10 -0
  43. package/src/RescriptRelay_Subscriptions.bs.js +24 -0
  44. package/src/RescriptRelay_Subscriptions.res +50 -0
  45. package/src/RescriptRelay_Subscriptions.resi +14 -0
  46. package/src/utils.js +418 -0
  47. package/src/utils.mjs +418 -0
@@ -0,0 +1,76 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+ 'use strict';
3
+
4
+ var List = require("rescript/lib/js/list.js");
5
+ var Belt_List = require("rescript/lib/js/belt_List.js");
6
+ var Caml_option = require("rescript/lib/js/caml_option.js");
7
+ var RelayRuntime = require("relay-runtime");
8
+
9
+ function resolveNestedRecord(rootRecord, path) {
10
+ var currentRecord = rootRecord;
11
+ var pathLength = List.length(path);
12
+ if (pathLength !== 0) {
13
+ for(var i = 0; i < pathLength; ++i){
14
+ var currentPath = Belt_List.get(path, i);
15
+ var match = currentRecord;
16
+ currentRecord = match !== undefined && currentPath !== undefined ? Caml_option.nullable_to_opt(Caml_option.valFromOption(match).getLinkedRecord(currentPath)) : undefined;
17
+ }
18
+ }
19
+ return currentRecord;
20
+ }
21
+
22
+ function resolveNestedRecordFromRoot(store, path) {
23
+ if (!path) {
24
+ return ;
25
+ }
26
+ var restPath = path.tl;
27
+ var rootRecordPath = path.hd;
28
+ if (restPath) {
29
+ return resolveNestedRecord(Caml_option.nullable_to_opt(store.getRootField(rootRecordPath)), restPath);
30
+ }
31
+ var rootRecord = store.getRootField(rootRecordPath);
32
+ if (!(rootRecord == null)) {
33
+ return Caml_option.some(rootRecord);
34
+ }
35
+
36
+ }
37
+
38
+ function removeNodeFromConnections(store, node, connections) {
39
+ Belt_List.forEach(connections, (function (connectionConfig) {
40
+ var owner = store.get(connectionConfig.parentID);
41
+ if (owner == null) {
42
+ return ;
43
+ }
44
+ var connection = RelayRuntime.ConnectionHandler.getConnection(owner, connectionConfig.key, connectionConfig.filters !== undefined ? Caml_option.valFromOption(connectionConfig.filters) : undefined);
45
+ if (!(connection == null)) {
46
+ RelayRuntime.ConnectionHandler.deleteNode(connection, node.getDataID());
47
+ return ;
48
+ }
49
+
50
+ }));
51
+ }
52
+
53
+ function createAndAddEdgeToConnections(store, node, connections, edgeName, insertAt) {
54
+ Belt_List.forEach(connections, (function (connectionConfig) {
55
+ var connectionOwner = store.get(connectionConfig.parentID);
56
+ if (connectionOwner == null) {
57
+ return ;
58
+ }
59
+ var connection = RelayRuntime.ConnectionHandler.getConnection(connectionOwner, connectionConfig.key, connectionConfig.filters !== undefined ? Caml_option.valFromOption(connectionConfig.filters) : undefined);
60
+ if (connection == null) {
61
+ return ;
62
+ }
63
+ var edge = RelayRuntime.ConnectionHandler.createEdge(store, connection, node, edgeName);
64
+ if (insertAt === "Start") {
65
+ RelayRuntime.ConnectionHandler.insertEdgeAfter(connection, edge);
66
+ return ;
67
+ }
68
+ RelayRuntime.ConnectionHandler.insertEdgeBefore(connection, edge);
69
+ }));
70
+ }
71
+
72
+ exports.resolveNestedRecord = resolveNestedRecord;
73
+ exports.resolveNestedRecordFromRoot = resolveNestedRecordFromRoot;
74
+ exports.removeNodeFromConnections = removeNodeFromConnections;
75
+ exports.createAndAddEdgeToConnections = createAndAddEdgeToConnections;
76
+ /* relay-runtime Not a pure module */
@@ -0,0 +1,89 @@
1
+ open RescriptRelay
2
+
3
+ let resolveNestedRecord = (
4
+ ~rootRecord: option<RescriptRelay.RecordProxy.t>,
5
+ ~path: list<string>,
6
+ ) => {
7
+ let currentRecord = ref(rootRecord)
8
+ let pathLength = List.length(path)
9
+
10
+ switch pathLength {
11
+ | 0 => ()
12
+ | _ =>
13
+ for i in 0 to pathLength - 1 {
14
+ let currentPath = path->Belt.List.get(i)
15
+ switch (currentRecord.contents, currentPath) {
16
+ | (Some(record), Some(currentPath)) =>
17
+ currentRecord := record->RescriptRelay.RecordProxy.getLinkedRecord(~name=currentPath)
18
+ | _ => currentRecord := None
19
+ }
20
+ }
21
+ }
22
+
23
+ currentRecord.contents
24
+ }
25
+
26
+ let resolveNestedRecordFromRoot = (~store, ~path: list<string>) =>
27
+ switch path {
28
+ | list{} => None
29
+ | list{rootRecordPath} =>
30
+ switch store->RescriptRelay.RecordSourceSelectorProxy.getRootField(~fieldName=rootRecordPath) {
31
+ | Some(rootRecord) => Some(rootRecord)
32
+ | None => None
33
+ }
34
+ | list{rootRecordPath, ...restPath} =>
35
+ resolveNestedRecord(
36
+ ~rootRecord=store->RescriptRelay.RecordSourceSelectorProxy.getRootField(
37
+ ~fieldName=rootRecordPath,
38
+ ),
39
+ ~path=restPath,
40
+ )
41
+ }
42
+
43
+ type insertAt =
44
+ | Start
45
+ | End
46
+
47
+ type connectionConfig = {
48
+ parentID: dataId,
49
+ key: string,
50
+ filters: option<RescriptRelay.arguments>,
51
+ }
52
+
53
+ let removeNodeFromConnections = (~store, ~node, ~connections) =>
54
+ connections->Belt.List.forEach(connectionConfig =>
55
+ switch store->RecordSourceSelectorProxy.get(~dataId=connectionConfig.parentID) {
56
+ | Some(owner) =>
57
+ switch ConnectionHandler.getConnection(
58
+ ~record=owner,
59
+ ~key=connectionConfig.key,
60
+ ~filters=?connectionConfig.filters,
61
+ ) {
62
+ | Some(connection) =>
63
+ ConnectionHandler.deleteNode(~connection, ~nodeId=node->RecordProxy.getDataId)
64
+ | None => ()
65
+ }
66
+ | None => ()
67
+ }
68
+ )
69
+
70
+ let createAndAddEdgeToConnections = (~store, ~node, ~connections, ~edgeName, ~insertAt) =>
71
+ connections->Belt.List.forEach(connectionConfig =>
72
+ switch store->RecordSourceSelectorProxy.get(~dataId=connectionConfig.parentID) {
73
+ | Some(connectionOwner) =>
74
+ switch ConnectionHandler.getConnection(
75
+ ~record=connectionOwner,
76
+ ~key=connectionConfig.key,
77
+ ~filters=?connectionConfig.filters,
78
+ ) {
79
+ | Some(connection) =>
80
+ let edge = ConnectionHandler.createEdge(~store, ~connection, ~node, ~edgeType=edgeName)
81
+ switch insertAt {
82
+ | Start => ConnectionHandler.insertEdgeAfter(~connection, ~newEdge=edge)
83
+ | End => ConnectionHandler.insertEdgeBefore(~connection, ~newEdge=edge)
84
+ }
85
+ | None => ()
86
+ }
87
+ | None => ()
88
+ }
89
+ )
@@ -0,0 +1,36 @@
1
+ /**Tries to return a record from a nested path of linked records.*/
2
+ let resolveNestedRecord: (
3
+ ~rootRecord: option<RescriptRelay.RecordProxy.t>,
4
+ ~path: list<string>,
5
+ ) => option<RescriptRelay.RecordProxy.t>
6
+
7
+ /**Tries to return a record from a nested path of linked records, starting from the root.*/
8
+ let resolveNestedRecordFromRoot: (
9
+ ~store: RescriptRelay.RecordSourceSelectorProxy.t,
10
+ ~path: list<string>,
11
+ ) => option<RescriptRelay.RecordProxy.t>
12
+
13
+ /**Helpers for handling connections.*/
14
+ type insertAt =
15
+ | Start
16
+ | End
17
+
18
+ type connectionConfig = {
19
+ parentID: RescriptRelay.dataId,
20
+ key: string,
21
+ filters: option<RescriptRelay.arguments>,
22
+ }
23
+
24
+ let removeNodeFromConnections: (
25
+ ~store: RescriptRelay.RecordSourceSelectorProxy.t,
26
+ ~node: RescriptRelay.RecordProxy.t,
27
+ ~connections: list<connectionConfig>,
28
+ ) => unit
29
+
30
+ let createAndAddEdgeToConnections: (
31
+ ~store: RescriptRelay.RecordSourceSelectorProxy.t,
32
+ ~node: RescriptRelay.RecordProxy.t,
33
+ ~connections: list<connectionConfig>,
34
+ ~edgeName: string,
35
+ ~insertAt: insertAt,
36
+ ) => unit
@@ -0,0 +1,122 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+ 'use strict';
3
+
4
+ var React = require("react");
5
+ var Caml_option = require("rescript/lib/js/caml_option.js");
6
+ var ReactRelay = require("react-relay");
7
+ var RescriptRelay_Internal = require("./RescriptRelay_Internal.bs.js");
8
+ var ResolverFragments = require("relay-runtime/lib/store/ResolverFragments");
9
+ var UseBlockingPaginationFragment = require("react-relay/lib/relay-hooks/legacy/useBlockingPaginationFragment").default;
10
+
11
+ function useFragment(node, convertFragment, fRef) {
12
+ var __x = ReactRelay.useFragment(node, fRef);
13
+ return RescriptRelay_Internal.internal_useConvertedValue(convertFragment, __x);
14
+ }
15
+
16
+ function useFragmentOpt(fRef, node, convertFragment) {
17
+ var data = ReactRelay.useFragment(node, fRef);
18
+ return React.useMemo((function () {
19
+ if (!(data == null)) {
20
+ return Caml_option.some(convertFragment(data));
21
+ }
22
+
23
+ }), [(data == null) ? undefined : Caml_option.some(data)]);
24
+ }
25
+
26
+ function readInlineData(node, convertFragment, fRef) {
27
+ return convertFragment(ReactRelay.readInlineData(node, fRef));
28
+ }
29
+
30
+ function read(node, convertFragment, fRef) {
31
+ return convertFragment(ResolverFragments.readFragment(node, fRef));
32
+ }
33
+
34
+ function internal_makeRefetchableFnOpts(fetchPolicy, onComplete, param) {
35
+ return {
36
+ fetchPolicy: fetchPolicy,
37
+ onComplete: RescriptRelay_Internal.internal_nullableToOptionalExnHandler(onComplete)
38
+ };
39
+ }
40
+
41
+ function usePaginationFragment(node, fRef, convertFragment, convertRefetchVariables) {
42
+ var p = ReactRelay.usePaginationFragment(node, fRef);
43
+ var data = RescriptRelay_Internal.internal_useConvertedValue(convertFragment, p.data);
44
+ return {
45
+ data: data,
46
+ loadNext: React.useMemo((function () {
47
+ return function (count, onComplete) {
48
+ return p.loadNext(count, {
49
+ onComplete: RescriptRelay_Internal.internal_nullableToOptionalExnHandler(onComplete)
50
+ });
51
+ };
52
+ }), [p.loadNext]),
53
+ loadPrevious: React.useMemo((function () {
54
+ return function (count, onComplete) {
55
+ return p.loadPrevious(count, {
56
+ onComplete: RescriptRelay_Internal.internal_nullableToOptionalExnHandler(onComplete)
57
+ });
58
+ };
59
+ }), [p.loadPrevious]),
60
+ hasNext: p.hasNext,
61
+ hasPrevious: p.hasPrevious,
62
+ isLoadingNext: p.isLoadingNext,
63
+ isLoadingPrevious: p.isLoadingPrevious,
64
+ refetch: React.useMemo((function () {
65
+ return function (variables, fetchPolicy, onComplete) {
66
+ return p.refetch(RescriptRelay_Internal.internal_cleanObjectFromUndefinedRaw(convertRefetchVariables(variables)), internal_makeRefetchableFnOpts(fetchPolicy, onComplete, undefined));
67
+ };
68
+ }), [p.refetch])
69
+ };
70
+ }
71
+
72
+ function useBlockingPaginationFragment(node, fRef, convertFragment, convertRefetchVariables) {
73
+ var p = UseBlockingPaginationFragment(node, fRef);
74
+ var data = RescriptRelay_Internal.internal_useConvertedValue(convertFragment, p.data);
75
+ return {
76
+ data: data,
77
+ loadNext: React.useMemo((function () {
78
+ return function (count, onComplete) {
79
+ return p.loadNext(count, {
80
+ onComplete: RescriptRelay_Internal.internal_nullableToOptionalExnHandler(onComplete)
81
+ });
82
+ };
83
+ }), [p.loadNext]),
84
+ loadPrevious: React.useMemo((function () {
85
+ return function (count, onComplete) {
86
+ return p.loadPrevious(count, {
87
+ onComplete: RescriptRelay_Internal.internal_nullableToOptionalExnHandler(onComplete)
88
+ });
89
+ };
90
+ }), [p.loadPrevious]),
91
+ hasNext: p.hasNext,
92
+ hasPrevious: p.hasPrevious,
93
+ refetch: React.useMemo((function () {
94
+ return function (variables, fetchPolicy, onComplete) {
95
+ return p.refetch(RescriptRelay_Internal.internal_cleanObjectFromUndefinedRaw(convertRefetchVariables(variables)), internal_makeRefetchableFnOpts(fetchPolicy, onComplete, undefined));
96
+ };
97
+ }), [p.refetch])
98
+ };
99
+ }
100
+
101
+ function useRefetchableFragment(node, convertFragment, convertRefetchVariables, fRef) {
102
+ var match = ReactRelay.useRefetchableFragment(node, fRef);
103
+ var refetchFn = match[1];
104
+ var data = RescriptRelay_Internal.internal_useConvertedValue(convertFragment, match[0]);
105
+ return [
106
+ data,
107
+ React.useMemo((function () {
108
+ return function (variables, fetchPolicy, onComplete) {
109
+ return refetchFn(RescriptRelay_Internal.internal_removeUndefinedAndConvertNullsRaw(convertRefetchVariables(variables)), internal_makeRefetchableFnOpts(fetchPolicy, onComplete, undefined));
110
+ };
111
+ }), [refetchFn])
112
+ ];
113
+ }
114
+
115
+ exports.useFragment = useFragment;
116
+ exports.useFragmentOpt = useFragmentOpt;
117
+ exports.readInlineData = readInlineData;
118
+ exports.read = read;
119
+ exports.usePaginationFragment = usePaginationFragment;
120
+ exports.useBlockingPaginationFragment = useBlockingPaginationFragment;
121
+ exports.useRefetchableFragment = useRefetchableFragment;
122
+ /* react Not a pure module */
@@ -0,0 +1,243 @@
1
+ open RescriptRelay
2
+
3
+ @module("react-relay")
4
+ external useFragment_: (fragmentNode<'node>, 'fragmentRef) => 'fragment = "useFragment"
5
+
6
+ let useFragment = (~node, ~convertFragment: 'fragment => 'fragment, ~fRef) => {
7
+ /** React hook for getting the data of this fragment. Pass \
8
+ the `fragmentRefs` of any object where you've spread your \
9
+ fragment into this and get the fragment data back.\n\n\
10
+ ### Fragment data outside of React's render\n\
11
+ If you're looking for a way to use fragments _outside_ of \
12
+ render (for regular function calls for instance, like for \
13
+ logging etc), look in to adding `@inline` to your \
14
+ fragment definition (like `fragment SomeFragment_user on \
15
+ User @inline {...}`) and then use `Fragment.readInline`. \
16
+ This will allow you to get the fragment data, but outside \
17
+ of React's render.*/
18
+ (
19
+ useFragment_(node, fRef)
20
+ ->(RescriptRelay_Internal.internal_useConvertedValue(convertFragment, _))
21
+ )
22
+ }
23
+
24
+ @module("react-relay")
25
+ external useFragmentOpt_: (fragmentNode<'node>, option<'fragmentRef>) => Js.Nullable.t<'fragment> =
26
+ "useFragment"
27
+
28
+ let useFragmentOpt = (~fRef, ~node, ~convertFragment: 'fragment => 'fragment) => {
29
+ // TODO(v11) can convert to Nullable pattern match.
30
+
31
+ /** A version of `Fragment.use` that'll allow you to pass \
32
+ `option<fragmentRefs>` and get `option<'fragmentData>` \
33
+ back. Useful for scenarios where you don't have the \
34
+ fragmentRefs yet.*/
35
+ let data =
36
+ useFragmentOpt_(node, fRef)->Js.Nullable.toOption
37
+ React.useMemo1(() => {
38
+ switch data {
39
+ | Some(data) => Some(convertFragment(data))
40
+ | None => None
41
+ }
42
+ }, [data])
43
+ }
44
+
45
+ @module("react-relay")
46
+ external readInlineData_: (fragmentNode<'node>, 'fragmentRef) => 'fragment = "readInlineData"
47
+
48
+ let readInlineData = (~node, ~convertFragment: 'fragment => 'fragment, ~fRef) => {
49
+ /** This lets you get the data for this fragment _outside \
50
+ of React's render_. Useful for letting functions with \
51
+ with fragments too, for things like logging etc.*/
52
+ (readInlineData_(node, fRef)->convertFragment)
53
+ }
54
+
55
+ @module("relay-runtime/lib/store/ResolverFragments")
56
+ external read_: (fragmentNode<'node>, 'fragmentRef) => 'fragment = "readFragment"
57
+
58
+ let read = (~node, ~convertFragment: 'fragment => 'fragment, ~fRef) => {
59
+ /** This lets you get the data for this fragment _outside \
60
+ of React's render_. Useful for letting functions with \
61
+ with fragments too, for things like logging etc.*/
62
+ (read_(node, fRef)->convertFragment)
63
+ }
64
+
65
+ type refetchableFnOpts = {
66
+ fetchPolicy?: fetchPolicy,
67
+ onComplete?: Js.Nullable.t<Js.Exn.t> => unit,
68
+ }
69
+
70
+ let internal_makeRefetchableFnOpts = (~fetchPolicy=?, ~onComplete=?, ()) => {
71
+ ?fetchPolicy,
72
+ onComplete: ?onComplete->RescriptRelay_Internal.internal_nullableToOptionalExnHandler,
73
+ }
74
+
75
+ type paginationLoadMoreOptions = {onComplete?: Js.Nullable.t<Js.Exn.t> => unit}
76
+ type paginationLoadMoreFn = (~count: int, ~onComplete: option<Js.Exn.t> => unit=?) => Disposable.t
77
+ type paginationFragmentReturnRaw<'fragment, 'refetchVariables> = {
78
+ data: 'fragment,
79
+ loadNext: (int, paginationLoadMoreOptions) => Disposable.t,
80
+ loadPrevious: (int, paginationLoadMoreOptions) => Disposable.t,
81
+ hasNext: bool,
82
+ hasPrevious: bool,
83
+ isLoadingNext: bool,
84
+ isLoadingPrevious: bool,
85
+ refetch: ('refetchVariables, refetchableFnOpts) => Disposable.t,
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
+ type paginationFragmentReturn<'fragment, 'refetchVariables> = {
100
+ data: 'fragment,
101
+ loadNext: paginationLoadMoreFn,
102
+ loadPrevious: paginationLoadMoreFn,
103
+ hasNext: bool,
104
+ hasPrevious: bool,
105
+ isLoadingNext: bool,
106
+ isLoadingPrevious: bool,
107
+ refetch: (
108
+ ~variables: 'refetchVariables,
109
+ ~fetchPolicy: fetchPolicy=?,
110
+ ~onComplete: option<Js.Exn.t> => unit=?,
111
+ ) => Disposable.t,
112
+ }
113
+
114
+ @module("react-relay")
115
+ external usePaginationFragment_: (
116
+ fragmentNode<'node>,
117
+ 'fragmentRef,
118
+ ) => paginationFragmentReturnRaw<'fragment, 'refetchVariables> = "usePaginationFragment"
119
+
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`.*/
124
+ let usePaginationFragment = (
125
+ ~node,
126
+ ~fRef,
127
+ ~convertFragment: 'fragment => 'fragment,
128
+ ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
129
+ ) => {
130
+ let p = usePaginationFragment_(node, fRef)
131
+ let data = RescriptRelay_Internal.internal_useConvertedValue(convertFragment, p.data)
132
+ {
133
+ data,
134
+ loadNext: React.useMemo1(() => (~count, ~onComplete=?) => {
135
+ p.loadNext(
136
+ count,
137
+ {onComplete: ?onComplete->RescriptRelay_Internal.internal_nullableToOptionalExnHandler},
138
+ )
139
+ }, [p.loadNext]),
140
+ loadPrevious: React.useMemo1(() => (~count, ~onComplete=?) => {
141
+ p.loadPrevious(
142
+ count,
143
+ {onComplete: ?onComplete->RescriptRelay_Internal.internal_nullableToOptionalExnHandler},
144
+ )
145
+ }, [p.loadPrevious]),
146
+ hasNext: p.hasNext,
147
+ hasPrevious: p.hasPrevious,
148
+ isLoadingNext: p.isLoadingNext,
149
+ isLoadingPrevious: p.isLoadingPrevious,
150
+ refetch: React.useMemo1(() => (~variables, ~fetchPolicy=?, ~onComplete=?) => {
151
+ p.refetch(
152
+ RescriptRelay_Internal.internal_cleanObjectFromUndefinedRaw(
153
+ variables->convertRefetchVariables,
154
+ ),
155
+ internal_makeRefetchableFnOpts(~onComplete?, ~fetchPolicy?, ()),
156
+ )
157
+ }, [p.refetch]),
158
+ }
159
+ }
160
+
161
+ @module("react-relay/lib/relay-hooks/legacy/useBlockingPaginationFragment")
162
+ external useBlockingPaginationFragment_: (
163
+ fragmentNode<'node>,
164
+ 'fragmentRef,
165
+ ) => paginationFragmentReturnRaw<'fragment, 'refetchVariables> = "default"
166
+
167
+ /** Like `Fragment.usePagination`, but calling the \
168
+ pagination function will trigger suspense. Useful for \
169
+ all-at-once pagination.*/
170
+ let useBlockingPaginationFragment = (
171
+ ~node,
172
+ ~fRef,
173
+ ~convertFragment: 'fragment => 'fragment,
174
+ ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
175
+ ) => {
176
+ let p = useBlockingPaginationFragment_(node, fRef)
177
+ let data = RescriptRelay_Internal.internal_useConvertedValue(convertFragment, p.data)
178
+ {
179
+ data,
180
+ loadNext: React.useMemo1(() => (~count, ~onComplete=?) => {
181
+ p.loadNext(
182
+ count,
183
+ {onComplete: ?onComplete->RescriptRelay_Internal.internal_nullableToOptionalExnHandler},
184
+ )
185
+ }, [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
+ hasNext: p.hasNext,
193
+ hasPrevious: p.hasPrevious,
194
+ refetch: React.useMemo1(() => (~variables, ~fetchPolicy=?, ~onComplete=?) => {
195
+ p.refetch(
196
+ RescriptRelay_Internal.internal_cleanObjectFromUndefinedRaw(
197
+ variables->convertRefetchVariables,
198
+ ),
199
+ internal_makeRefetchableFnOpts(~onComplete?, ~fetchPolicy?, ()),
200
+ )
201
+ }, [p.refetch]),
202
+ }
203
+ }
204
+
205
+ @module("react-relay")
206
+ external useRefetchableFragment_: (
207
+ fragmentNode<'node>,
208
+ 'fragmentRef,
209
+ ) => ('fragment, ('refetchVariables, refetchableFnOpts) => Disposable.t) = "useRefetchableFragment"
210
+
211
+ /**React hook for using a fragment that you want to refetch. Returns \
212
+ a tuple of `(fragmentData, refetchFn)`.\n\n\
213
+ ### Refetching and variables\n\
214
+ You supply a _diff_ of your variables to Relay when refetching. \
215
+ Diffed variables here means that any new value you supply when \
216
+ refetching will be merged with the variables you last used when \
217
+ fetching data for this fragment.\n\n\
218
+ ### `Fragment.makeRefetchVariables` - helper for making the \
219
+ refetch variables\n\
220
+ There's a helper generated for you to create those diffed \
221
+ variables more easily at `Fragment.makeRefetchVariables`.*/
222
+ let useRefetchableFragment = (
223
+ ~node,
224
+ ~convertFragment: 'fragment => 'fragment,
225
+ ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
226
+ ~fRef,
227
+ ) => {
228
+ let (fragmentData, refetchFn) = useRefetchableFragment_(node, fRef)
229
+ let data = RescriptRelay_Internal.internal_useConvertedValue(convertFragment, fragmentData)
230
+ (
231
+ data,
232
+ React.useMemo1(
233
+ () => (~variables: 'refetchVariables, ~fetchPolicy=?, ~onComplete=?) =>
234
+ refetchFn(
235
+ RescriptRelay_Internal.internal_removeUndefinedAndConvertNullsRaw(
236
+ variables->convertRefetchVariables,
237
+ ),
238
+ internal_makeRefetchableFnOpts(~fetchPolicy?, ~onComplete?, ()),
239
+ ),
240
+ [refetchFn],
241
+ ),
242
+ )
243
+ }
@@ -0,0 +1,85 @@
1
+ open RescriptRelay
2
+
3
+ let useFragment: (
4
+ ~node: fragmentNode<'a>,
5
+ ~convertFragment: 'fragment => 'fragment,
6
+ ~fRef: 'b,
7
+ ) => 'fragment
8
+
9
+ let useFragmentOpt: (
10
+ ~fRef: option<'a>,
11
+ ~node: fragmentNode<'b>,
12
+ ~convertFragment: 'fragment => 'fragment,
13
+ ) => option<'fragment>
14
+
15
+ let readInlineData: (
16
+ ~node: fragmentNode<'a>,
17
+ ~convertFragment: 'fragment => 'fragment,
18
+ ~fRef: 'b,
19
+ ) => 'fragment
20
+
21
+ let read: (
22
+ ~node: fragmentNode<'a>,
23
+ ~convertFragment: 'fragment => 'fragment,
24
+ ~fRef: 'b,
25
+ ) => 'fragment
26
+
27
+ type paginationLoadMoreOptions = {onComplete?: Js.Nullable.t<Js.Exn.t> => unit}
28
+
29
+ type paginationLoadMoreFn = (~count: int, ~onComplete: option<Js.Exn.t> => unit=?) => Disposable.t
30
+
31
+ type paginationBlockingFragmentReturn<'fragment, 'refetchVariables> = {
32
+ data: 'fragment,
33
+ loadNext: paginationLoadMoreFn,
34
+ loadPrevious: paginationLoadMoreFn,
35
+ hasNext: bool,
36
+ hasPrevious: bool,
37
+ refetch: (
38
+ ~variables: 'refetchVariables,
39
+ ~fetchPolicy: fetchPolicy=?,
40
+ ~onComplete: option<Js.Exn.t> => unit=?,
41
+ ) => Disposable.t,
42
+ }
43
+
44
+ type paginationFragmentReturn<'fragment, 'refetchVariables> = {
45
+ data: 'fragment,
46
+ loadNext: paginationLoadMoreFn,
47
+ loadPrevious: paginationLoadMoreFn,
48
+ hasNext: bool,
49
+ hasPrevious: bool,
50
+ isLoadingNext: bool,
51
+ isLoadingPrevious: bool,
52
+ refetch: (
53
+ ~variables: 'refetchVariables,
54
+ ~fetchPolicy: fetchPolicy=?,
55
+ ~onComplete: option<Js.Exn.t> => unit=?,
56
+ ) => Disposable.t,
57
+ }
58
+
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: (
67
+ ~node: fragmentNode<'a>,
68
+ ~fRef: 'b,
69
+ ~convertFragment: 'fragment => 'fragment,
70
+ ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
71
+ ) => paginationBlockingFragmentReturn<'fragment, 'refetchVariables>
72
+
73
+ let useRefetchableFragment: (
74
+ ~node: fragmentNode<'a>,
75
+ ~convertFragment: 'fragment => 'fragment,
76
+ ~convertRefetchVariables: 'refetchVariables => 'refetchVariables,
77
+ ~fRef: 'b,
78
+ ) => (
79
+ 'fragment,
80
+ (
81
+ ~variables: 'refetchVariables,
82
+ ~fetchPolicy: fetchPolicy=?,
83
+ ~onComplete: option<Js.Exn.t> => unit=?,
84
+ ) => Disposable.t,
85
+ )