react-relay 15.0.0 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayQueryFetcher.js.flow +1 -5
- package/ReactRelayQueryRenderer.js.flow +9 -36
- package/ReactRelayTypes.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +3 -1
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/ReactRelayContainerUtils.js +0 -11
- package/lib/ReactRelayContext.js +0 -11
- package/lib/ReactRelayFragmentContainer.js +6 -78
- package/lib/ReactRelayFragmentMockRenderer.js +0 -11
- package/lib/ReactRelayLocalQueryRenderer.js +0 -17
- package/lib/ReactRelayPaginationContainer.js +5 -208
- package/lib/ReactRelayQueryFetcher.js +2 -51
- package/lib/ReactRelayQueryRenderer.js +6 -94
- package/lib/ReactRelayQueryRendererContext.js +0 -11
- package/lib/ReactRelayRefetchContainer.js +5 -91
- package/lib/ReactRelayTestMocker.js +9 -85
- package/lib/ReactRelayTypes.js +0 -11
- package/lib/RelayContext.js +0 -21
- package/lib/assertFragmentMap.js +0 -15
- package/lib/buildReactRelayContainer.js +0 -19
- package/lib/getRootVariablesForFragments.js +0 -14
- package/lib/hooks.js +0 -15
- package/lib/index.js +0 -17
- package/lib/isRelayEnvironment.js +1 -18
- package/lib/jest-react/enqueueTask.js +0 -20
- package/lib/jest-react/internalAct.js +0 -38
- package/lib/legacy.js +0 -15
- package/lib/multi-actor/ActorChange.js +0 -11
- package/lib/multi-actor/index.js +0 -11
- package/lib/multi-actor/useRelayActorEnvironment.js +0 -11
- package/lib/relay-hooks/EntryPointContainer.react.js +0 -11
- package/lib/relay-hooks/EntryPointTypes.flow.js +1 -14
- package/lib/relay-hooks/FragmentResource.js +76 -132
- package/lib/relay-hooks/HooksImplementation.js +0 -11
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -22
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -18
- package/lib/relay-hooks/MatchContainer.js +0 -94
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -15
- package/lib/relay-hooks/QueryResource.js +2 -68
- package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -11
- package/lib/relay-hooks/SuspenseResource.js +0 -34
- package/lib/relay-hooks/loadEntryPoint.js +1 -24
- package/lib/relay-hooks/loadQuery.js +2 -106
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +2 -27
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -13
- package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +1 -36
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +3 -27
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +34 -99
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +0 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -16
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +1 -23
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -29
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +12 -96
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +0 -14
- package/lib/relay-hooks/useBlockingPaginationFragment.js +0 -42
- package/lib/relay-hooks/useClientQuery.js +0 -18
- package/lib/relay-hooks/useEntryPointLoader.js +0 -69
- package/lib/relay-hooks/useFetchTrackingRef.js +0 -26
- package/lib/relay-hooks/useFragment.js +0 -17
- package/lib/relay-hooks/useFragmentNode.js +2 -32
- package/lib/relay-hooks/useIsMountedRef.js +0 -11
- package/lib/relay-hooks/useIsOperationNodeActive.js +0 -11
- package/lib/relay-hooks/useIsParentQueryActive.js +0 -11
- package/lib/relay-hooks/useLazyLoadQuery.js +0 -18
- package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -35
- package/lib/relay-hooks/useLoadMoreFunction.js +9 -34
- package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -11
- package/lib/relay-hooks/useMemoVariables.js +0 -17
- package/lib/relay-hooks/useMutation.js +0 -11
- package/lib/relay-hooks/usePaginationFragment.js +1 -26
- package/lib/relay-hooks/usePreloadedQuery.js +0 -27
- package/lib/relay-hooks/useQueryLoader.js +0 -74
- package/lib/relay-hooks/useRefetchableFragment.js +0 -16
- package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -97
- package/lib/relay-hooks/useRelayEnvironment.js +0 -11
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -15
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -25
- package/lib/relay-hooks/useSubscription.js +0 -15
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +0 -17
- package/package.json +2 -2
- 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/relay-hooks/EntryPointContainer.react.js.flow +5 -0
- package/relay-hooks/EntryPointTypes.flow.js.flow +20 -19
- package/relay-hooks/FragmentResource.js.flow +114 -26
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -2
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +7 -5
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +5 -0
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +5 -0
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +2 -0
- package/relay-hooks/loadEntryPoint.js.flow +4 -2
- package/relay-hooks/loadQuery.js.flow +21 -1
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -2
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +2 -1
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +28 -10
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +3 -9
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +28 -57
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +19 -12
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +15 -31
- package/relay-hooks/useBlockingPaginationFragment.js.flow +2 -4
- package/relay-hooks/useClientQuery.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +15 -9
- package/relay-hooks/useMutation.js.flow +26 -9
- package/relay-hooks/usePaginationFragment.js.flow +2 -8
- package/relay-hooks/useQueryLoader.js.flow +2 -8
- package/relay-hooks/useRefetchableFragment.js.flow +3 -2
- package/relay-hooks/useRefetchableFragmentNode.js.flow +28 -13
@@ -1,33 +1,9 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
15
4
|
var _require = require('react'),
|
16
5
|
useCallback = _require.useCallback,
|
17
6
|
useEffect = _require.useEffect;
|
18
|
-
|
19
|
-
/**
|
20
|
-
* This hook returns a mutable React ref that holds the value of whether a
|
21
|
-
* fetch request is in flight. The reason this is a mutable ref instead of
|
22
|
-
* state is because we don't actually want to trigger an update when this
|
23
|
-
* changes, but instead synchronously keep track of whether the network request
|
24
|
-
* is in flight, for example in order to bail out of a request if one is
|
25
|
-
* already in flight. If this was state, due to the nature of concurrent
|
26
|
-
* updates, this value wouldn't be in sync with when the request is actually
|
27
|
-
* in flight.
|
28
|
-
* The additional functions returned by this Hook can be used to mutate
|
29
|
-
* the ref.
|
30
|
-
*/
|
31
7
|
function useFetchTrackingRef() {
|
32
8
|
var subscriptionRef = useUnsafeRef_DEPRECATED(null);
|
33
9
|
var isFetchingRef = useUnsafeRef_DEPRECATED(false);
|
@@ -46,8 +22,6 @@ function useFetchTrackingRef() {
|
|
46
22
|
subscriptionRef.current = null;
|
47
23
|
isFetchingRef.current = false;
|
48
24
|
}, []);
|
49
|
-
|
50
|
-
// Dipose of ongoing fetch on unmount
|
51
25
|
useEffect(function () {
|
52
26
|
return disposeFetch;
|
53
27
|
}, [disposeFetch]);
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var HooksImplementation = require('./HooksImplementation');
|
@@ -21,15 +10,12 @@ var _require2 = require('react'),
|
|
21
10
|
var _require3 = require('relay-runtime'),
|
22
11
|
getFragment = _require3.getFragment;
|
23
12
|
function useFragment_LEGACY(fragment, key) {
|
24
|
-
// We need to use this hook in order to be able to track if
|
25
|
-
// loadQuery was called during render
|
26
13
|
useTrackLoadQueryInRender();
|
27
14
|
var fragmentNode = getFragment(fragment);
|
28
15
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
29
16
|
var _useFragmentNode = useFragmentNode(fragmentNode, key, 'useFragment()'),
|
30
17
|
data = _useFragmentNode.data;
|
31
18
|
if (process.env.NODE_ENV !== "production") {
|
32
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
33
19
|
useDebugValue({
|
34
20
|
fragment: fragmentNode.name,
|
35
21
|
data: data
|
@@ -40,11 +26,8 @@ function useFragment_LEGACY(fragment, key) {
|
|
40
26
|
function useFragment(fragment, key) {
|
41
27
|
var impl = HooksImplementation.get();
|
42
28
|
if (impl) {
|
43
|
-
// $FlowFixMe This is safe because impl.useFragment has the type of useFragment...
|
44
29
|
return impl.useFragment(fragment, key);
|
45
|
-
// (i.e. type declared above, but not the supertype used in this function definition)
|
46
30
|
} else {
|
47
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
48
31
|
return useFragment_LEGACY(fragment, key);
|
49
32
|
}
|
50
33
|
}
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var _require = require('./FragmentResource'),
|
@@ -19,6 +8,7 @@ var _require2 = require('react'),
|
|
19
8
|
useEffect = _require2.useEffect,
|
20
9
|
useState = _require2.useState;
|
21
10
|
var _require3 = require('relay-runtime'),
|
11
|
+
RelayFeatureFlags = _require3.RelayFeatureFlags,
|
22
12
|
getFragmentIdentifier = _require3.getFragmentIdentifier;
|
23
13
|
var warning = require("fbjs/lib/warning");
|
24
14
|
function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
@@ -28,8 +18,6 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
28
18
|
var _useState = useState(0),
|
29
19
|
forceUpdate = _useState[1];
|
30
20
|
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
31
|
-
|
32
|
-
// Read fragment data; this might suspend.
|
33
21
|
var fragmentResult = FragmentResource.readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName);
|
34
22
|
var isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
|
35
23
|
function enableStoreUpdates() {
|
@@ -46,36 +34,19 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
46
34
|
if (isMountedRef.current === false || isListeningForUpdatesRef.current === false) {
|
47
35
|
return;
|
48
36
|
}
|
49
|
-
|
50
|
-
// React bails out on noop state updates as an optimization.
|
51
|
-
// If we want to force an update via setState, we need to pass an value.
|
52
|
-
// The actual value can be arbitrary though, e.g. an incremented number.
|
53
37
|
forceUpdate(function (count) {
|
54
38
|
return count + 1;
|
55
39
|
});
|
56
40
|
}
|
57
|
-
|
58
|
-
// Establish Relay store subscriptions in the commit phase, only if
|
59
|
-
// rendering for the first time, or if we need to subscribe to new data
|
60
|
-
// If the fragment identifier changes, it means that the variables on the
|
61
|
-
// fragment owner changed, or the fragment ref points to different records.
|
62
|
-
// In this case, we need to resubscribe to the Relay store.
|
63
41
|
useEffect(function () {
|
64
42
|
isMountedRef.current = true;
|
65
43
|
var disposable = FragmentResource.subscribe(fragmentResult, handleDataUpdate);
|
66
44
|
return function () {
|
67
|
-
// When unmounting or resubscribing to new data, clean up current
|
68
|
-
// subscription. This will also make sure fragment data is no longer
|
69
|
-
// cached so that next time it its read, it will be freshly read from
|
70
|
-
// the Relay store
|
71
45
|
isMountedRef.current = false;
|
72
46
|
disposable.dispose();
|
73
47
|
};
|
74
|
-
// NOTE: We disable react-hooks-deps warning because environment and fragmentIdentifier
|
75
|
-
// is capturing all information about whether the effect should be re-ran.
|
76
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
77
48
|
}, [environment, fragmentIdentifier]);
|
78
|
-
if (process.env.NODE_ENV !== "production") {
|
49
|
+
if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
|
79
50
|
if (fragmentRef != null && (fragmentResult.data === undefined || Array.isArray(fragmentResult.data) && fragmentResult.data.length > 0 && fragmentResult.data.every(function (data) {
|
80
51
|
return data === undefined;
|
81
52
|
}))) {
|
@@ -83,7 +54,6 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
83
54
|
}
|
84
55
|
}
|
85
56
|
return {
|
86
|
-
// $FlowFixMe[incompatible-return]
|
87
57
|
data: fragmentResult.data,
|
88
58
|
disableStoreUpdates: disableStoreUpdates,
|
89
59
|
enableStoreUpdates: enableStoreUpdates
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var _require = require('react'),
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var useIsOperationNodeActive = require('./useIsOperationNodeActive');
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var _require = require('./loadQuery'),
|
@@ -18,14 +7,7 @@ var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
|
18
7
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
19
8
|
var _require2 = require('relay-runtime'),
|
20
9
|
fetchQuery = _require2.__internal.fetchQuery;
|
21
|
-
|
22
|
-
// This separate type export is only needed as long as we are injecting
|
23
|
-
// a separate hooks implementation in ./HooksImplementation -- it can
|
24
|
-
// be removed after we stop doing that.
|
25
|
-
|
26
10
|
function useLazyLoadQuery(gqlQuery, variables, options) {
|
27
|
-
// We need to use this hook in order to be able to track if
|
28
|
-
// loadQuery was called during render
|
29
11
|
useTrackLoadQueryInRender();
|
30
12
|
var environment = useRelayEnvironment();
|
31
13
|
var query = useMemoOperationDescriptor(gqlQuery, variables, options && options.networkCacheConfig ? options.networkCacheConfig : {
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var ProfilerContext = require('./ProfilerContext');
|
@@ -51,26 +40,11 @@ function useLazyLoadQueryNode(_ref) {
|
|
51
40
|
var maybeHiddenOrFastRefresh = useRef(false);
|
52
41
|
useEffect(function () {
|
53
42
|
return function () {
|
54
|
-
// Attempt to detect if the component was
|
55
|
-
// hidden (by Offscreen API), or fast refresh occured;
|
56
|
-
// Only in these situations would the effect cleanup
|
57
|
-
// for "unmounting" run multiple times, so if
|
58
|
-
// we are ever able to read this ref with a value
|
59
|
-
// of true, it means that one of these cases
|
60
|
-
// has happened.
|
61
43
|
maybeHiddenOrFastRefresh.current = true;
|
62
44
|
};
|
63
45
|
}, []);
|
64
46
|
useEffect(function () {
|
65
47
|
if (maybeHiddenOrFastRefresh.current === true) {
|
66
|
-
// This block only runs if the component has previously "unmounted"
|
67
|
-
// due to it being hidden by the Offscreen API, or during fast refresh.
|
68
|
-
// At this point, the current cached resource will have been disposed
|
69
|
-
// by the previous cleanup, so instead of attempting to
|
70
|
-
// do our regular commit setup, which would incorrectly attempt to
|
71
|
-
// retain a cached query resource that was disposed, we need to force
|
72
|
-
// a re-render so that the cache entry for this query is re-intiliazed and
|
73
|
-
// and re-evaluated (and potentially cause a refetch).
|
74
48
|
maybeHiddenOrFastRefresh.current = false;
|
75
49
|
forceUpdate(function (n) {
|
76
50
|
return n + 1;
|
@@ -81,19 +55,10 @@ function useLazyLoadQueryNode(_ref) {
|
|
81
55
|
return function () {
|
82
56
|
disposable.dispose();
|
83
57
|
};
|
84
|
-
// NOTE: We disable react-hooks-deps warning because the `environment`
|
85
|
-
// and `cacheIdentifier` identities are capturing all information about whether
|
86
|
-
// the effect should be re-executed and the query re-retained.
|
87
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
88
58
|
}, [environment, cacheIdentifier]);
|
89
59
|
useEffect(function () {
|
90
|
-
// Release any temporary retain that's not released. At this point, if the
|
91
|
-
// cacheIdentifier doesn't change, the query is still permanently retained,
|
92
|
-
// and the temporary retain is redundant.
|
93
60
|
QueryResource.releaseTemporaryRetain(preparedQueryResult);
|
94
|
-
// This effect is intended to run on every commit, thus no dependency
|
95
61
|
});
|
96
|
-
|
97
62
|
var fragmentNode = preparedQueryResult.fragmentNode,
|
98
63
|
fragmentRef = preparedQueryResult.fragmentRef;
|
99
64
|
var _useFragmentNode = useFragmentNode(fragmentNode, fragmentRef, componentDisplayName),
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
@@ -27,6 +16,7 @@ var _require2 = require('relay-runtime'),
|
|
27
16
|
ConnectionInterface = _require2.ConnectionInterface,
|
28
17
|
createOperationDescriptor = _require2.createOperationDescriptor,
|
29
18
|
getPaginationVariables = _require2.getPaginationVariables,
|
19
|
+
getRefetchMetadata = _require2.getRefetchMetadata,
|
30
20
|
getSelector = _require2.getSelector,
|
31
21
|
getValueAtPath = _require2.getValueAtPath;
|
32
22
|
var warning = require("fbjs/lib/warning");
|
@@ -41,15 +31,16 @@ function useLoadMoreFunction(args) {
|
|
41
31
|
paginationMetadata = args.paginationMetadata,
|
42
32
|
componentDisplayName = args.componentDisplayName,
|
43
33
|
observer = args.observer,
|
44
|
-
onReset = args.onReset
|
45
|
-
identifierField = args.identifierField;
|
34
|
+
onReset = args.onReset;
|
46
35
|
var environment = useRelayEnvironment();
|
47
36
|
var _useFetchTrackingRef = useFetchTrackingRef(),
|
48
37
|
isFetchingRef = _useFetchTrackingRef.isFetchingRef,
|
49
38
|
startFetch = _useFetchTrackingRef.startFetch,
|
50
39
|
disposeFetch = _useFetchTrackingRef.disposeFetch,
|
51
40
|
completeFetch = _useFetchTrackingRef.completeFetch;
|
52
|
-
var
|
41
|
+
var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
|
42
|
+
identifierInfo = _getRefetchMetadata.identifierInfo;
|
43
|
+
var identifierValue = (identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierField) != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierInfo.identifierField] : null;
|
53
44
|
var isMountedRef = useIsMountedRef();
|
54
45
|
var _useState = useState(environment),
|
55
46
|
mirroredEnvironment = _useState[0],
|
@@ -68,20 +59,14 @@ function useLoadMoreFunction(args) {
|
|
68
59
|
var _getConnectionState = getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData),
|
69
60
|
cursor = _getConnectionState.cursor,
|
70
61
|
hasMore = _getConnectionState.hasMore;
|
71
|
-
|
72
|
-
// Dispose of pagination requests in flight when unmounting
|
73
62
|
useEffect(function () {
|
74
63
|
return function () {
|
75
64
|
disposeFetch();
|
76
65
|
};
|
77
66
|
}, [disposeFetch]);
|
78
67
|
var loadMore = useCallback(function (count, options) {
|
79
|
-
// TODO(T41131846): Fetch/Caching policies for loadMore
|
80
|
-
|
81
68
|
var onComplete = options === null || options === void 0 ? void 0 : options.onComplete;
|
82
69
|
if (isMountedRef.current !== true) {
|
83
|
-
// Bail out and warn if we're trying to paginate after the component
|
84
|
-
// has unmounted
|
85
70
|
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected fetch on unmounted component for fragment ' + '`%s` in `%s`. It looks like some instances of your component are ' + 'still trying to fetch data but they already unmounted. ' + 'Please make sure you clear all timers, intervals, ' + 'async calls, etc that may trigger a fetch.', fragmentNode.name, componentDisplayName) : void 0;
|
86
71
|
return {
|
87
72
|
dispose: function dispose() {}
|
@@ -105,17 +90,11 @@ function useLoadMoreFunction(args) {
|
|
105
90
|
var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
|
106
91
|
var baseVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables);
|
107
92
|
var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata);
|
108
|
-
|
109
|
-
// If the query needs an identifier value ('id' or similar) and one
|
110
|
-
// was not explicitly provided, read it from the fragment data.
|
111
|
-
if (identifierField != null) {
|
112
|
-
// @refetchable fragments are guaranteed to have an `id` selection
|
113
|
-
// if the type is Node, implements Node, or is @fetchable. Double-check
|
114
|
-
// that there actually is a value at runtime.
|
93
|
+
if (identifierInfo != null) {
|
115
94
|
if (typeof identifierValue !== 'string') {
|
116
|
-
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected result to have a string ' + '`%s` in order to refetch, got `%s`.', identifierField, identifierValue) : void 0;
|
95
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected result to have a string ' + '`%s` in order to refetch, got `%s`.', identifierInfo.identifierField, identifierValue) : void 0;
|
117
96
|
}
|
118
|
-
paginationVariables.
|
97
|
+
paginationVariables[identifierInfo.identifierQueryVariableName] = identifierValue;
|
119
98
|
}
|
120
99
|
var paginationQuery = createOperationDescriptor(paginationRequest, paginationVariables, {
|
121
100
|
force: true
|
@@ -139,11 +118,7 @@ function useLoadMoreFunction(args) {
|
|
139
118
|
return {
|
140
119
|
dispose: disposeFetch
|
141
120
|
};
|
142
|
-
},
|
143
|
-
// NOTE: We disable react-hooks-deps warning because all values
|
144
|
-
// inside paginationMetadata are static
|
145
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
146
|
-
[environment, identifierValue, direction, cursor, startFetch, disposeFetch, completeFetch, isFetchingRef, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
|
121
|
+
}, [environment, identifierValue, direction, cursor, startFetch, disposeFetch, completeFetch, isFetchingRef, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
|
147
122
|
return [loadMore, hasMore, disposeFetch];
|
148
123
|
}
|
149
124
|
function getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData) {
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var useMemoVariables = require('./useMemoVariables');
|
@@ -1,25 +1,8 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var areEqual = require("fbjs/lib/areEqual");
|
15
4
|
var _require = require('react'),
|
16
5
|
useState = _require.useState;
|
17
|
-
|
18
|
-
/**
|
19
|
-
* Memoizes the passed in `variables` object based on `areEqual` equality.
|
20
|
-
* This is useful when a `variables` object is used as a value in a depencency
|
21
|
-
* array as it might often be constructed during render.
|
22
|
-
*/
|
23
6
|
function useMemoVariables(variables) {
|
24
7
|
var _useState = useState(variables),
|
25
8
|
mirroredVariables = _useState[0],
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
@@ -25,11 +14,6 @@ var _require2 = require('relay-runtime'),
|
|
25
14
|
getFragment = _require2.getFragment,
|
26
15
|
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
27
16
|
getPaginationMetadata = _require2.getPaginationMetadata;
|
28
|
-
|
29
|
-
// This separate type export is only needed as long as we are injecting
|
30
|
-
// a separate hooks implementation in ./HooksImplementation -- it can
|
31
|
-
// be removed after we stop doing that.
|
32
|
-
|
33
17
|
function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
34
18
|
var fragmentNode = getFragment(fragmentInput);
|
35
19
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePaginationFragment()');
|
@@ -37,15 +21,12 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
37
21
|
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
38
22
|
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
39
23
|
paginationRequest = _getPaginationMetadat.paginationRequest,
|
40
|
-
paginationMetadata = _getPaginationMetadat.paginationMetadata
|
41
|
-
identifierField = _getPaginationMetadat.identifierField;
|
24
|
+
paginationMetadata = _getPaginationMetadat.paginationMetadata;
|
42
25
|
var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName),
|
43
26
|
fragmentData = _useRefetchableFragme.fragmentData,
|
44
27
|
fragmentRef = _useRefetchableFragme.fragmentRef,
|
45
28
|
refetch = _useRefetchableFragme.refetch;
|
46
29
|
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
47
|
-
|
48
|
-
// Backward pagination
|
49
30
|
var _useLoadMore = useLoadMore({
|
50
31
|
componentDisplayName: componentDisplayName,
|
51
32
|
connectionPathInFragmentData: connectionPathInFragmentData,
|
@@ -54,7 +35,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
54
35
|
fragmentIdentifier: fragmentIdentifier,
|
55
36
|
fragmentNode: fragmentNode,
|
56
37
|
fragmentRef: fragmentRef,
|
57
|
-
identifierField: identifierField,
|
58
38
|
paginationMetadata: paginationMetadata,
|
59
39
|
paginationRequest: paginationRequest
|
60
40
|
}),
|
@@ -62,8 +42,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
62
42
|
hasPrevious = _useLoadMore[1],
|
63
43
|
isLoadingPrevious = _useLoadMore[2],
|
64
44
|
disposeFetchPrevious = _useLoadMore[3];
|
65
|
-
|
66
|
-
// Forward pagination
|
67
45
|
var _useLoadMore2 = useLoadMore({
|
68
46
|
componentDisplayName: componentDisplayName,
|
69
47
|
connectionPathInFragmentData: connectionPathInFragmentData,
|
@@ -72,7 +50,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
72
50
|
fragmentIdentifier: fragmentIdentifier,
|
73
51
|
fragmentNode: fragmentNode,
|
74
52
|
fragmentRef: fragmentRef,
|
75
|
-
identifierField: identifierField,
|
76
53
|
paginationMetadata: paginationMetadata,
|
77
54
|
paginationRequest: paginationRequest
|
78
55
|
}),
|
@@ -88,7 +65,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
88
65
|
}));
|
89
66
|
}, [disposeFetchNext, disposeFetchPrevious, refetch]);
|
90
67
|
if (process.env.NODE_ENV !== "production") {
|
91
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
92
68
|
useDebugValue({
|
93
69
|
fragment: fragmentNode.name,
|
94
70
|
data: fragmentData,
|
@@ -141,7 +117,6 @@ function usePaginationFragment(fragmentInput, parentFragmentRef) {
|
|
141
117
|
if (impl) {
|
142
118
|
return impl.usePaginationFragment(fragmentInput, parentFragmentRef);
|
143
119
|
} else {
|
144
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
145
120
|
return usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef);
|
146
121
|
}
|
147
122
|
}
|
@@ -1,14 +1,3 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
1
|
'use strict';
|
13
2
|
|
14
3
|
var _require = require('./loadQuery'),
|
@@ -25,8 +14,6 @@ var _require3 = require('relay-runtime'),
|
|
25
14
|
fetchQuery = _require3$__internal.fetchQuery;
|
26
15
|
var warning = require("fbjs/lib/warning");
|
27
16
|
function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
28
|
-
// We need to use this hook in order to be able to track if
|
29
|
-
// loadQuery was called during render
|
30
17
|
useTrackLoadQueryInRender();
|
31
18
|
var environment = useRelayEnvironment();
|
32
19
|
var fetchKey = preloadedQuery.fetchKey,
|
@@ -62,24 +49,11 @@ function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
|
62
49
|
var fallbackFetchObservable = fetchQuery(environment, operation);
|
63
50
|
var fetchObservable;
|
64
51
|
if (source != null && environment === preloadedQuery.environment) {
|
65
|
-
// If the source observable exists and the environments match, reuse
|
66
|
-
// the source observable.
|
67
|
-
// If the source observable happens to be empty, we need to fall back
|
68
|
-
// and re-execute and de-dupe the query (at render time).
|
69
52
|
fetchObservable = source.ifEmpty(fallbackFetchObservable);
|
70
53
|
} else if (environment !== preloadedQuery.environment) {
|
71
|
-
// If a call to loadQuery is made with a particular environment, and that
|
72
|
-
// preloaded query is passed to usePreloadedQuery in a different environment
|
73
|
-
// context, we cannot re-use the existing preloaded query.
|
74
|
-
// Instead, we need to fall back and re-execute and de-dupe the query with
|
75
|
-
// the new environment (at render time).
|
76
|
-
// TODO T68036756 track occurences of this warning and turn it into a hard error
|
77
54
|
process.env.NODE_ENV !== "production" ? warning(false, 'usePreloadedQuery(): usePreloadedQuery was passed a preloaded query ' + 'that was created with a different environment than the one that is currently ' + 'in context. In the future, this will become a hard error.') : void 0;
|
78
55
|
fetchObservable = fallbackFetchObservable;
|
79
56
|
} else {
|
80
|
-
// if (source == null)
|
81
|
-
// If the source observable does not exist, we need to
|
82
|
-
// fall back and re-execute and de-dupe the query (at render time).
|
83
57
|
fetchObservable = fallbackFetchObservable;
|
84
58
|
}
|
85
59
|
useLazyLoadQueryNodeParams = {
|
@@ -93,7 +67,6 @@ function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
|
93
67
|
}
|
94
68
|
var data = useLazyLoadQueryNode(useLazyLoadQueryNodeParams);
|
95
69
|
if (process.env.NODE_ENV !== "production") {
|
96
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
97
70
|
useDebugValue({
|
98
71
|
query: preloadedQuery.name,
|
99
72
|
variables: preloadedQuery.variables,
|