react-relay 14.1.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +19 -5
- package/ReactRelayQueryRenderer.js.flow +32 -1
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +1 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +7 -5
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +2 -2
- package/lib/ReactRelayContext.js +3 -3
- package/lib/ReactRelayFragmentContainer.js +39 -66
- package/lib/ReactRelayFragmentMockRenderer.js +2 -3
- package/lib/ReactRelayLocalQueryRenderer.js +18 -30
- package/lib/ReactRelayPaginationContainer.js +66 -159
- package/lib/ReactRelayQueryFetcher.js +48 -74
- package/lib/ReactRelayQueryRenderer.js +62 -82
- package/lib/ReactRelayQueryRendererContext.js +2 -1
- package/lib/ReactRelayRefetchContainer.js +52 -99
- package/lib/ReactRelayTestMocker.js +32 -66
- package/lib/ReactRelayTypes.js +2 -0
- package/lib/RelayContext.js +4 -6
- package/lib/assertFragmentMap.js +3 -4
- package/lib/buildReactRelayContainer.js +10 -25
- package/lib/getRootVariablesForFragments.js +5 -8
- package/lib/hooks.js +5 -17
- package/lib/index.js +5 -24
- package/lib/isRelayEnvironment.js +5 -3
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -7
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -7
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
- package/lib/relay-hooks/FragmentResource.js +102 -196
- package/lib/relay-hooks/HooksImplementation.js +2 -5
- package/lib/relay-hooks/InternalLogger.js +2 -2
- package/lib/relay-hooks/LRUCache.js +2 -19
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
- package/lib/relay-hooks/MatchContainer.js +14 -22
- package/lib/relay-hooks/ProfilerContext.js +3 -2
- package/lib/relay-hooks/QueryResource.js +30 -99
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
- package/lib/relay-hooks/SuspenseResource.js +8 -31
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +41 -77
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
- package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
- package/lib/relay-hooks/useClientQuery.js +3 -6
- package/lib/relay-hooks/useEntryPointLoader.js +17 -36
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
- package/lib/relay-hooks/useFragment.js +8 -18
- package/lib/relay-hooks/useFragmentNode.js +20 -31
- package/lib/relay-hooks/useIsMountedRef.js +4 -5
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +6 -9
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
- package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
- package/lib/relay-hooks/useMemoVariables.js +15 -33
- package/lib/relay-hooks/useMutation.js +8 -25
- package/lib/relay-hooks/usePaginationFragment.js +61 -76
- package/lib/relay-hooks/usePreloadedQuery.js +12 -29
- package/lib/relay-hooks/useQueryLoader.js +23 -47
- package/lib/relay-hooks/useRefetchableFragment.js +8 -18
- package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
- package/lib/relay-hooks/useRelayEnvironment.js +4 -7
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
- package/lib/relay-hooks/useSubscription.js +5 -9
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
- 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 +1 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
- package/relay-hooks/FragmentResource.js.flow +34 -8
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +35 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
- package/relay-hooks/useClientQuery.js.flow +1 -1
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +5 -4
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +4 -4
- package/relay-hooks/usePaginationFragment.js.flow +53 -46
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +85 -22
- package/relay-hooks/useRefetchableFragment.js.flow +64 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
@@ -6,81 +6,82 @@
|
|
6
6
|
*
|
7
7
|
*
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
11
|
+
|
10
12
|
'use strict';
|
11
13
|
|
12
14
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
13
|
-
|
14
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
-
|
16
16
|
var invariant = require('invariant');
|
17
|
-
|
18
17
|
var _require = require('relay-runtime'),
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
fetchQuery = _require.__internal.fetchQuery,
|
19
|
+
createOperationDescriptor = _require.createOperationDescriptor,
|
20
|
+
isRelayModernEnvironment = _require.isRelayModernEnvironment;
|
23
21
|
var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
24
22
|
function ReactRelayQueryFetcher(args) {
|
25
23
|
(0, _defineProperty2["default"])(this, "_selectionReferences", []);
|
26
|
-
(0, _defineProperty2["default"])(this, "
|
27
|
-
|
24
|
+
(0, _defineProperty2["default"])(this, "_didFetchFinish", false);
|
28
25
|
if (args != null) {
|
29
26
|
this._cacheSelectionReference = args.cacheSelectionReference;
|
30
27
|
this._selectionReferences = args.selectionReferences;
|
31
28
|
}
|
32
29
|
}
|
33
|
-
|
34
30
|
var _proto = ReactRelayQueryFetcher.prototype;
|
35
|
-
|
36
31
|
_proto.getSelectionReferences = function getSelectionReferences() {
|
37
32
|
return {
|
38
33
|
cacheSelectionReference: this._cacheSelectionReference,
|
39
34
|
selectionReferences: this._selectionReferences
|
40
35
|
};
|
41
36
|
};
|
42
|
-
|
43
37
|
_proto.lookupInStore = function lookupInStore(environment, operation, fetchPolicy) {
|
44
38
|
if (fetchPolicy === 'store-and-network' || fetchPolicy === 'store-or-network') {
|
45
39
|
if (environment.check(operation).status === 'available') {
|
46
40
|
this._retainCachedOperation(environment, operation);
|
47
|
-
|
48
41
|
return environment.lookup(operation.fragment);
|
49
42
|
}
|
50
43
|
}
|
51
|
-
|
52
44
|
return null;
|
53
45
|
};
|
54
|
-
|
46
|
+
_proto.getFetchResult = function getFetchResult() {
|
47
|
+
if (this._didFetchFinish) {
|
48
|
+
// We don't reset '_didFetchFinish' because another callback may be set
|
49
|
+
if (this._error != null) {
|
50
|
+
return {
|
51
|
+
error: this._error
|
52
|
+
};
|
53
|
+
} else if (this._snapshot != null) {
|
54
|
+
return {
|
55
|
+
snapshot: this._snapshot
|
56
|
+
};
|
57
|
+
}
|
58
|
+
} else {
|
59
|
+
return null;
|
60
|
+
}
|
61
|
+
};
|
55
62
|
_proto.execute = function execute(_ref) {
|
56
63
|
var _this = this;
|
57
|
-
|
58
64
|
var environment = _ref.environment,
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
operation = _ref.operation,
|
66
|
+
_ref$preservePrevious = _ref.preservePreviousReferences,
|
67
|
+
preservePreviousReferences = _ref$preservePrevious === void 0 ? false : _ref$preservePrevious;
|
62
68
|
var reference = environment.retain(operation);
|
63
|
-
|
64
69
|
var error = function error() {
|
65
70
|
// We may have partially fulfilled the request, so let the next request
|
66
71
|
// or the unmount dispose of the references.
|
67
72
|
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
68
73
|
};
|
69
|
-
|
70
74
|
var complete = function complete() {
|
71
75
|
if (!preservePreviousReferences) {
|
72
76
|
_this.disposeSelectionReferences();
|
73
77
|
}
|
74
|
-
|
75
78
|
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
76
79
|
};
|
77
|
-
|
78
80
|
var unsubscribe = function unsubscribe() {
|
79
81
|
// Let the next request or the unmount code dispose of the references.
|
80
82
|
// We may have partially fulfilled the request.
|
81
83
|
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
82
84
|
};
|
83
|
-
|
84
85
|
if (!isRelayModernEnvironment(environment)) {
|
85
86
|
return environment.execute({
|
86
87
|
operation: operation
|
@@ -90,26 +91,21 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
90
91
|
unsubscribe: unsubscribe
|
91
92
|
});
|
92
93
|
}
|
93
|
-
|
94
94
|
return fetchQuery(environment, operation)["do"]({
|
95
95
|
error: error,
|
96
96
|
complete: complete,
|
97
97
|
unsubscribe: unsubscribe
|
98
98
|
});
|
99
99
|
};
|
100
|
-
|
101
100
|
_proto.setOnDataChange = function setOnDataChange(onDataChange) {
|
102
101
|
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `setOnDataChange` should have been called after having called `fetch`') : invariant(false) : void 0;
|
103
|
-
|
104
102
|
if (typeof onDataChange === 'function') {
|
105
103
|
// Mutate the most recent fetchOptions in place,
|
106
104
|
// So that in-progress requests can access the updated callback.
|
107
105
|
this._fetchOptions.onDataChangeCallbacks = this._fetchOptions.onDataChangeCallbacks || [];
|
108
|
-
|
109
106
|
this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
|
110
|
-
|
111
|
-
|
112
|
-
// We don't reset '_callOnDataChangeWhenSet' because another callback may be set
|
107
|
+
if (this._didFetchFinish) {
|
108
|
+
// We don't reset '_didFetchFinish' because another callback may be set
|
113
109
|
if (this._error != null) {
|
114
110
|
onDataChange({
|
115
111
|
error: this._error
|
@@ -122,6 +118,7 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
122
118
|
}
|
123
119
|
}
|
124
120
|
}
|
121
|
+
|
125
122
|
/**
|
126
123
|
* `fetch` fetches the data for the given operation.
|
127
124
|
* If a result is immediately available synchronously, it will be synchronously
|
@@ -130,19 +127,14 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
130
127
|
* Otherwise, the fetched result will be communicated via the `onDataChange` callback.
|
131
128
|
* `onDataChange` will be called with the first result (**if it wasn't returned synchronously**),
|
132
129
|
* and then subsequently whenever the data changes.
|
133
|
-
|
134
|
-
;
|
135
|
-
|
130
|
+
*/;
|
136
131
|
_proto.fetch = function fetch(fetchOptions, cacheConfigOverride) {
|
137
132
|
var _this2 = this;
|
138
|
-
|
139
133
|
var environment = fetchOptions.environment,
|
140
|
-
|
141
|
-
|
134
|
+
operation = fetchOptions.operation,
|
135
|
+
onDataChange = fetchOptions.onDataChange;
|
142
136
|
var fetchHasReturned = false;
|
143
|
-
|
144
137
|
var _error;
|
145
|
-
|
146
138
|
this.disposeRequest();
|
147
139
|
var oldOnDataChangeCallbacks = this._fetchOptions && this._fetchOptions.onDataChangeCallbacks;
|
148
140
|
this._fetchOptions = {
|
@@ -150,12 +142,10 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
150
142
|
onDataChangeCallbacks: oldOnDataChangeCallbacks || [],
|
151
143
|
operation: operation
|
152
144
|
};
|
153
|
-
|
154
145
|
if (onDataChange && this._fetchOptions.onDataChangeCallbacks.indexOf(onDataChange) === -1) {
|
155
146
|
// $FlowFixMe[incompatible-use]
|
156
147
|
this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
|
157
148
|
}
|
158
|
-
|
159
149
|
var operationOverride = cacheConfigOverride ? createOperationDescriptor(operation.request.node, operation.request.variables, cacheConfigOverride) : operation;
|
160
150
|
var request = this.execute({
|
161
151
|
environment: environment,
|
@@ -166,10 +156,11 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
166
156
|
next: function next() {
|
167
157
|
// If we received a response,
|
168
158
|
// Make a note that to notify the callback when it's later added.
|
169
|
-
_this2.
|
170
|
-
_this2._error = null;
|
171
|
-
// (i.e. after `fetch` has returned).
|
159
|
+
_this2._didFetchFinish = true;
|
160
|
+
_this2._error = null;
|
172
161
|
|
162
|
+
// Only notify of the first result if `next` is being called **asynchronously**
|
163
|
+
// (i.e. after `fetch` has returned).
|
173
164
|
_this2._onQueryDataAvailable({
|
174
165
|
notifyFirstResult: fetchHasReturned
|
175
166
|
});
|
@@ -177,12 +168,13 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
177
168
|
error: function error(err) {
|
178
169
|
// If we received a response when we didn't have a change callback,
|
179
170
|
// Make a note that to notify the callback when it's later added.
|
180
|
-
_this2.
|
171
|
+
_this2._didFetchFinish = true;
|
181
172
|
_this2._error = err;
|
182
173
|
_this2._snapshot = null;
|
183
|
-
var onDataChangeCallbacks = _this2._fetchOptions && _this2._fetchOptions.onDataChangeCallbacks;
|
184
|
-
// (i.e. after `fetch` has returned).
|
174
|
+
var onDataChangeCallbacks = _this2._fetchOptions && _this2._fetchOptions.onDataChangeCallbacks;
|
185
175
|
|
176
|
+
// Only notify of error if `error` is being called **asynchronously**
|
177
|
+
// (i.e. after `fetch` has returned).
|
186
178
|
if (fetchHasReturned) {
|
187
179
|
if (onDataChangeCallbacks) {
|
188
180
|
onDataChangeCallbacks.forEach(function (onDataChange) {
|
@@ -202,88 +194,73 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
202
194
|
}
|
203
195
|
};
|
204
196
|
fetchHasReturned = true;
|
205
|
-
|
206
197
|
if (_error) {
|
207
198
|
throw _error;
|
208
199
|
}
|
209
|
-
|
210
200
|
return this._snapshot;
|
211
201
|
};
|
212
|
-
|
213
202
|
_proto.retry = function retry(cacheConfigOverride) {
|
214
203
|
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `retry` should be called after having called `fetch`') : invariant(false) : void 0;
|
215
204
|
return this.fetch({
|
216
205
|
environment: this._fetchOptions.environment,
|
217
206
|
operation: this._fetchOptions.operation,
|
218
207
|
onDataChange: null // If there are onDataChangeCallbacks they will be reused
|
219
|
-
|
220
208
|
}, cacheConfigOverride);
|
221
209
|
};
|
222
|
-
|
223
210
|
_proto.dispose = function dispose() {
|
224
211
|
this.disposeRequest();
|
225
212
|
this.disposeSelectionReferences();
|
226
213
|
};
|
227
|
-
|
228
214
|
_proto.disposeRequest = function disposeRequest() {
|
229
215
|
this._error = null;
|
230
|
-
this._snapshot = null;
|
216
|
+
this._snapshot = null;
|
231
217
|
|
218
|
+
// order is important, dispose of pendingFetch before selectionReferences
|
232
219
|
if (this._pendingRequest) {
|
233
220
|
this._pendingRequest.dispose();
|
234
221
|
}
|
235
|
-
|
236
222
|
if (this._rootSubscription) {
|
237
223
|
this._rootSubscription.dispose();
|
238
|
-
|
239
224
|
this._rootSubscription = null;
|
240
225
|
}
|
241
226
|
};
|
242
|
-
|
243
227
|
_proto._retainCachedOperation = function _retainCachedOperation(environment, operation) {
|
244
228
|
this._disposeCacheSelectionReference();
|
245
|
-
|
246
229
|
this._cacheSelectionReference = environment.retain(operation);
|
247
230
|
};
|
248
|
-
|
249
231
|
_proto._disposeCacheSelectionReference = function _disposeCacheSelectionReference() {
|
250
232
|
this._cacheSelectionReference && this._cacheSelectionReference.dispose();
|
251
233
|
this._cacheSelectionReference = null;
|
252
234
|
};
|
253
|
-
|
254
235
|
_proto.disposeSelectionReferences = function disposeSelectionReferences() {
|
255
236
|
this._disposeCacheSelectionReference();
|
256
|
-
|
257
237
|
this._selectionReferences.forEach(function (r) {
|
258
238
|
return r.dispose();
|
259
239
|
});
|
260
|
-
|
261
240
|
this._selectionReferences = [];
|
262
241
|
};
|
263
|
-
|
264
242
|
_proto._onQueryDataAvailable = function _onQueryDataAvailable(_ref2) {
|
265
243
|
var _this3 = this;
|
266
|
-
|
267
244
|
var notifyFirstResult = _ref2.notifyFirstResult;
|
268
245
|
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `_onQueryDataAvailable` should have been called after having called `fetch`') : invariant(false) : void 0;
|
269
246
|
var _this$_fetchOptions = this._fetchOptions,
|
270
|
-
|
271
|
-
|
272
|
-
|
247
|
+
environment = _this$_fetchOptions.environment,
|
248
|
+
onDataChangeCallbacks = _this$_fetchOptions.onDataChangeCallbacks,
|
249
|
+
operation = _this$_fetchOptions.operation;
|
250
|
+
|
251
|
+
// `_onQueryDataAvailable` can be called synchronously the first time and can be called
|
273
252
|
// multiple times by network layers that support data subscriptions.
|
274
253
|
// Wait until the first payload to call `onDataChange` and subscribe for data updates.
|
275
|
-
|
276
254
|
if (this._snapshot) {
|
277
255
|
return;
|
278
256
|
}
|
257
|
+
this._snapshot = environment.lookup(operation.fragment);
|
279
258
|
|
280
|
-
|
281
|
-
|
259
|
+
// Subscribe to changes in the data of the root fragment
|
282
260
|
this._rootSubscription = environment.subscribe(this._snapshot, function (snapshot) {
|
283
261
|
// Read from this._fetchOptions in case onDataChange() was lazily added.
|
284
262
|
if (_this3._fetchOptions != null) {
|
285
263
|
var maybeNewOnDataChangeCallbacks = _this3._fetchOptions.onDataChangeCallbacks;
|
286
|
-
|
287
264
|
if (Array.isArray(maybeNewOnDataChangeCallbacks)) {
|
288
265
|
maybeNewOnDataChangeCallbacks.forEach(function (onDataChange) {
|
289
266
|
return onDataChange({
|
@@ -293,7 +270,6 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
293
270
|
}
|
294
271
|
}
|
295
272
|
});
|
296
|
-
|
297
273
|
if (this._snapshot && notifyFirstResult && Array.isArray(onDataChangeCallbacks)) {
|
298
274
|
var snapshot = this._snapshot;
|
299
275
|
onDataChangeCallbacks.forEach(function (onDataChange) {
|
@@ -303,8 +279,6 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
303
279
|
});
|
304
280
|
}
|
305
281
|
};
|
306
|
-
|
307
282
|
return ReactRelayQueryFetcher;
|
308
283
|
}();
|
309
|
-
|
310
284
|
module.exports = ReactRelayQueryFetcher;
|