react-relay 11.0.2 → 13.0.0-rc.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +47 -0
- package/ReactRelayContainerUtils.js.flow +1 -1
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +3 -4
- package/ReactRelayFragmentContainer.js.flow +25 -25
- package/ReactRelayFragmentMockRenderer.js.flow +2 -2
- package/ReactRelayLocalQueryRenderer.js.flow +7 -8
- package/ReactRelayPaginationContainer.js.flow +112 -59
- package/ReactRelayQueryFetcher.js.flow +10 -11
- package/ReactRelayQueryRenderer.js.flow +116 -82
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +42 -39
- package/ReactRelayTestMocker.js.flow +17 -15
- package/ReactRelayTypes.js.flow +11 -11
- package/RelayContext.js.flow +4 -4
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +12 -8
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +11 -7
- package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
- package/assertFragmentMap.js.flow +3 -3
- package/buildReactRelayContainer.js.flow +12 -11
- package/getRootVariablesForFragments.js.flow +3 -5
- package/hooks.js +1 -1
- package/hooks.js.flow +6 -7
- package/index.js +1 -1
- package/index.js.flow +7 -8
- package/isRelayEnvironment.js.flow +1 -1
- package/jest-react/enqueueTask.js.flow +56 -0
- package/jest-react/index.js.flow +12 -0
- package/jest-react/internalAct.js.flow +138 -0
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -1
- package/lib/ReactRelayContainerUtils.js +1 -1
- package/lib/ReactRelayContext.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +22 -16
- package/lib/ReactRelayFragmentMockRenderer.js +3 -3
- package/lib/ReactRelayLocalQueryRenderer.js +8 -9
- package/lib/ReactRelayPaginationContainer.js +97 -39
- package/lib/ReactRelayQueryFetcher.js +3 -3
- package/lib/ReactRelayQueryRenderer.js +87 -54
- package/lib/ReactRelayQueryRendererContext.js +1 -1
- package/lib/ReactRelayRefetchContainer.js +39 -26
- package/lib/ReactRelayTestMocker.js +8 -9
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +4 -3
- package/lib/assertFragmentMap.js +3 -2
- package/lib/buildReactRelayContainer.js +8 -8
- package/lib/getRootVariablesForFragments.js +2 -3
- package/lib/hooks.js +6 -6
- package/lib/index.js +8 -8
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/jest-react/enqueueTask.js +53 -0
- package/lib/jest-react/index.js +13 -0
- package/lib/jest-react/internalAct.js +115 -0
- package/lib/legacy.js +1 -1
- package/lib/multi-actor/ActorChange.js +30 -0
- package/lib/multi-actor/index.js +11 -0
- package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
- package/lib/readContext.js +1 -1
- package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
- package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
- package/lib/relay-hooks/FragmentResource.js +342 -89
- package/lib/relay-hooks/InternalLogger.js +1 -1
- package/lib/relay-hooks/LRUCache.js +1 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
- package/lib/relay-hooks/MatchContainer.js +2 -2
- package/lib/relay-hooks/ProfilerContext.js +1 -1
- package/lib/relay-hooks/QueryResource.js +172 -29
- package/lib/relay-hooks/RelayEnvironmentProvider.js +6 -4
- package/lib/relay-hooks/SuspenseResource.js +130 -0
- package/lib/relay-hooks/loadEntryPoint.js +1 -1
- package/lib/relay-hooks/loadQuery.js +42 -20
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -16
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
- package/lib/relay-hooks/useBlockingPaginationFragment.js +5 -6
- package/lib/relay-hooks/useEntryPointLoader.js +3 -3
- package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
- package/lib/relay-hooks/useFragment.js +7 -7
- package/lib/relay-hooks/useFragmentNode.js +5 -5
- package/lib/relay-hooks/useIsMountedRef.js +1 -1
- package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
- package/lib/relay-hooks/useLazyLoadQueryNode.js +11 -5
- package/lib/relay-hooks/useLoadMoreFunction.js +9 -13
- package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
- package/lib/relay-hooks/useMemoVariables.js +3 -3
- package/lib/relay-hooks/useMutation.js +18 -7
- package/lib/relay-hooks/usePaginationFragment.js +3 -4
- package/lib/relay-hooks/usePreloadedQuery.js +6 -6
- package/lib/relay-hooks/useQueryLoader.js +31 -11
- package/lib/relay-hooks/useRefetchableFragment.js +1 -1
- package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -18
- package/lib/relay-hooks/useRelayEnvironment.js +3 -3
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
- package/lib/relay-hooks/useSubscription.js +11 -8
- package/multi-actor/ActorChange.js.flow +58 -0
- package/multi-actor/index.js.flow +14 -0
- package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
- package/package.json +3 -3
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/readContext.js.flow +1 -1
- package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
- package/relay-hooks/EntryPointTypes.flow.js.flow +25 -26
- package/relay-hooks/FragmentResource.js.flow +359 -93
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
- package/relay-hooks/MatchContainer.js.flow +4 -3
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +217 -26
- package/relay-hooks/RelayEnvironmentProvider.js.flow +15 -5
- package/relay-hooks/SuspenseResource.js.flow +115 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/utils.js.flow +21 -32
- package/relay-hooks/loadEntryPoint.js.flow +7 -13
- package/relay-hooks/loadQuery.js.flow +50 -32
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +31 -22
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
- package/relay-hooks/useBlockingPaginationFragment.js.flow +14 -12
- package/relay-hooks/useEntryPointLoader.js.flow +8 -11
- package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
- package/relay-hooks/useFragment.js.flow +31 -62
- package/relay-hooks/useFragmentNode.js.flow +6 -8
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
- package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
- package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
- package/relay-hooks/useLazyLoadQueryNode.js.flow +20 -14
- package/relay-hooks/useLoadMoreFunction.js.flow +21 -30
- package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
- package/relay-hooks/useMemoVariables.js.flow +7 -7
- package/relay-hooks/useMutation.js.flow +27 -27
- package/relay-hooks/usePaginationFragment.js.flow +39 -45
- package/relay-hooks/usePreloadedQuery.js.flow +14 -20
- package/relay-hooks/useQueryLoader.js.flow +42 -23
- package/relay-hooks/useRefetchableFragment.js.flow +8 -9
- package/relay-hooks/useRefetchableFragmentNode.js.flow +25 -33
- package/relay-hooks/useRelayEnvironment.js.flow +3 -5
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
- package/relay-hooks/useSubscription.js.flow +21 -11
- package/lib/relay-hooks/getPaginationMetadata.js +0 -41
- package/lib/relay-hooks/getPaginationVariables.js +0 -67
- package/lib/relay-hooks/getRefetchMetadata.js +0 -36
- package/lib/relay-hooks/getValueAtPath.js +0 -51
- package/relay-hooks/getPaginationMetadata.js.flow +0 -74
- package/relay-hooks/getPaginationVariables.js.flow +0 -110
- package/relay-hooks/getRefetchMetadata.js.flow +0 -80
- package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -11,7 +11,8 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
var
|
14
|
+
var _require = require('./loadQuery'),
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
15
16
|
|
16
17
|
var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
17
18
|
|
@@ -19,10 +20,7 @@ var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
|
19
20
|
|
20
21
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
21
22
|
|
22
|
-
var
|
23
|
-
|
24
|
-
var _require = require('./loadQuery'),
|
25
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
23
|
+
var invariant = require('invariant');
|
26
24
|
|
27
25
|
var _require2 = require('react'),
|
28
26
|
useDebugValue = _require2.useDebugValue;
|
@@ -32,6 +30,8 @@ var _require3 = require('relay-runtime'),
|
|
32
30
|
fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
|
33
31
|
fetchQuery = _require3$__internal.fetchQuery;
|
34
32
|
|
33
|
+
var warning = require("fbjs/lib/warning");
|
34
|
+
|
35
35
|
function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
36
36
|
// We need to use this hook in order to be able to track if
|
37
37
|
// loadQuery was called during render
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -15,24 +15,36 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
15
15
|
|
16
16
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
17
17
|
|
18
|
-
var useIsMountedRef = require('./useIsMountedRef');
|
19
|
-
|
20
|
-
var useRelayEnvironment = require('./useRelayEnvironment');
|
21
|
-
|
22
18
|
var _require = require('./loadQuery'),
|
23
19
|
loadQuery = _require.loadQuery,
|
24
20
|
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
25
21
|
|
22
|
+
var useIsMountedRef = require('./useIsMountedRef');
|
23
|
+
|
24
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
25
|
+
|
26
26
|
var _require2 = require('react'),
|
27
27
|
useCallback = _require2.useCallback,
|
28
28
|
useEffect = _require2.useEffect,
|
29
29
|
useRef = _require2.useRef,
|
30
30
|
useState = _require2.useState;
|
31
31
|
|
32
|
+
var _require3 = require('relay-runtime'),
|
33
|
+
getRequest = _require3.getRequest;
|
34
|
+
|
32
35
|
var initialNullQueryReferenceState = {
|
33
36
|
kind: 'NullQueryReference'
|
34
37
|
};
|
35
38
|
|
39
|
+
function requestIsLiveQuery(preloadableRequest) {
|
40
|
+
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
41
|
+
return preloadableRequest.params.metadata.live !== undefined;
|
42
|
+
}
|
43
|
+
|
44
|
+
var request = getRequest(preloadableRequest);
|
45
|
+
return request.params.metadata.live !== undefined;
|
46
|
+
}
|
47
|
+
|
36
48
|
function useQueryLoader(preloadableRequest, initialQueryReference) {
|
37
49
|
/**
|
38
50
|
* We want to always call `queryReference.dispose()` for every call to
|
@@ -175,7 +187,11 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
175
187
|
undisposedQueryReferences["delete"](undisposedQueryReference);
|
176
188
|
|
177
189
|
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
178
|
-
|
190
|
+
if (requestIsLiveQuery(preloadableRequest)) {
|
191
|
+
undisposedQueryReference.dispose && undisposedQueryReference.dispose();
|
192
|
+
} else {
|
193
|
+
undisposedQueryReference.releaseQuery && undisposedQueryReference.releaseQuery();
|
194
|
+
}
|
179
195
|
}
|
180
196
|
}
|
181
197
|
} catch (err) {
|
@@ -184,7 +200,7 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
184
200
|
_iterator.f();
|
185
201
|
}
|
186
202
|
}
|
187
|
-
}, [queryReference, isMountedRef, queryLoaderCallback]);
|
203
|
+
}, [queryReference, isMountedRef, queryLoaderCallback, preloadableRequest]);
|
188
204
|
useEffect(function () {
|
189
205
|
return function disposeAllRemainingQueryReferences() {
|
190
206
|
// undisposedQueryReferences.current is never reassigned
|
@@ -194,10 +210,14 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
194
210
|
|
195
211
|
try {
|
196
212
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
197
|
-
var
|
213
|
+
var undisposedQueryReference = _step2.value;
|
198
214
|
|
199
|
-
if (
|
200
|
-
|
215
|
+
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
216
|
+
if (requestIsLiveQuery(preloadableRequest)) {
|
217
|
+
undisposedQueryReference.dispose && undisposedQueryReference.dispose();
|
218
|
+
} else {
|
219
|
+
undisposedQueryReference.releaseQuery && undisposedQueryReference.releaseQuery();
|
220
|
+
}
|
201
221
|
}
|
202
222
|
}
|
203
223
|
} catch (err) {
|
@@ -206,7 +226,7 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
206
226
|
_iterator2.f();
|
207
227
|
}
|
208
228
|
};
|
209
|
-
}, []);
|
229
|
+
}, [preloadableRequest]);
|
210
230
|
return [queryReference.kind === 'NullQueryReference' ? null : queryReference, queryLoaderCallback, disposeQuery];
|
211
231
|
}
|
212
232
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -15,13 +15,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
15
15
|
|
16
16
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
17
|
|
18
|
-
var
|
19
|
-
|
20
|
-
var getRefetchMetadata = require('./getRefetchMetadata');
|
18
|
+
var _require = require('./FragmentResource'),
|
19
|
+
getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
|
21
20
|
|
22
|
-
var
|
21
|
+
var ProfilerContext = require('./ProfilerContext');
|
23
22
|
|
24
|
-
var
|
23
|
+
var _require2 = require('./QueryResource'),
|
24
|
+
getQueryResourceForEnvironment = _require2.getQueryResourceForEnvironment;
|
25
25
|
|
26
26
|
var useFragmentNode = require('./useFragmentNode');
|
27
27
|
|
@@ -31,13 +31,7 @@ var useQueryLoader = require('./useQueryLoader');
|
|
31
31
|
|
32
32
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
33
33
|
|
34
|
-
var
|
35
|
-
|
36
|
-
var _require = require('./FragmentResource'),
|
37
|
-
getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
|
38
|
-
|
39
|
-
var _require2 = require('./QueryResource'),
|
40
|
-
getQueryResourceForEnvironment = _require2.getQueryResourceForEnvironment;
|
34
|
+
var invariant = require('invariant');
|
41
35
|
|
42
36
|
var _require3 = require('react'),
|
43
37
|
useCallback = _require3.useCallback,
|
@@ -48,7 +42,11 @@ var _require4 = require('relay-runtime'),
|
|
48
42
|
fetchQuery = _require4.__internal.fetchQuery,
|
49
43
|
createOperationDescriptor = _require4.createOperationDescriptor,
|
50
44
|
getFragmentIdentifier = _require4.getFragmentIdentifier,
|
51
|
-
|
45
|
+
getRefetchMetadata = _require4.getRefetchMetadata,
|
46
|
+
getSelector = _require4.getSelector,
|
47
|
+
getValueAtPath = _require4.getValueAtPath;
|
48
|
+
|
49
|
+
var warning = require("fbjs/lib/warning");
|
52
50
|
|
53
51
|
function reducer(state, action) {
|
54
52
|
switch (action.type) {
|
@@ -262,7 +260,6 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
262
260
|
// all variables required by the fragment when calling `refetch()`.
|
263
261
|
// We fill in any variables not passed by the call to `refetch()` with the
|
264
262
|
// variables from the original parent fragment owner.
|
265
|
-
// $FlowFixMe[cannot-spread-interface]
|
266
263
|
|
267
264
|
|
268
265
|
var refetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables), providedRefetchVariables); // If the query needs an identifier value ('id' or similar) and one
|
@@ -312,7 +309,7 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
312
309
|
// - fragmentNode and parentFragmentRef are also captured by including
|
313
310
|
// fragmentIdentifier
|
314
311
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
315
|
-
[fragmentIdentifier, dispatch, disposeQuery, identifierValue]);
|
312
|
+
[fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery]);
|
316
313
|
}
|
317
314
|
|
318
315
|
var debugFunctions;
|
@@ -321,8 +318,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
321
318
|
debugFunctions = {
|
322
319
|
getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, environment) {
|
323
320
|
var _require5 = require('relay-runtime'),
|
324
|
-
Record = _require5.Record;
|
325
|
-
|
321
|
+
Record = _require5.Record;
|
326
322
|
|
327
323
|
var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables.id;
|
328
324
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -11,13 +11,13 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
var ReactRelayContext = require('react-relay/ReactRelayContext');
|
15
|
-
|
16
14
|
var invariant = require('invariant');
|
17
15
|
|
18
16
|
var _require = require('react'),
|
19
17
|
useContext = _require.useContext;
|
20
18
|
|
19
|
+
var ReactRelayContext = require('react-relay/ReactRelayContext');
|
20
|
+
|
21
21
|
function useRelayEnvironment() {
|
22
22
|
var context = useContext(ReactRelayContext);
|
23
23
|
!(context != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'useRelayEnvironment: Expected to have found a Relay environment provided by ' + 'a `RelayEnvironmentProvider` component. ' + 'This usually means that useRelayEnvironment was used in a ' + 'component that is not a descendant of a `RelayEnvironmentProvider`. ' + 'Please make sure a `RelayEnvironmentProvider` has been rendered somewhere ' + 'as a parent or ancestor of your component.') : invariant(false) : void 0;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -11,11 +11,11 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
var warning = require("fbjs/lib/warning");
|
15
|
-
|
16
14
|
var _require = require('react'),
|
17
15
|
useRef = _require.useRef;
|
18
16
|
|
17
|
+
var warning = require("fbjs/lib/warning");
|
18
|
+
|
19
19
|
function useStaticFragmentNodeWarning(fragmentNode, warningContext) {
|
20
20
|
if (process.env.NODE_ENV !== "production") {
|
21
21
|
// This is calling `useRef` conditionally, but based on the environment
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -16,7 +16,6 @@ var useRelayEnvironment = require('./useRelayEnvironment');
|
|
16
16
|
var _require = require('react'),
|
17
17
|
useEffect = _require.useEffect,
|
18
18
|
useRef = _require.useRef;
|
19
|
-
|
20
19
|
/**
|
21
20
|
* This hook subscribes a callback to the invalidation state of the given data
|
22
21
|
* ids.
|
@@ -26,6 +25,8 @@ var _require = require('react'),
|
|
26
25
|
* re-established and the previous one will be disposed.
|
27
26
|
* The subscription will automatically be disposed on unmount
|
28
27
|
*/
|
28
|
+
|
29
|
+
|
29
30
|
function useSubscribeToInvalidationState(dataIDs, callback) {
|
30
31
|
var environment = useRelayEnvironment();
|
31
32
|
var disposableRef = useRef(null);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -10,12 +10,13 @@
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
var React = require('react');
|
14
|
-
|
15
13
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
16
14
|
|
17
|
-
var _require = require('
|
18
|
-
|
15
|
+
var _require = require('react'),
|
16
|
+
useEffect = _require.useEffect;
|
17
|
+
|
18
|
+
var _require2 = require('relay-runtime'),
|
19
|
+
requestSubscription = _require2.requestSubscription;
|
19
20
|
|
20
21
|
function useSubscription(config, requestSubscriptionFn) {
|
21
22
|
// N.B. this will re-subscribe every render if config or requestSubscriptionFn
|
@@ -23,9 +24,11 @@ function useSubscription(config, requestSubscriptionFn) {
|
|
23
24
|
// Please do not pass an object defined in-line.
|
24
25
|
var actualRequestSubscription = requestSubscriptionFn !== null && requestSubscriptionFn !== void 0 ? requestSubscriptionFn : requestSubscription;
|
25
26
|
var environment = useRelayEnvironment();
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
useEffect(function () {
|
28
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
29
|
+
var _actualRequestSubscri = actualRequestSubscription(environment, config),
|
30
|
+
dispose = _actualRequestSubscri.dispose; // $FlowFixMe[incompatible-call]
|
31
|
+
|
29
32
|
|
30
33
|
return dispose;
|
31
34
|
}, [environment, config, actualRequestSubscription]);
|
@@ -0,0 +1,58 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict-local
|
8
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
import type {ActorIdentifier} from 'relay-runtime/multi-actor-environment';
|
15
|
+
|
16
|
+
const RelayEnvironmentProvider = require('../relay-hooks/RelayEnvironmentProvider');
|
17
|
+
const useRelayActorEnvironment = require('./useRelayActorEnvironment');
|
18
|
+
const React = require('react');
|
19
|
+
|
20
|
+
export opaque type ActorChangePoint<TFragmentRef> = $ReadOnly<{
|
21
|
+
__fragmentRef: TFragmentRef,
|
22
|
+
__viewer: ActorIdentifier,
|
23
|
+
}>;
|
24
|
+
|
25
|
+
type ActorChangeProps<TFragmentRef> = {
|
26
|
+
actorChangePoint: ActorChangePoint<TFragmentRef>,
|
27
|
+
children: (
|
28
|
+
fragmentRef: TFragmentRef,
|
29
|
+
actorIdentifier: ActorIdentifier,
|
30
|
+
) => React.MixedElement,
|
31
|
+
};
|
32
|
+
|
33
|
+
function ActorChange<TFragmentRef>(
|
34
|
+
props: ActorChangeProps<TFragmentRef>,
|
35
|
+
): React.Element<typeof RelayEnvironmentProvider> {
|
36
|
+
const actorEnvironment = useRelayActorEnvironment(
|
37
|
+
props.actorChangePoint.__viewer,
|
38
|
+
);
|
39
|
+
const getEnvironmentForActor = React.useCallback(
|
40
|
+
(actorIdentifier: ActorIdentifier) => {
|
41
|
+
return actorEnvironment.multiActorEnvironment.forActor(actorIdentifier);
|
42
|
+
},
|
43
|
+
[actorEnvironment],
|
44
|
+
);
|
45
|
+
|
46
|
+
return (
|
47
|
+
<RelayEnvironmentProvider
|
48
|
+
environment={actorEnvironment}
|
49
|
+
getEnvironmentForActor={getEnvironmentForActor}>
|
50
|
+
{props.children(
|
51
|
+
props.actorChangePoint.__fragmentRef,
|
52
|
+
props.actorChangePoint.__viewer,
|
53
|
+
)}
|
54
|
+
</RelayEnvironmentProvider>
|
55
|
+
);
|
56
|
+
}
|
57
|
+
|
58
|
+
module.exports = ActorChange;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict-local
|
8
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
export type {ActorChangePoint} from './ActorChange';
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
* @flow strict-local
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
// flowlint ambiguous-object-type:error
|
13
|
+
|
14
|
+
'use strict';
|
15
|
+
|
16
|
+
import type {
|
17
|
+
ActorIdentifier,
|
18
|
+
IActorEnvironment,
|
19
|
+
} from 'relay-runtime/multi-actor-environment';
|
20
|
+
|
21
|
+
const invariant = require('invariant');
|
22
|
+
const {useContext} = require('react');
|
23
|
+
const ReactRelayContext = require('react-relay/ReactRelayContext');
|
24
|
+
|
25
|
+
function useRelayActorEnvironment(
|
26
|
+
actorIdentifier: ActorIdentifier,
|
27
|
+
): IActorEnvironment {
|
28
|
+
const context = useContext(ReactRelayContext);
|
29
|
+
invariant(
|
30
|
+
context != null,
|
31
|
+
'useRelayActorEnvironment: Expected to have found a Relay environment provided by ' +
|
32
|
+
'a `RelayEnvironmentProvider` component. ' +
|
33
|
+
'This usually means that useRelayActorEnvironment was used in a ' +
|
34
|
+
'component that is not a descendant of a `RelayEnvironmentProvider`. ' +
|
35
|
+
'Please make sure a `RelayEnvironmentProvider` has been rendered somewhere ' +
|
36
|
+
'as a parent or ancestor of your component.',
|
37
|
+
);
|
38
|
+
const getEnvironmentForActor = context.getEnvironmentForActor;
|
39
|
+
invariant(
|
40
|
+
getEnvironmentForActor != null,
|
41
|
+
'useRelayActorEnvironment: Expected to have a function `getEnvironmentForActor`.' +
|
42
|
+
'This usually means that `RelayEnvironmentProvider`. was not properly set up for use in the ' +
|
43
|
+
'multi actor application. Please make sure the provider has defined a `getEnvironmentForActor`.',
|
44
|
+
);
|
45
|
+
|
46
|
+
return getEnvironmentForActor(actorIdentifier);
|
47
|
+
}
|
48
|
+
|
49
|
+
module.exports = useRelayActorEnvironment;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-relay",
|
3
3
|
"description": "A framework for building GraphQL-driven React applications.",
|
4
|
-
"version": "
|
4
|
+
"version": "13.0.0-rc.2",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay",
|
@@ -13,10 +13,10 @@
|
|
13
13
|
"repository": "facebook/relay",
|
14
14
|
"dependencies": {
|
15
15
|
"@babel/runtime": "^7.0.0",
|
16
|
-
"fbjs": "^3.0.
|
16
|
+
"fbjs": "^3.0.2",
|
17
17
|
"invariant": "^2.2.4",
|
18
18
|
"nullthrows": "^1.1.1",
|
19
|
-
"relay-runtime": "
|
19
|
+
"relay-runtime": "13.0.0-rc.2"
|
20
20
|
},
|
21
21
|
"peerDependencies": {
|
22
22
|
"react": "^16.9.0 || ^17"
|