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