@apollo/client 3.6.0-beta.9 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs +325 -255
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/ApolloClient.d.ts +2 -3
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +2 -6
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +9 -3
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +78 -41
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +4 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +26 -9
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +115 -65
- package/core/core.cjs.map +1 -1
- package/core/watchQueryOptions.d.ts +3 -1
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +23 -21
- package/react/hooks/hooks.cjs +193 -180
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/index.d.ts +1 -1
- package/react/hooks/index.d.ts.map +1 -1
- package/react/hooks/index.js +1 -1
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +2 -2
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +38 -24
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +6 -3
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +33 -3
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +152 -134
- package/react/hooks/useQuery.js.map +1 -1
- package/react/ssr/RenderPromises.d.ts +2 -1
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js +23 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/ssr.cjs +23 -1
- package/react/ssr/ssr.cjs.map +1 -1
- package/react/types/types.d.ts +9 -13
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/mocking/mockFetch.js +1 -1
- package/testing/core/mocking/mockFetch.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +5 -0
- package/utilities/common/mergeOptions.d.ts.map +1 -0
- package/utilities/common/mergeOptions.js +8 -0
- package/utilities/common/mergeOptions.js.map +1 -0
- package/utilities/graphql/transform.d.ts +2 -2
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +1 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +1 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/utilities.cjs +8 -1
- package/utilities/utilities.cjs.map +1 -1
- package/version.js +1 -1
- package/react/hooks/options.d.ts +0 -3
- package/react/hooks/options.d.ts.map +0 -1
- package/react/hooks/options.js +0 -20
- package/react/hooks/options.js.map +0 -1
package/apollo-client.cjs
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
var tsInvariant = require('ts-invariant');
|
|
7
|
-
var
|
|
7
|
+
var equality = require('@wry/equality');
|
|
8
8
|
var zenObservableTs = require('zen-observable-ts');
|
|
9
9
|
require('symbol-observable');
|
|
10
10
|
var graphql = require('graphql');
|
|
@@ -13,8 +13,7 @@ var context = require('@wry/context');
|
|
|
13
13
|
var trie = require('@wry/trie');
|
|
14
14
|
var graphqlTag = require('graphql-tag');
|
|
15
15
|
var React = require('react');
|
|
16
|
-
|
|
17
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
16
|
+
var index_js = require('use-sync-external-store/shim/index.js');
|
|
18
17
|
|
|
19
18
|
function _interopNamespace(e) {
|
|
20
19
|
if (e && e.__esModule) return e;
|
|
@@ -28,7 +27,6 @@ function _interopNamespace(e) {
|
|
|
28
27
|
return Object.freeze(n);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
32
30
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
33
31
|
|
|
34
32
|
function maybe(thunk) {
|
|
@@ -542,7 +540,7 @@ function removeDirectivesFromDocument(directives, doc) {
|
|
|
542
540
|
return modifiedDoc;
|
|
543
541
|
}
|
|
544
542
|
var addTypenameToDocument = Object.assign(function (doc) {
|
|
545
|
-
return graphql.visit(
|
|
543
|
+
return graphql.visit(doc, {
|
|
546
544
|
SelectionSet: {
|
|
547
545
|
enter: function (node, _key, parent) {
|
|
548
546
|
if (parent &&
|
|
@@ -1090,6 +1088,12 @@ function stringifyForDisplay(value) {
|
|
|
1090
1088
|
}).split(JSON.stringify(undefId)).join("<undefined>");
|
|
1091
1089
|
}
|
|
1092
1090
|
|
|
1091
|
+
function mergeOptions(defaults, options) {
|
|
1092
|
+
return compact(defaults, options, options.variables && {
|
|
1093
|
+
variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1093
1097
|
function fromError(errorValue) {
|
|
1094
1098
|
return new zenObservableTs.Observable(function (observer) {
|
|
1095
1099
|
observer.error(errorValue);
|
|
@@ -1294,7 +1298,7 @@ var concat = ApolloLink.concat;
|
|
|
1294
1298
|
|
|
1295
1299
|
var execute = ApolloLink.execute;
|
|
1296
1300
|
|
|
1297
|
-
var version = '3.6.0
|
|
1301
|
+
var version = '3.6.0';
|
|
1298
1302
|
|
|
1299
1303
|
var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1300
1304
|
function parseAndCheckHttpResponse(operations) {
|
|
@@ -2162,7 +2166,7 @@ var Layer = (function (_super) {
|
|
|
2162
2166
|
}
|
|
2163
2167
|
else if (ownStoreObject !== parentStoreObject) {
|
|
2164
2168
|
Object.keys(ownStoreObject).forEach(function (storeFieldName) {
|
|
2165
|
-
if (!
|
|
2169
|
+
if (!equality.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
|
|
2166
2170
|
_this.group.dirty(dataId, storeFieldName);
|
|
2167
2171
|
}
|
|
2168
2172
|
});
|
|
@@ -2206,7 +2210,7 @@ var Stump = (function (_super) {
|
|
|
2206
2210
|
function storeObjectReconciler(existingObject, incomingObject, property) {
|
|
2207
2211
|
var existingValue = existingObject[property];
|
|
2208
2212
|
var incomingValue = incomingObject[property];
|
|
2209
|
-
return
|
|
2213
|
+
return equality.equal(existingValue, incomingValue) ? existingValue : incomingValue;
|
|
2210
2214
|
}
|
|
2211
2215
|
function supportsResultCaching(store) {
|
|
2212
2216
|
return !!(store instanceof EntityStore && store.group.caching);
|
|
@@ -3536,7 +3540,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
3536
3540
|
return;
|
|
3537
3541
|
if (isReference(existing))
|
|
3538
3542
|
return;
|
|
3539
|
-
if (
|
|
3543
|
+
if (equality.equal(existing, incoming))
|
|
3540
3544
|
return;
|
|
3541
3545
|
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
3542
3546
|
return;
|
|
@@ -3850,7 +3854,7 @@ var InMemoryCache = (function (_super) {
|
|
|
3850
3854
|
return;
|
|
3851
3855
|
}
|
|
3852
3856
|
}
|
|
3853
|
-
if (!lastDiff || !
|
|
3857
|
+
if (!lastDiff || !equality.equal(lastDiff.result, diff.result)) {
|
|
3854
3858
|
c.callback(c.lastDiff = diff, lastDiff);
|
|
3855
3859
|
}
|
|
3856
3860
|
};
|
|
@@ -3909,7 +3913,6 @@ function isNetworkRequestInFlight(networkStatus) {
|
|
|
3909
3913
|
}
|
|
3910
3914
|
|
|
3911
3915
|
var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
|
|
3912
|
-
var warnedAboutUpdateQuery = false;
|
|
3913
3916
|
var ObservableQuery = (function (_super) {
|
|
3914
3917
|
tslib.__extends(ObservableQuery, _super);
|
|
3915
3918
|
function ObservableQuery(_a) {
|
|
@@ -3942,16 +3945,22 @@ var ObservableQuery = (function (_super) {
|
|
|
3942
3945
|
}) || this;
|
|
3943
3946
|
_this.observers = new Set();
|
|
3944
3947
|
_this.subscriptions = new Set();
|
|
3948
|
+
_this.queryInfo = queryInfo;
|
|
3949
|
+
_this.queryManager = queryManager;
|
|
3945
3950
|
_this.isTornDown = false;
|
|
3946
|
-
_this.options = options;
|
|
3951
|
+
_this.options = tslib.__assign({ initialFetchPolicy: options.fetchPolicy || "cache-first" }, options);
|
|
3947
3952
|
_this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
|
3948
|
-
var opDef = getOperationDefinition(
|
|
3953
|
+
var opDef = getOperationDefinition(_this.query);
|
|
3949
3954
|
_this.queryName = opDef && opDef.name && opDef.name.value;
|
|
3950
|
-
_this.initialFetchPolicy = options.fetchPolicy || "cache-first";
|
|
3951
|
-
_this.queryManager = queryManager;
|
|
3952
|
-
_this.queryInfo = queryInfo;
|
|
3953
3955
|
return _this;
|
|
3954
3956
|
}
|
|
3957
|
+
Object.defineProperty(ObservableQuery.prototype, "query", {
|
|
3958
|
+
get: function () {
|
|
3959
|
+
return this.queryManager.transform(this.options.query).document;
|
|
3960
|
+
},
|
|
3961
|
+
enumerable: false,
|
|
3962
|
+
configurable: true
|
|
3963
|
+
});
|
|
3955
3964
|
Object.defineProperty(ObservableQuery.prototype, "variables", {
|
|
3956
3965
|
get: function () {
|
|
3957
3966
|
return this.options.variables;
|
|
@@ -3995,7 +4004,7 @@ var ObservableQuery = (function (_super) {
|
|
|
3995
4004
|
if (diff.complete || this.options.returnPartialData) {
|
|
3996
4005
|
result.data = diff.result;
|
|
3997
4006
|
}
|
|
3998
|
-
if (
|
|
4007
|
+
if (equality.equal(result.data, {})) {
|
|
3999
4008
|
result.data = void 0;
|
|
4000
4009
|
}
|
|
4001
4010
|
if (diff.complete) {
|
|
@@ -4026,13 +4035,13 @@ var ObservableQuery = (function (_super) {
|
|
|
4026
4035
|
return result;
|
|
4027
4036
|
};
|
|
4028
4037
|
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
|
|
4029
|
-
return !this.last || !
|
|
4038
|
+
return !this.last || !equality.equal(this.last.result, newResult);
|
|
4030
4039
|
};
|
|
4031
4040
|
ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
|
|
4032
4041
|
var last = this.last;
|
|
4033
4042
|
if (last &&
|
|
4034
4043
|
last[key] &&
|
|
4035
|
-
(!variablesMustMatch ||
|
|
4044
|
+
(!variablesMustMatch || equality.equal(last.variables, this.variables))) {
|
|
4036
4045
|
return last[key];
|
|
4037
4046
|
}
|
|
4038
4047
|
};
|
|
@@ -4065,13 +4074,13 @@ var ObservableQuery = (function (_super) {
|
|
|
4065
4074
|
reobserveOptions.fetchPolicy = 'network-only';
|
|
4066
4075
|
}
|
|
4067
4076
|
if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
|
|
4068
|
-
var queryDef = getQueryDefinition(this.
|
|
4077
|
+
var queryDef = getQueryDefinition(this.query);
|
|
4069
4078
|
var vars = queryDef.variableDefinitions;
|
|
4070
4079
|
if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
|
|
4071
4080
|
__DEV__ && tsInvariant.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
|
|
4072
4081
|
}
|
|
4073
4082
|
}
|
|
4074
|
-
if (variables && !
|
|
4083
|
+
if (variables && !equality.equal(this.options.variables, variables)) {
|
|
4075
4084
|
reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
4076
4085
|
}
|
|
4077
4086
|
this.queryInfo.resetLastWrite();
|
|
@@ -4079,37 +4088,51 @@ var ObservableQuery = (function (_super) {
|
|
|
4079
4088
|
};
|
|
4080
4089
|
ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
|
4081
4090
|
var _this = this;
|
|
4082
|
-
var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
|
|
4091
|
+
var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), { query: this.query }), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
|
|
4083
4092
|
var qid = this.queryManager.generateQueryId();
|
|
4093
|
+
var queryInfo = this.queryInfo;
|
|
4094
|
+
var originalNetworkStatus = queryInfo.networkStatus;
|
|
4095
|
+
queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
4084
4096
|
if (combinedOptions.notifyOnNetworkStatusChange) {
|
|
4085
|
-
this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
4086
4097
|
this.observe();
|
|
4087
4098
|
}
|
|
4099
|
+
var updatedQuerySet = new Set();
|
|
4088
4100
|
return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4101
|
+
_this.queryManager.removeQuery(qid);
|
|
4102
|
+
if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
|
|
4103
|
+
queryInfo.networkStatus = originalNetworkStatus;
|
|
4104
|
+
}
|
|
4105
|
+
_this.queryManager.cache.batch({
|
|
4106
|
+
update: function (cache) {
|
|
4107
|
+
var updateQuery = fetchMoreOptions.updateQuery;
|
|
4108
|
+
if (updateQuery) {
|
|
4109
|
+
cache.updateQuery({
|
|
4110
|
+
query: _this.query,
|
|
4111
|
+
variables: _this.variables,
|
|
4112
|
+
returnPartialData: true,
|
|
4113
|
+
optimistic: false,
|
|
4114
|
+
}, function (previous) { return updateQuery(previous, {
|
|
4115
|
+
fetchMoreResult: fetchMoreResult.data,
|
|
4116
|
+
variables: combinedOptions.variables,
|
|
4117
|
+
}); });
|
|
4118
|
+
}
|
|
4119
|
+
else {
|
|
4120
|
+
cache.writeQuery({
|
|
4121
|
+
query: combinedOptions.query,
|
|
4122
|
+
variables: combinedOptions.variables,
|
|
4123
|
+
data: fetchMoreResult.data,
|
|
4124
|
+
});
|
|
4125
|
+
}
|
|
4126
|
+
},
|
|
4127
|
+
onWatchUpdated: function (watch) {
|
|
4128
|
+
updatedQuerySet.add(watch.query);
|
|
4129
|
+
},
|
|
4130
|
+
});
|
|
4109
4131
|
return fetchMoreResult;
|
|
4110
4132
|
}).finally(function () {
|
|
4111
|
-
_this.
|
|
4112
|
-
|
|
4133
|
+
if (!updatedQuerySet.has(_this.query)) {
|
|
4134
|
+
reobserveCacheFirst(_this);
|
|
4135
|
+
}
|
|
4113
4136
|
});
|
|
4114
4137
|
};
|
|
4115
4138
|
ObservableQuery.prototype.subscribeToMore = function (options) {
|
|
@@ -4152,7 +4175,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4152
4175
|
return this.reobserve(newOptions);
|
|
4153
4176
|
};
|
|
4154
4177
|
ObservableQuery.prototype.setVariables = function (variables) {
|
|
4155
|
-
if (
|
|
4178
|
+
if (equality.equal(this.variables, variables)) {
|
|
4156
4179
|
return this.observers.size
|
|
4157
4180
|
? this.result()
|
|
4158
4181
|
: Promise.resolve();
|
|
@@ -4162,7 +4185,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4162
4185
|
return Promise.resolve();
|
|
4163
4186
|
}
|
|
4164
4187
|
return this.reobserve({
|
|
4165
|
-
fetchPolicy: this.initialFetchPolicy,
|
|
4188
|
+
fetchPolicy: this.options.initialFetchPolicy,
|
|
4166
4189
|
variables: variables,
|
|
4167
4190
|
}, exports.NetworkStatus.setVariables);
|
|
4168
4191
|
};
|
|
@@ -4195,19 +4218,18 @@ var ObservableQuery = (function (_super) {
|
|
|
4195
4218
|
this.updatePolling();
|
|
4196
4219
|
};
|
|
4197
4220
|
ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
|
|
4198
|
-
if (options === void 0) { options = this.options; }
|
|
4199
4221
|
if (options.nextFetchPolicy) {
|
|
4200
|
-
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
|
|
4222
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
|
|
4201
4223
|
if (typeof options.nextFetchPolicy === "function") {
|
|
4202
4224
|
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
4203
4225
|
reason: reason,
|
|
4204
4226
|
options: options,
|
|
4205
4227
|
observable: this,
|
|
4206
|
-
|
|
4228
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
4207
4229
|
});
|
|
4208
4230
|
}
|
|
4209
4231
|
else if (reason === "variables-changed") {
|
|
4210
|
-
options.fetchPolicy =
|
|
4232
|
+
options.fetchPolicy = initialFetchPolicy;
|
|
4211
4233
|
}
|
|
4212
4234
|
else {
|
|
4213
4235
|
options.fetchPolicy = options.nextFetchPolicy;
|
|
@@ -4277,16 +4299,18 @@ var ObservableQuery = (function (_super) {
|
|
|
4277
4299
|
newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
|
4278
4300
|
newNetworkStatus === exports.NetworkStatus.poll;
|
|
4279
4301
|
var oldVariables = this.options.variables;
|
|
4302
|
+
var oldFetchPolicy = this.options.fetchPolicy;
|
|
4303
|
+
var mergedOptions = mergeOptions(this.options, newOptions || {});
|
|
4280
4304
|
var options = useDisposableConcast
|
|
4281
|
-
?
|
|
4282
|
-
: assign(this.options,
|
|
4305
|
+
? mergedOptions
|
|
4306
|
+
: assign(this.options, mergedOptions);
|
|
4283
4307
|
if (!useDisposableConcast) {
|
|
4284
4308
|
this.updatePolling();
|
|
4285
4309
|
if (newOptions &&
|
|
4286
4310
|
newOptions.variables &&
|
|
4287
|
-
!newOptions.
|
|
4288
|
-
!
|
|
4289
|
-
this.applyNextFetchPolicy("variables-changed");
|
|
4311
|
+
!equality.equal(newOptions.variables, oldVariables) &&
|
|
4312
|
+
(!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
|
|
4313
|
+
this.applyNextFetchPolicy("variables-changed", options);
|
|
4290
4314
|
if (newNetworkStatus === void 0) {
|
|
4291
4315
|
newNetworkStatus = exports.NetworkStatus.setVariables;
|
|
4292
4316
|
}
|
|
@@ -4350,6 +4374,23 @@ var ObservableQuery = (function (_super) {
|
|
|
4350
4374
|
return ObservableQuery;
|
|
4351
4375
|
}(zenObservableTs.Observable));
|
|
4352
4376
|
fixObservableSubclass(ObservableQuery);
|
|
4377
|
+
function reobserveCacheFirst(obsQuery) {
|
|
4378
|
+
var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
|
|
4379
|
+
if (fetchPolicy === "cache-and-network" ||
|
|
4380
|
+
fetchPolicy === "network-only") {
|
|
4381
|
+
return obsQuery.reobserve({
|
|
4382
|
+
fetchPolicy: "cache-first",
|
|
4383
|
+
nextFetchPolicy: function () {
|
|
4384
|
+
this.nextFetchPolicy = nextFetchPolicy;
|
|
4385
|
+
if (typeof nextFetchPolicy === "function") {
|
|
4386
|
+
return nextFetchPolicy.apply(this, arguments);
|
|
4387
|
+
}
|
|
4388
|
+
return fetchPolicy;
|
|
4389
|
+
},
|
|
4390
|
+
});
|
|
4391
|
+
}
|
|
4392
|
+
return obsQuery.reobserve();
|
|
4393
|
+
}
|
|
4353
4394
|
function defaultSubscriptionObserverErrorCallback(error) {
|
|
4354
4395
|
__DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
|
|
4355
4396
|
}
|
|
@@ -4659,10 +4700,10 @@ var QueryInfo = (function () {
|
|
|
4659
4700
|
var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
|
|
4660
4701
|
if (this.variables &&
|
|
4661
4702
|
this.networkStatus !== exports.NetworkStatus.loading &&
|
|
4662
|
-
!
|
|
4703
|
+
!equality.equal(this.variables, query.variables)) {
|
|
4663
4704
|
networkStatus = exports.NetworkStatus.setVariables;
|
|
4664
4705
|
}
|
|
4665
|
-
if (!
|
|
4706
|
+
if (!equality.equal(query.variables, this.variables)) {
|
|
4666
4707
|
this.lastDiff = void 0;
|
|
4667
4708
|
}
|
|
4668
4709
|
Object.assign(this, {
|
|
@@ -4688,7 +4729,7 @@ var QueryInfo = (function () {
|
|
|
4688
4729
|
QueryInfo.prototype.getDiff = function (variables) {
|
|
4689
4730
|
if (variables === void 0) { variables = this.variables; }
|
|
4690
4731
|
var options = this.getDiffOptions(variables);
|
|
4691
|
-
if (this.lastDiff &&
|
|
4732
|
+
if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
|
|
4692
4733
|
return this.lastDiff.diff;
|
|
4693
4734
|
}
|
|
4694
4735
|
this.updateWatch(this.variables = variables);
|
|
@@ -4722,7 +4763,7 @@ var QueryInfo = (function () {
|
|
|
4722
4763
|
var oldDiff = this.lastDiff && this.lastDiff.diff;
|
|
4723
4764
|
this.updateLastDiff(diff);
|
|
4724
4765
|
if (!this.dirty &&
|
|
4725
|
-
!
|
|
4766
|
+
!equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
|
4726
4767
|
this.dirty = true;
|
|
4727
4768
|
if (!this.notifyTimeout) {
|
|
4728
4769
|
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
@@ -4740,11 +4781,12 @@ var QueryInfo = (function () {
|
|
|
4740
4781
|
if (oq) {
|
|
4741
4782
|
oq["queryInfo"] = this;
|
|
4742
4783
|
this.listeners.add(this.oqListener = function () {
|
|
4743
|
-
|
|
4784
|
+
var diff = _this.getDiff();
|
|
4785
|
+
if (diff.fromOptimisticTransaction) {
|
|
4744
4786
|
oq["observe"]();
|
|
4745
4787
|
}
|
|
4746
4788
|
else {
|
|
4747
|
-
oq
|
|
4789
|
+
reobserveCacheFirst(oq);
|
|
4748
4790
|
}
|
|
4749
4791
|
});
|
|
4750
4792
|
}
|
|
@@ -4796,7 +4838,7 @@ var QueryInfo = (function () {
|
|
|
4796
4838
|
}
|
|
4797
4839
|
var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
|
4798
4840
|
if (!this.lastWatch ||
|
|
4799
|
-
!
|
|
4841
|
+
!equality.equal(watchOptions, this.lastWatch)) {
|
|
4800
4842
|
this.cancel();
|
|
4801
4843
|
this.cancel = this.cache.watch(this.lastWatch = watchOptions);
|
|
4802
4844
|
}
|
|
@@ -4808,8 +4850,8 @@ var QueryInfo = (function () {
|
|
|
4808
4850
|
var lastWrite = this.lastWrite;
|
|
4809
4851
|
return !(lastWrite &&
|
|
4810
4852
|
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
4811
|
-
|
|
4812
|
-
|
|
4853
|
+
equality.equal(variables, lastWrite.variables) &&
|
|
4854
|
+
equality.equal(result.data, lastWrite.result.data));
|
|
4813
4855
|
};
|
|
4814
4856
|
QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
|
|
4815
4857
|
var _this = this;
|
|
@@ -5207,9 +5249,9 @@ var QueryManager = (function () {
|
|
|
5207
5249
|
});
|
|
5208
5250
|
this.queries.set(observable.queryId, queryInfo);
|
|
5209
5251
|
queryInfo.init({
|
|
5210
|
-
document:
|
|
5252
|
+
document: observable.query,
|
|
5211
5253
|
observableQuery: observable,
|
|
5212
|
-
variables:
|
|
5254
|
+
variables: observable.variables,
|
|
5213
5255
|
});
|
|
5214
5256
|
return observable;
|
|
5215
5257
|
};
|
|
@@ -5393,8 +5435,10 @@ var QueryManager = (function () {
|
|
|
5393
5435
|
};
|
|
5394
5436
|
QueryManager.prototype.removeQuery = function (queryId) {
|
|
5395
5437
|
this.fetchCancelFns.delete(queryId);
|
|
5396
|
-
this.
|
|
5397
|
-
|
|
5438
|
+
if (this.queries.has(queryId)) {
|
|
5439
|
+
this.getQuery(queryId).stop();
|
|
5440
|
+
this.queries.delete(queryId);
|
|
5441
|
+
}
|
|
5398
5442
|
};
|
|
5399
5443
|
QueryManager.prototype.broadcastQueries = function () {
|
|
5400
5444
|
if (this.onBroadcast)
|
|
@@ -5478,10 +5522,11 @@ var QueryManager = (function () {
|
|
|
5478
5522
|
var aqr = {
|
|
5479
5523
|
data: result.data,
|
|
5480
5524
|
loading: false,
|
|
5481
|
-
networkStatus:
|
|
5525
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
5482
5526
|
};
|
|
5483
5527
|
if (hasErrors && options.errorPolicy !== "ignore") {
|
|
5484
5528
|
aqr.errors = result.errors;
|
|
5529
|
+
aqr.networkStatus = exports.NetworkStatus.error;
|
|
5485
5530
|
}
|
|
5486
5531
|
return aqr;
|
|
5487
5532
|
}, function (networkError) {
|
|
@@ -5599,10 +5644,10 @@ var QueryManager = (function () {
|
|
|
5599
5644
|
};
|
|
5600
5645
|
QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a, networkStatus) {
|
|
5601
5646
|
var _this = this;
|
|
5602
|
-
var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange;
|
|
5647
|
+
var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange, fetchBlockingPromise = _a.fetchBlockingPromise;
|
|
5603
5648
|
var oldNetworkStatus = queryInfo.networkStatus;
|
|
5604
5649
|
queryInfo.init({
|
|
5605
|
-
document: query,
|
|
5650
|
+
document: this.transform(query).document,
|
|
5606
5651
|
variables: variables,
|
|
5607
5652
|
networkStatus: networkStatus,
|
|
5608
5653
|
});
|
|
@@ -5612,7 +5657,7 @@ var QueryManager = (function () {
|
|
|
5612
5657
|
var data = diff.result;
|
|
5613
5658
|
if (__DEV__ &&
|
|
5614
5659
|
!returnPartialData &&
|
|
5615
|
-
!
|
|
5660
|
+
!equality.equal(data, {})) {
|
|
5616
5661
|
logMissingFieldErrors(diff.missing);
|
|
5617
5662
|
}
|
|
5618
5663
|
var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
@@ -5632,12 +5677,26 @@ var QueryManager = (function () {
|
|
|
5632
5677
|
refetchWritePolicy !== "merge") ? 1
|
|
5633
5678
|
: 2;
|
|
5634
5679
|
var resultsFromLink = function () {
|
|
5635
|
-
return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
5680
|
+
var get = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
5636
5681
|
variables: variables,
|
|
5637
5682
|
context: context,
|
|
5638
5683
|
fetchPolicy: fetchPolicy,
|
|
5639
5684
|
errorPolicy: errorPolicy,
|
|
5640
|
-
});
|
|
5685
|
+
}); };
|
|
5686
|
+
return fetchBlockingPromise ? fetchBlockingPromise.then(function (ok) { return ok ? get() : zenObservableTs.Observable.of(); }, function (error) {
|
|
5687
|
+
var apolloError = isApolloError(error)
|
|
5688
|
+
? error
|
|
5689
|
+
: new ApolloError({ clientErrors: [error] });
|
|
5690
|
+
if (errorPolicy !== "ignore") {
|
|
5691
|
+
queryInfo.markError(apolloError);
|
|
5692
|
+
}
|
|
5693
|
+
return zenObservableTs.Observable.of({
|
|
5694
|
+
loading: false,
|
|
5695
|
+
networkStatus: exports.NetworkStatus.error,
|
|
5696
|
+
error: apolloError,
|
|
5697
|
+
data: readCache().result,
|
|
5698
|
+
});
|
|
5699
|
+
}) : get();
|
|
5641
5700
|
};
|
|
5642
5701
|
var shouldNotify = notifyOnNetworkStatusChange &&
|
|
5643
5702
|
typeof oldNetworkStatus === "number" &&
|
|
@@ -5713,11 +5772,6 @@ var QueryManager = (function () {
|
|
|
5713
5772
|
}());
|
|
5714
5773
|
|
|
5715
5774
|
var hasSuggestedDevtools = false;
|
|
5716
|
-
function mergeOptions(defaults, options) {
|
|
5717
|
-
return compact(defaults, options, options.variables && {
|
|
5718
|
-
variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
|
|
5719
|
-
});
|
|
5720
|
-
}
|
|
5721
5775
|
var ApolloClient = (function () {
|
|
5722
5776
|
function ApolloClient(options) {
|
|
5723
5777
|
var _this = this;
|
|
@@ -6075,26 +6129,9 @@ function verifyDocumentType(document, type) {
|
|
|
6075
6129
|
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
|
|
6076
6130
|
}
|
|
6077
6131
|
|
|
6078
|
-
function useNormalizedOptions(optionsOrFunction) {
|
|
6079
|
-
var optionsRef = React.useRef();
|
|
6080
|
-
var options = optionsRef.current || Object.create(null);
|
|
6081
|
-
if (typeof optionsOrFunction === "function") {
|
|
6082
|
-
var newOptions = optionsOrFunction(options);
|
|
6083
|
-
if (newOptions !== options) {
|
|
6084
|
-
Object.assign(options, newOptions, newOptions.variables && {
|
|
6085
|
-
variables: tslib.__assign(tslib.__assign({}, options.variables), newOptions.variables),
|
|
6086
|
-
});
|
|
6087
|
-
}
|
|
6088
|
-
}
|
|
6089
|
-
else if (optionsOrFunction && !equal__default(optionsOrFunction, options)) {
|
|
6090
|
-
options = optionsOrFunction;
|
|
6091
|
-
}
|
|
6092
|
-
return optionsRef.current = options;
|
|
6093
|
-
}
|
|
6094
|
-
|
|
6095
6132
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
6096
|
-
function useQuery(query,
|
|
6097
|
-
|
|
6133
|
+
function useQuery(query, options) {
|
|
6134
|
+
if (options === void 0) { options = Object.create(null); }
|
|
6098
6135
|
return useInternalState(useApolloClient(options.client), query).useQuery(options);
|
|
6099
6136
|
}
|
|
6100
6137
|
function useInternalState(client, query) {
|
|
@@ -6115,118 +6152,31 @@ var InternalState = (function () {
|
|
|
6115
6152
|
function InternalState(client, query) {
|
|
6116
6153
|
this.client = client;
|
|
6117
6154
|
this.query = query;
|
|
6155
|
+
this.ssrDisabledResult = maybeDeepFreeze({
|
|
6156
|
+
loading: true,
|
|
6157
|
+
data: void 0,
|
|
6158
|
+
error: void 0,
|
|
6159
|
+
networkStatus: exports.NetworkStatus.loading,
|
|
6160
|
+
});
|
|
6161
|
+
this.skipStandbyResult = maybeDeepFreeze({
|
|
6162
|
+
loading: false,
|
|
6163
|
+
data: void 0,
|
|
6164
|
+
error: void 0,
|
|
6165
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
6166
|
+
});
|
|
6118
6167
|
this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
|
|
6119
6168
|
verifyDocumentType(query, exports.DocumentType.Query);
|
|
6120
6169
|
}
|
|
6121
6170
|
InternalState.prototype.forceUpdate = function () {
|
|
6122
6171
|
};
|
|
6123
6172
|
InternalState.prototype.useQuery = function (options) {
|
|
6173
|
+
var _this = this;
|
|
6174
|
+
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6124
6175
|
this.useOptions(options);
|
|
6125
6176
|
var obsQuery = this.useObservableQuery();
|
|
6126
|
-
|
|
6127
|
-
var result = this.getCurrentResult();
|
|
6128
|
-
this.unsafeHandlePartialRefetch(result);
|
|
6129
|
-
return this.toQueryResult(result);
|
|
6130
|
-
};
|
|
6131
|
-
InternalState.prototype.useOptions = function (options) {
|
|
6132
|
-
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6133
|
-
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6134
|
-
if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
|
|
6135
|
-
this.watchQueryOptions = watchQueryOptions;
|
|
6136
|
-
}
|
|
6137
|
-
this.ssrDisabled = !!(options && (options.ssr === false ||
|
|
6138
|
-
options.skip));
|
|
6139
|
-
this.onCompleted = options
|
|
6140
|
-
&& options.onCompleted
|
|
6141
|
-
|| InternalState.prototype.onCompleted;
|
|
6142
|
-
this.onError = options
|
|
6143
|
-
&& options.onError
|
|
6144
|
-
|| InternalState.prototype.onError;
|
|
6145
|
-
};
|
|
6146
|
-
InternalState.prototype.createWatchQueryOptions = function (_a) {
|
|
6147
|
-
var _b;
|
|
6148
|
-
if (_a === void 0) { _a = {}; }
|
|
6149
|
-
var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
|
|
6150
|
-
var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
|
|
6151
|
-
if (skip) {
|
|
6152
|
-
watchQueryOptions.fetchPolicy = 'standby';
|
|
6153
|
-
}
|
|
6154
|
-
else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
|
|
6155
|
-
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
6156
|
-
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
6157
|
-
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6158
|
-
}
|
|
6159
|
-
else if (!watchQueryOptions.fetchPolicy) {
|
|
6160
|
-
var defaultOptions = this.client.defaultOptions.watchQuery;
|
|
6161
|
-
watchQueryOptions.fetchPolicy =
|
|
6162
|
-
defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
|
|
6163
|
-
}
|
|
6164
|
-
if (!watchQueryOptions.variables) {
|
|
6165
|
-
watchQueryOptions.variables = {};
|
|
6166
|
-
}
|
|
6167
|
-
return watchQueryOptions;
|
|
6168
|
-
};
|
|
6169
|
-
InternalState.prototype.onCompleted = function (data) { };
|
|
6170
|
-
InternalState.prototype.onError = function (error) { };
|
|
6171
|
-
InternalState.prototype.useObservableQuery = function () {
|
|
6172
|
-
var _this = this;
|
|
6173
|
-
var obsQuery = this.observable =
|
|
6174
|
-
this.renderPromises
|
|
6175
|
-
&& this.renderPromises.getSSRObservable(this.watchQueryOptions)
|
|
6176
|
-
|| this.observable
|
|
6177
|
-
|| this.client.watchQuery(this.watchQueryOptions);
|
|
6178
|
-
this.obsQueryFields = React.useMemo(function () { return ({
|
|
6179
|
-
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6180
|
-
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
6181
|
-
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
6182
|
-
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
6183
|
-
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6184
|
-
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6185
|
-
}); }, [obsQuery]);
|
|
6186
|
-
if (this.renderPromises) {
|
|
6187
|
-
this.renderPromises.registerSSRObservable(obsQuery);
|
|
6188
|
-
if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
|
|
6189
|
-
this.renderPromises.addQueryPromise({
|
|
6190
|
-
getOptions: function () { return obsQuery.options; },
|
|
6191
|
-
fetchData: function () { return new Promise(function (resolve) {
|
|
6192
|
-
var sub = obsQuery.subscribe({
|
|
6193
|
-
next: function (result) {
|
|
6194
|
-
if (!result.loading) {
|
|
6195
|
-
resolve();
|
|
6196
|
-
sub.unsubscribe();
|
|
6197
|
-
}
|
|
6198
|
-
},
|
|
6199
|
-
error: function () {
|
|
6200
|
-
resolve();
|
|
6201
|
-
sub.unsubscribe();
|
|
6202
|
-
},
|
|
6203
|
-
complete: function () {
|
|
6204
|
-
resolve();
|
|
6205
|
-
},
|
|
6206
|
-
});
|
|
6207
|
-
}); },
|
|
6208
|
-
}, function () { return null; });
|
|
6209
|
-
obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
|
|
6210
|
-
}
|
|
6211
|
-
}
|
|
6212
|
-
var prevOptionsRef = React.useRef({
|
|
6213
|
-
watchQueryOptions: this.watchQueryOptions,
|
|
6214
|
-
});
|
|
6215
|
-
React.useEffect(function () {
|
|
6216
|
-
if (_this.renderPromises) ;
|
|
6217
|
-
else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
|
|
6218
|
-
obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
|
|
6219
|
-
prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
|
|
6220
|
-
_this.setResult(obsQuery.getCurrentResult());
|
|
6221
|
-
}
|
|
6222
|
-
}, [obsQuery, this.watchQueryOptions]);
|
|
6223
|
-
return obsQuery;
|
|
6224
|
-
};
|
|
6225
|
-
InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
|
|
6226
|
-
var _this = this;
|
|
6227
|
-
React.useEffect(function () {
|
|
6177
|
+
var result = index_js.useSyncExternalStore(React.useCallback(function () {
|
|
6228
6178
|
if (_this.renderPromises) {
|
|
6229
|
-
return;
|
|
6179
|
+
return function () { };
|
|
6230
6180
|
}
|
|
6231
6181
|
var onNext = function () {
|
|
6232
6182
|
var previousResult = _this.result;
|
|
@@ -6234,7 +6184,7 @@ var InternalState = (function () {
|
|
|
6234
6184
|
if (previousResult &&
|
|
6235
6185
|
previousResult.loading === result.loading &&
|
|
6236
6186
|
previousResult.networkStatus === result.networkStatus &&
|
|
6237
|
-
|
|
6187
|
+
equality.equal(previousResult.data, result.data)) {
|
|
6238
6188
|
return;
|
|
6239
6189
|
}
|
|
6240
6190
|
_this.setResult(result);
|
|
@@ -6255,7 +6205,7 @@ var InternalState = (function () {
|
|
|
6255
6205
|
var previousResult = _this.result;
|
|
6256
6206
|
if (!previousResult ||
|
|
6257
6207
|
(previousResult && previousResult.loading) ||
|
|
6258
|
-
!
|
|
6208
|
+
!equality.equal(error, previousResult.error)) {
|
|
6259
6209
|
_this.setResult({
|
|
6260
6210
|
data: (previousResult && previousResult.data),
|
|
6261
6211
|
error: error,
|
|
@@ -6270,7 +6220,117 @@ var InternalState = (function () {
|
|
|
6270
6220
|
obsQuery,
|
|
6271
6221
|
this.renderPromises,
|
|
6272
6222
|
this.client.disableNetworkFetches,
|
|
6273
|
-
]);
|
|
6223
|
+
]), function () { return _this.getCurrentResult(); });
|
|
6224
|
+
this.unsafeHandlePartialRefetch(result);
|
|
6225
|
+
return this.toQueryResult(result);
|
|
6226
|
+
};
|
|
6227
|
+
InternalState.prototype.useOptions = function (options) {
|
|
6228
|
+
var _a;
|
|
6229
|
+
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6230
|
+
var currentWatchQueryOptions = this.watchQueryOptions;
|
|
6231
|
+
var resolveFetchBlockingPromise;
|
|
6232
|
+
if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
6233
|
+
this.watchQueryOptions = watchQueryOptions;
|
|
6234
|
+
if (currentWatchQueryOptions && this.observable) {
|
|
6235
|
+
this.observable.reobserve(tslib.__assign({ fetchBlockingPromise: new Promise(function (resolve) {
|
|
6236
|
+
resolveFetchBlockingPromise = resolve;
|
|
6237
|
+
}) }, watchQueryOptions));
|
|
6238
|
+
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
6239
|
+
this.result = void 0;
|
|
6240
|
+
}
|
|
6241
|
+
}
|
|
6242
|
+
useUnblockFetchEffect(this.renderPromises, resolveFetchBlockingPromise);
|
|
6243
|
+
this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
|
|
6244
|
+
this.onError = options.onError || InternalState.prototype.onError;
|
|
6245
|
+
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
6246
|
+
this.queryHookOptions.ssr === false) {
|
|
6247
|
+
this.result = this.ssrDisabledResult;
|
|
6248
|
+
}
|
|
6249
|
+
else if (this.queryHookOptions.skip ||
|
|
6250
|
+
this.watchQueryOptions.fetchPolicy === 'standby') {
|
|
6251
|
+
this.result = this.skipStandbyResult;
|
|
6252
|
+
}
|
|
6253
|
+
else if (this.result === this.ssrDisabledResult ||
|
|
6254
|
+
this.result === this.skipStandbyResult) {
|
|
6255
|
+
this.result = void 0;
|
|
6256
|
+
}
|
|
6257
|
+
};
|
|
6258
|
+
InternalState.prototype.createWatchQueryOptions = function (_a) {
|
|
6259
|
+
if (_a === void 0) { _a = {}; }
|
|
6260
|
+
var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var defaultOptions = _a.defaultOptions, otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
|
|
6261
|
+
var toMerge = [];
|
|
6262
|
+
var globalDefaults = this.client.defaultOptions.watchQuery;
|
|
6263
|
+
if (globalDefaults)
|
|
6264
|
+
toMerge.push(globalDefaults);
|
|
6265
|
+
if (defaultOptions)
|
|
6266
|
+
toMerge.push(defaultOptions);
|
|
6267
|
+
var latestOptions = this.observable && this.observable.options;
|
|
6268
|
+
if (latestOptions && toMerge.length) {
|
|
6269
|
+
var defaults_1 = toMerge.reduce(mergeOptions, Object.create(null));
|
|
6270
|
+
toMerge.length = 1;
|
|
6271
|
+
toMerge[0] = defaults_1;
|
|
6272
|
+
Object.keys(defaults_1).forEach(function (defaultOptionName) {
|
|
6273
|
+
var currentOptionValue = latestOptions[defaultOptionName];
|
|
6274
|
+
if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
|
|
6275
|
+
!equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
|
|
6276
|
+
defaults_1[defaultOptionName] = defaultOptionName === "variables"
|
|
6277
|
+
? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
|
|
6278
|
+
}
|
|
6279
|
+
});
|
|
6280
|
+
}
|
|
6281
|
+
toMerge.push(otherOptions);
|
|
6282
|
+
var merged = toMerge.reduce(mergeOptions, Object.create(null));
|
|
6283
|
+
var watchQueryOptions = Object.assign(merged, { query: this.query });
|
|
6284
|
+
if (this.renderPromises &&
|
|
6285
|
+
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
6286
|
+
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
6287
|
+
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6288
|
+
}
|
|
6289
|
+
else if (!watchQueryOptions.fetchPolicy) {
|
|
6290
|
+
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6291
|
+
}
|
|
6292
|
+
if (skip) {
|
|
6293
|
+
var _b = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? watchQueryOptions.fetchPolicy : _b;
|
|
6294
|
+
Object.assign(watchQueryOptions, {
|
|
6295
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
6296
|
+
fetchPolicy: 'standby',
|
|
6297
|
+
});
|
|
6298
|
+
}
|
|
6299
|
+
if (!watchQueryOptions.variables) {
|
|
6300
|
+
watchQueryOptions.variables = {};
|
|
6301
|
+
}
|
|
6302
|
+
return watchQueryOptions;
|
|
6303
|
+
};
|
|
6304
|
+
InternalState.prototype.onCompleted = function (data) { };
|
|
6305
|
+
InternalState.prototype.onError = function (error) { };
|
|
6306
|
+
InternalState.prototype.useObservableQuery = function () {
|
|
6307
|
+
var resolveFetchBlockingPromise;
|
|
6308
|
+
var obsQuery = this.observable =
|
|
6309
|
+
this.renderPromises
|
|
6310
|
+
&& this.renderPromises.getSSRObservable(this.watchQueryOptions)
|
|
6311
|
+
|| this.observable
|
|
6312
|
+
|| this.client.watchQuery(tslib.__assign({ fetchBlockingPromise: new Promise(function (resolve) {
|
|
6313
|
+
resolveFetchBlockingPromise = resolve;
|
|
6314
|
+
}) }, this.watchQueryOptions));
|
|
6315
|
+
useUnblockFetchEffect(this.renderPromises, resolveFetchBlockingPromise);
|
|
6316
|
+
this.obsQueryFields = React.useMemo(function () { return ({
|
|
6317
|
+
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6318
|
+
reobserve: obsQuery.reobserve.bind(obsQuery),
|
|
6319
|
+
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
6320
|
+
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
6321
|
+
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
6322
|
+
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6323
|
+
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6324
|
+
}); }, [obsQuery]);
|
|
6325
|
+
if (this.renderPromises) {
|
|
6326
|
+
this.renderPromises.registerSSRObservable(obsQuery);
|
|
6327
|
+
var ssrAllowed = !(this.queryHookOptions.ssr === false ||
|
|
6328
|
+
this.queryHookOptions.skip);
|
|
6329
|
+
if (ssrAllowed && obsQuery.getCurrentResult().loading) {
|
|
6330
|
+
this.renderPromises.addObservableQueryPromise(obsQuery);
|
|
6331
|
+
}
|
|
6332
|
+
}
|
|
6333
|
+
return obsQuery;
|
|
6274
6334
|
};
|
|
6275
6335
|
InternalState.prototype.setResult = function (nextResult) {
|
|
6276
6336
|
var previousResult = this.result;
|
|
@@ -6292,30 +6352,10 @@ var InternalState = (function () {
|
|
|
6292
6352
|
}
|
|
6293
6353
|
};
|
|
6294
6354
|
InternalState.prototype.getCurrentResult = function () {
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
result = this.result = this.observable.getCurrentResult();
|
|
6298
|
-
this.handleErrorOrCompleted(result);
|
|
6299
|
-
}
|
|
6300
|
-
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
6301
|
-
this.queryHookOptions.ssr === false) {
|
|
6302
|
-
result = {
|
|
6303
|
-
loading: true,
|
|
6304
|
-
data: void 0,
|
|
6305
|
-
error: void 0,
|
|
6306
|
-
networkStatus: exports.NetworkStatus.loading,
|
|
6307
|
-
};
|
|
6308
|
-
}
|
|
6309
|
-
else if (this.queryHookOptions.skip ||
|
|
6310
|
-
this.queryHookOptions.fetchPolicy === 'standby') {
|
|
6311
|
-
result = {
|
|
6312
|
-
loading: false,
|
|
6313
|
-
data: void 0,
|
|
6314
|
-
error: void 0,
|
|
6315
|
-
networkStatus: exports.NetworkStatus.ready,
|
|
6316
|
-
};
|
|
6355
|
+
if (!this.result) {
|
|
6356
|
+
this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
|
|
6317
6357
|
}
|
|
6318
|
-
return result;
|
|
6358
|
+
return this.result;
|
|
6319
6359
|
};
|
|
6320
6360
|
InternalState.prototype.toQueryResult = function (result) {
|
|
6321
6361
|
var queryResult = this.toQueryResultCache.get(result);
|
|
@@ -6343,34 +6383,52 @@ var InternalState = (function () {
|
|
|
6343
6383
|
};
|
|
6344
6384
|
return InternalState;
|
|
6345
6385
|
}());
|
|
6386
|
+
function useUnblockFetchEffect(renderPromises, resolveFetchBlockingPromise) {
|
|
6387
|
+
if (resolveFetchBlockingPromise) {
|
|
6388
|
+
if (renderPromises) {
|
|
6389
|
+
resolveFetchBlockingPromise(true);
|
|
6390
|
+
}
|
|
6391
|
+
else {
|
|
6392
|
+
setTimeout(function () { return resolveFetchBlockingPromise(false); }, 5000);
|
|
6393
|
+
}
|
|
6394
|
+
}
|
|
6395
|
+
React.useEffect(function () {
|
|
6396
|
+
if (resolveFetchBlockingPromise) {
|
|
6397
|
+
resolveFetchBlockingPromise(true);
|
|
6398
|
+
}
|
|
6399
|
+
}, [resolveFetchBlockingPromise]);
|
|
6400
|
+
}
|
|
6346
6401
|
|
|
6347
6402
|
var EAGER_METHODS = [
|
|
6348
6403
|
'refetch',
|
|
6404
|
+
'reobserve',
|
|
6349
6405
|
'fetchMore',
|
|
6350
6406
|
'updateQuery',
|
|
6351
6407
|
'startPolling',
|
|
6352
6408
|
'subscribeToMore',
|
|
6353
6409
|
];
|
|
6354
|
-
function useLazyQuery(query,
|
|
6355
|
-
var
|
|
6356
|
-
var
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
}
|
|
6410
|
+
function useLazyQuery(query, options) {
|
|
6411
|
+
var internalState = useInternalState(useApolloClient(options && options.client), query);
|
|
6412
|
+
var execOptionsRef = React.useRef();
|
|
6413
|
+
var defaultOptions = internalState.client.defaultOptions.watchQuery;
|
|
6414
|
+
var initialFetchPolicy = (options && options.fetchPolicy) ||
|
|
6415
|
+
(execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
|
|
6416
|
+
(defaultOptions && defaultOptions.fetchPolicy) ||
|
|
6417
|
+
"cache-first";
|
|
6418
|
+
var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
|
|
6419
|
+
var result = Object.assign(useQueryResult, {
|
|
6420
|
+
called: !!execOptionsRef.current,
|
|
6421
|
+
});
|
|
6363
6422
|
var eagerMethods = React.useMemo(function () {
|
|
6364
6423
|
var eagerMethods = {};
|
|
6365
6424
|
var _loop_1 = function (key) {
|
|
6366
6425
|
var method = result[key];
|
|
6367
6426
|
eagerMethods[key] = function () {
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6427
|
+
if (!execOptionsRef.current) {
|
|
6428
|
+
execOptionsRef.current = Object.create(null);
|
|
6429
|
+
internalState.forceUpdate();
|
|
6371
6430
|
}
|
|
6372
|
-
|
|
6373
|
-
return method.apply(void 0, args);
|
|
6431
|
+
return method.apply(this, arguments);
|
|
6374
6432
|
};
|
|
6375
6433
|
};
|
|
6376
6434
|
for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
|
|
@@ -6379,15 +6437,24 @@ function useLazyQuery(query, optionsOrFunction) {
|
|
|
6379
6437
|
}
|
|
6380
6438
|
return eagerMethods;
|
|
6381
6439
|
}, []);
|
|
6382
|
-
result.error = result.error || void 0;
|
|
6383
6440
|
Object.assign(result, eagerMethods);
|
|
6384
6441
|
var execute = React.useCallback(function (executeOptions) {
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6442
|
+
var promise = result.reobserve(execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
6443
|
+
fetchPolicy: initialFetchPolicy,
|
|
6444
|
+
}).then(function (apolloQueryResult) {
|
|
6445
|
+
apolloQueryResult = apolloQueryResult || internalState["getCurrentResult"]();
|
|
6446
|
+
if (apolloQueryResult.error ||
|
|
6447
|
+
isNonEmptyArray(apolloQueryResult.errors)) {
|
|
6448
|
+
var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
|
|
6449
|
+
if (errorPolicy === "none") {
|
|
6450
|
+
throw apolloQueryResult.error || new ApolloError({
|
|
6451
|
+
graphQLErrors: apolloQueryResult.errors,
|
|
6452
|
+
});
|
|
6453
|
+
}
|
|
6454
|
+
}
|
|
6455
|
+
return internalState.toQueryResult(apolloQueryResult);
|
|
6456
|
+
}).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
6457
|
+
internalState.forceUpdate();
|
|
6391
6458
|
promise.catch(function () { });
|
|
6392
6459
|
return promise;
|
|
6393
6460
|
}, []);
|
|
@@ -6443,7 +6510,7 @@ function useMutation(mutation, options) {
|
|
|
6443
6510
|
error: error,
|
|
6444
6511
|
client: client,
|
|
6445
6512
|
};
|
|
6446
|
-
if (ref.current.isMounted && !
|
|
6513
|
+
if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
|
|
6447
6514
|
setResult(ref.current.result = result_1);
|
|
6448
6515
|
}
|
|
6449
6516
|
}
|
|
@@ -6461,7 +6528,7 @@ function useMutation(mutation, options) {
|
|
|
6461
6528
|
called: true,
|
|
6462
6529
|
client: client,
|
|
6463
6530
|
};
|
|
6464
|
-
if (!
|
|
6531
|
+
if (!equality.equal(ref.current.result, result_2)) {
|
|
6465
6532
|
setResult(ref.current.result = result_2);
|
|
6466
6533
|
}
|
|
6467
6534
|
}
|
|
@@ -6476,9 +6543,12 @@ function useMutation(mutation, options) {
|
|
|
6476
6543
|
var reset = React.useCallback(function () {
|
|
6477
6544
|
setResult({ called: false, loading: false, client: client });
|
|
6478
6545
|
}, []);
|
|
6479
|
-
React.useEffect(function () {
|
|
6480
|
-
ref.current.isMounted =
|
|
6481
|
-
|
|
6546
|
+
React.useEffect(function () {
|
|
6547
|
+
ref.current.isMounted = true;
|
|
6548
|
+
return function () {
|
|
6549
|
+
ref.current.isMounted = false;
|
|
6550
|
+
};
|
|
6551
|
+
}, []);
|
|
6482
6552
|
return [execute, tslib.__assign({ reset: reset }, result)];
|
|
6483
6553
|
}
|
|
6484
6554
|
|
|
@@ -6524,7 +6594,7 @@ function useSubscription(subscription, options) {
|
|
|
6524
6594
|
subscription !== ref.current.subscription ||
|
|
6525
6595
|
(options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
|
|
6526
6596
|
!(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
|
|
6527
|
-
!
|
|
6597
|
+
!equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
|
|
6528
6598
|
setResult({
|
|
6529
6599
|
loading: true,
|
|
6530
6600
|
data: void 0,
|