@apollo/client 3.6.0-beta.8 → 3.6.0-rc.1
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 +339 -258
- 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 +10 -4
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +95 -45
- 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 +30 -11
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +135 -71
- package/core/core.cjs.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.d.ts.map +1 -1
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/watchQueryOptions.d.ts +10 -1
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +15 -13
- package/react/hooks/hooks.cjs +187 -177
- 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.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-rc.1';
|
|
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
|
};
|
|
@@ -4194,6 +4217,26 @@ var ObservableQuery = (function (_super) {
|
|
|
4194
4217
|
this.options.pollInterval = 0;
|
|
4195
4218
|
this.updatePolling();
|
|
4196
4219
|
};
|
|
4220
|
+
ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
|
|
4221
|
+
if (options.nextFetchPolicy) {
|
|
4222
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
|
|
4223
|
+
if (typeof options.nextFetchPolicy === "function") {
|
|
4224
|
+
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
4225
|
+
reason: reason,
|
|
4226
|
+
options: options,
|
|
4227
|
+
observable: this,
|
|
4228
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
4229
|
+
});
|
|
4230
|
+
}
|
|
4231
|
+
else if (reason === "variables-changed") {
|
|
4232
|
+
options.fetchPolicy = initialFetchPolicy;
|
|
4233
|
+
}
|
|
4234
|
+
else {
|
|
4235
|
+
options.fetchPolicy = options.nextFetchPolicy;
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
return options.fetchPolicy;
|
|
4239
|
+
};
|
|
4197
4240
|
ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
|
|
4198
4241
|
this.queryManager.setObservableQuery(this);
|
|
4199
4242
|
return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
|
|
@@ -4256,16 +4299,18 @@ var ObservableQuery = (function (_super) {
|
|
|
4256
4299
|
newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
|
4257
4300
|
newNetworkStatus === exports.NetworkStatus.poll;
|
|
4258
4301
|
var oldVariables = this.options.variables;
|
|
4302
|
+
var oldFetchPolicy = this.options.fetchPolicy;
|
|
4303
|
+
var mergedOptions = mergeOptions(this.options, newOptions || {});
|
|
4259
4304
|
var options = useDisposableConcast
|
|
4260
|
-
?
|
|
4261
|
-
: assign(this.options,
|
|
4305
|
+
? mergedOptions
|
|
4306
|
+
: assign(this.options, mergedOptions);
|
|
4262
4307
|
if (!useDisposableConcast) {
|
|
4263
4308
|
this.updatePolling();
|
|
4264
4309
|
if (newOptions &&
|
|
4265
4310
|
newOptions.variables &&
|
|
4266
|
-
!newOptions.
|
|
4267
|
-
!
|
|
4268
|
-
|
|
4311
|
+
!equality.equal(newOptions.variables, oldVariables) &&
|
|
4312
|
+
(!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
|
|
4313
|
+
this.applyNextFetchPolicy("variables-changed", options);
|
|
4269
4314
|
if (newNetworkStatus === void 0) {
|
|
4270
4315
|
newNetworkStatus = exports.NetworkStatus.setVariables;
|
|
4271
4316
|
}
|
|
@@ -4329,6 +4374,23 @@ var ObservableQuery = (function (_super) {
|
|
|
4329
4374
|
return ObservableQuery;
|
|
4330
4375
|
}(zenObservableTs.Observable));
|
|
4331
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
|
+
}
|
|
4332
4394
|
function defaultSubscriptionObserverErrorCallback(error) {
|
|
4333
4395
|
__DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
|
|
4334
4396
|
}
|
|
@@ -4337,14 +4399,6 @@ function logMissingFieldErrors(missing) {
|
|
|
4337
4399
|
__DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
|
|
4338
4400
|
}
|
|
4339
4401
|
}
|
|
4340
|
-
function applyNextFetchPolicy(options) {
|
|
4341
|
-
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
|
|
4342
|
-
if (nextFetchPolicy) {
|
|
4343
|
-
options.fetchPolicy = typeof nextFetchPolicy === "function"
|
|
4344
|
-
? nextFetchPolicy.call(options, fetchPolicy)
|
|
4345
|
-
: nextFetchPolicy;
|
|
4346
|
-
}
|
|
4347
|
-
}
|
|
4348
4402
|
|
|
4349
4403
|
var LocalState = (function () {
|
|
4350
4404
|
function LocalState(_a) {
|
|
@@ -4646,10 +4700,10 @@ var QueryInfo = (function () {
|
|
|
4646
4700
|
var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
|
|
4647
4701
|
if (this.variables &&
|
|
4648
4702
|
this.networkStatus !== exports.NetworkStatus.loading &&
|
|
4649
|
-
!
|
|
4703
|
+
!equality.equal(this.variables, query.variables)) {
|
|
4650
4704
|
networkStatus = exports.NetworkStatus.setVariables;
|
|
4651
4705
|
}
|
|
4652
|
-
if (!
|
|
4706
|
+
if (!equality.equal(query.variables, this.variables)) {
|
|
4653
4707
|
this.lastDiff = void 0;
|
|
4654
4708
|
}
|
|
4655
4709
|
Object.assign(this, {
|
|
@@ -4675,7 +4729,7 @@ var QueryInfo = (function () {
|
|
|
4675
4729
|
QueryInfo.prototype.getDiff = function (variables) {
|
|
4676
4730
|
if (variables === void 0) { variables = this.variables; }
|
|
4677
4731
|
var options = this.getDiffOptions(variables);
|
|
4678
|
-
if (this.lastDiff &&
|
|
4732
|
+
if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
|
|
4679
4733
|
return this.lastDiff.diff;
|
|
4680
4734
|
}
|
|
4681
4735
|
this.updateWatch(this.variables = variables);
|
|
@@ -4709,7 +4763,7 @@ var QueryInfo = (function () {
|
|
|
4709
4763
|
var oldDiff = this.lastDiff && this.lastDiff.diff;
|
|
4710
4764
|
this.updateLastDiff(diff);
|
|
4711
4765
|
if (!this.dirty &&
|
|
4712
|
-
!
|
|
4766
|
+
!equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
|
4713
4767
|
this.dirty = true;
|
|
4714
4768
|
if (!this.notifyTimeout) {
|
|
4715
4769
|
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
@@ -4727,11 +4781,12 @@ var QueryInfo = (function () {
|
|
|
4727
4781
|
if (oq) {
|
|
4728
4782
|
oq["queryInfo"] = this;
|
|
4729
4783
|
this.listeners.add(this.oqListener = function () {
|
|
4730
|
-
|
|
4784
|
+
var diff = _this.getDiff();
|
|
4785
|
+
if (diff.fromOptimisticTransaction) {
|
|
4731
4786
|
oq["observe"]();
|
|
4732
4787
|
}
|
|
4733
4788
|
else {
|
|
4734
|
-
oq
|
|
4789
|
+
reobserveCacheFirst(oq);
|
|
4735
4790
|
}
|
|
4736
4791
|
});
|
|
4737
4792
|
}
|
|
@@ -4783,7 +4838,7 @@ var QueryInfo = (function () {
|
|
|
4783
4838
|
}
|
|
4784
4839
|
var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
|
4785
4840
|
if (!this.lastWatch ||
|
|
4786
|
-
!
|
|
4841
|
+
!equality.equal(watchOptions, this.lastWatch)) {
|
|
4787
4842
|
this.cancel();
|
|
4788
4843
|
this.cancel = this.cache.watch(this.lastWatch = watchOptions);
|
|
4789
4844
|
}
|
|
@@ -4795,8 +4850,8 @@ var QueryInfo = (function () {
|
|
|
4795
4850
|
var lastWrite = this.lastWrite;
|
|
4796
4851
|
return !(lastWrite &&
|
|
4797
4852
|
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
4798
|
-
|
|
4799
|
-
|
|
4853
|
+
equality.equal(variables, lastWrite.variables) &&
|
|
4854
|
+
equality.equal(result.data, lastWrite.result.data));
|
|
4800
4855
|
};
|
|
4801
4856
|
QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
|
|
4802
4857
|
var _this = this;
|
|
@@ -5194,9 +5249,9 @@ var QueryManager = (function () {
|
|
|
5194
5249
|
});
|
|
5195
5250
|
this.queries.set(observable.queryId, queryInfo);
|
|
5196
5251
|
queryInfo.init({
|
|
5197
|
-
document:
|
|
5252
|
+
document: observable.query,
|
|
5198
5253
|
observableQuery: observable,
|
|
5199
|
-
variables:
|
|
5254
|
+
variables: observable.variables,
|
|
5200
5255
|
});
|
|
5201
5256
|
return observable;
|
|
5202
5257
|
};
|
|
@@ -5380,8 +5435,10 @@ var QueryManager = (function () {
|
|
|
5380
5435
|
};
|
|
5381
5436
|
QueryManager.prototype.removeQuery = function (queryId) {
|
|
5382
5437
|
this.fetchCancelFns.delete(queryId);
|
|
5383
|
-
this.
|
|
5384
|
-
|
|
5438
|
+
if (this.queries.has(queryId)) {
|
|
5439
|
+
this.getQuery(queryId).stop();
|
|
5440
|
+
this.queries.delete(queryId);
|
|
5441
|
+
}
|
|
5385
5442
|
};
|
|
5386
5443
|
QueryManager.prototype.broadcastQueries = function () {
|
|
5387
5444
|
if (this.onBroadcast)
|
|
@@ -5465,10 +5522,11 @@ var QueryManager = (function () {
|
|
|
5465
5522
|
var aqr = {
|
|
5466
5523
|
data: result.data,
|
|
5467
5524
|
loading: false,
|
|
5468
|
-
networkStatus:
|
|
5525
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
5469
5526
|
};
|
|
5470
5527
|
if (hasErrors && options.errorPolicy !== "ignore") {
|
|
5471
5528
|
aqr.errors = result.errors;
|
|
5529
|
+
aqr.networkStatus = exports.NetworkStatus.error;
|
|
5472
5530
|
}
|
|
5473
5531
|
return aqr;
|
|
5474
5532
|
}, function (networkError) {
|
|
@@ -5510,7 +5568,9 @@ var QueryManager = (function () {
|
|
|
5510
5568
|
: fromVariables(normalized.variables));
|
|
5511
5569
|
concast.cleanup(function () {
|
|
5512
5570
|
_this.fetchCancelFns.delete(queryId);
|
|
5513
|
-
|
|
5571
|
+
if (queryInfo.observableQuery) {
|
|
5572
|
+
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
5573
|
+
}
|
|
5514
5574
|
});
|
|
5515
5575
|
return concast;
|
|
5516
5576
|
};
|
|
@@ -5584,10 +5644,10 @@ var QueryManager = (function () {
|
|
|
5584
5644
|
};
|
|
5585
5645
|
QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a, networkStatus) {
|
|
5586
5646
|
var _this = this;
|
|
5587
|
-
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;
|
|
5588
5648
|
var oldNetworkStatus = queryInfo.networkStatus;
|
|
5589
5649
|
queryInfo.init({
|
|
5590
|
-
document: query,
|
|
5650
|
+
document: this.transform(query).document,
|
|
5591
5651
|
variables: variables,
|
|
5592
5652
|
networkStatus: networkStatus,
|
|
5593
5653
|
});
|
|
@@ -5597,7 +5657,7 @@ var QueryManager = (function () {
|
|
|
5597
5657
|
var data = diff.result;
|
|
5598
5658
|
if (__DEV__ &&
|
|
5599
5659
|
!returnPartialData &&
|
|
5600
|
-
!
|
|
5660
|
+
!equality.equal(data, {})) {
|
|
5601
5661
|
logMissingFieldErrors(diff.missing);
|
|
5602
5662
|
}
|
|
5603
5663
|
var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
@@ -5617,12 +5677,26 @@ var QueryManager = (function () {
|
|
|
5617
5677
|
refetchWritePolicy !== "merge") ? 1
|
|
5618
5678
|
: 2;
|
|
5619
5679
|
var resultsFromLink = function () {
|
|
5620
|
-
return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
5680
|
+
var get = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
5621
5681
|
variables: variables,
|
|
5622
5682
|
context: context,
|
|
5623
5683
|
fetchPolicy: fetchPolicy,
|
|
5624
5684
|
errorPolicy: errorPolicy,
|
|
5625
|
-
});
|
|
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();
|
|
5626
5700
|
};
|
|
5627
5701
|
var shouldNotify = notifyOnNetworkStatusChange &&
|
|
5628
5702
|
typeof oldNetworkStatus === "number" &&
|
|
@@ -5698,11 +5772,6 @@ var QueryManager = (function () {
|
|
|
5698
5772
|
}());
|
|
5699
5773
|
|
|
5700
5774
|
var hasSuggestedDevtools = false;
|
|
5701
|
-
function mergeOptions(defaults, options) {
|
|
5702
|
-
return compact(defaults, options, options.variables && {
|
|
5703
|
-
variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
|
|
5704
|
-
});
|
|
5705
|
-
}
|
|
5706
5775
|
var ApolloClient = (function () {
|
|
5707
5776
|
function ApolloClient(options) {
|
|
5708
5777
|
var _this = this;
|
|
@@ -6060,26 +6129,9 @@ function verifyDocumentType(document, type) {
|
|
|
6060
6129
|
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
|
|
6061
6130
|
}
|
|
6062
6131
|
|
|
6063
|
-
function useNormalizedOptions(optionsOrFunction) {
|
|
6064
|
-
var optionsRef = React.useRef();
|
|
6065
|
-
var options = optionsRef.current || Object.create(null);
|
|
6066
|
-
if (typeof optionsOrFunction === "function") {
|
|
6067
|
-
var newOptions = optionsOrFunction(options);
|
|
6068
|
-
if (newOptions !== options) {
|
|
6069
|
-
Object.assign(options, newOptions, newOptions.variables && {
|
|
6070
|
-
variables: tslib.__assign(tslib.__assign({}, options.variables), newOptions.variables),
|
|
6071
|
-
});
|
|
6072
|
-
}
|
|
6073
|
-
}
|
|
6074
|
-
else if (optionsOrFunction && !equal__default(optionsOrFunction, options)) {
|
|
6075
|
-
options = optionsOrFunction;
|
|
6076
|
-
}
|
|
6077
|
-
return optionsRef.current = options;
|
|
6078
|
-
}
|
|
6079
|
-
|
|
6080
6132
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
6081
|
-
function useQuery(query,
|
|
6082
|
-
|
|
6133
|
+
function useQuery(query, options) {
|
|
6134
|
+
if (options === void 0) { options = Object.create(null); }
|
|
6083
6135
|
return useInternalState(useApolloClient(options.client), query).useQuery(options);
|
|
6084
6136
|
}
|
|
6085
6137
|
function useInternalState(client, query) {
|
|
@@ -6100,118 +6152,31 @@ var InternalState = (function () {
|
|
|
6100
6152
|
function InternalState(client, query) {
|
|
6101
6153
|
this.client = client;
|
|
6102
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
|
+
});
|
|
6103
6167
|
this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
|
|
6104
6168
|
verifyDocumentType(query, exports.DocumentType.Query);
|
|
6105
6169
|
}
|
|
6106
6170
|
InternalState.prototype.forceUpdate = function () {
|
|
6107
6171
|
};
|
|
6108
6172
|
InternalState.prototype.useQuery = function (options) {
|
|
6173
|
+
var _this = this;
|
|
6174
|
+
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6109
6175
|
this.useOptions(options);
|
|
6110
6176
|
var obsQuery = this.useObservableQuery();
|
|
6111
|
-
|
|
6112
|
-
var result = this.getCurrentResult();
|
|
6113
|
-
this.unsafeHandlePartialRefetch(result);
|
|
6114
|
-
return this.toQueryResult(result);
|
|
6115
|
-
};
|
|
6116
|
-
InternalState.prototype.useOptions = function (options) {
|
|
6117
|
-
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6118
|
-
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6119
|
-
if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
|
|
6120
|
-
this.watchQueryOptions = watchQueryOptions;
|
|
6121
|
-
}
|
|
6122
|
-
this.ssrDisabled = !!(options && (options.ssr === false ||
|
|
6123
|
-
options.skip));
|
|
6124
|
-
this.onCompleted = options
|
|
6125
|
-
&& options.onCompleted
|
|
6126
|
-
|| InternalState.prototype.onCompleted;
|
|
6127
|
-
this.onError = options
|
|
6128
|
-
&& options.onError
|
|
6129
|
-
|| InternalState.prototype.onError;
|
|
6130
|
-
};
|
|
6131
|
-
InternalState.prototype.createWatchQueryOptions = function (_a) {
|
|
6132
|
-
var _b;
|
|
6133
|
-
if (_a === void 0) { _a = {}; }
|
|
6134
|
-
var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
|
|
6135
|
-
var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
|
|
6136
|
-
if (skip) {
|
|
6137
|
-
watchQueryOptions.fetchPolicy = 'standby';
|
|
6138
|
-
}
|
|
6139
|
-
else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
|
|
6140
|
-
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
6141
|
-
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
6142
|
-
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6143
|
-
}
|
|
6144
|
-
else if (!watchQueryOptions.fetchPolicy) {
|
|
6145
|
-
var defaultOptions = this.client.defaultOptions.watchQuery;
|
|
6146
|
-
watchQueryOptions.fetchPolicy =
|
|
6147
|
-
defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
|
|
6148
|
-
}
|
|
6149
|
-
if (!watchQueryOptions.variables) {
|
|
6150
|
-
watchQueryOptions.variables = {};
|
|
6151
|
-
}
|
|
6152
|
-
return watchQueryOptions;
|
|
6153
|
-
};
|
|
6154
|
-
InternalState.prototype.onCompleted = function (data) { };
|
|
6155
|
-
InternalState.prototype.onError = function (error) { };
|
|
6156
|
-
InternalState.prototype.useObservableQuery = function () {
|
|
6157
|
-
var _this = this;
|
|
6158
|
-
var obsQuery = this.observable =
|
|
6159
|
-
this.renderPromises
|
|
6160
|
-
&& this.renderPromises.getSSRObservable(this.watchQueryOptions)
|
|
6161
|
-
|| this.observable
|
|
6162
|
-
|| this.client.watchQuery(this.watchQueryOptions);
|
|
6163
|
-
this.obsQueryFields = React.useMemo(function () { return ({
|
|
6164
|
-
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6165
|
-
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
6166
|
-
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
6167
|
-
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
6168
|
-
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6169
|
-
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6170
|
-
}); }, [obsQuery]);
|
|
6171
|
-
if (this.renderPromises) {
|
|
6172
|
-
this.renderPromises.registerSSRObservable(obsQuery);
|
|
6173
|
-
if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
|
|
6174
|
-
this.renderPromises.addQueryPromise({
|
|
6175
|
-
getOptions: function () { return obsQuery.options; },
|
|
6176
|
-
fetchData: function () { return new Promise(function (resolve) {
|
|
6177
|
-
var sub = obsQuery.subscribe({
|
|
6178
|
-
next: function (result) {
|
|
6179
|
-
if (!result.loading) {
|
|
6180
|
-
resolve();
|
|
6181
|
-
sub.unsubscribe();
|
|
6182
|
-
}
|
|
6183
|
-
},
|
|
6184
|
-
error: function () {
|
|
6185
|
-
resolve();
|
|
6186
|
-
sub.unsubscribe();
|
|
6187
|
-
},
|
|
6188
|
-
complete: function () {
|
|
6189
|
-
resolve();
|
|
6190
|
-
},
|
|
6191
|
-
});
|
|
6192
|
-
}); },
|
|
6193
|
-
}, function () { return null; });
|
|
6194
|
-
obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
|
|
6195
|
-
}
|
|
6196
|
-
}
|
|
6197
|
-
var prevOptionsRef = React.useRef({
|
|
6198
|
-
watchQueryOptions: this.watchQueryOptions,
|
|
6199
|
-
});
|
|
6200
|
-
React.useEffect(function () {
|
|
6201
|
-
if (_this.renderPromises) ;
|
|
6202
|
-
else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
|
|
6203
|
-
obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
|
|
6204
|
-
prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
|
|
6205
|
-
_this.setResult(obsQuery.getCurrentResult());
|
|
6206
|
-
}
|
|
6207
|
-
}, [obsQuery, this.watchQueryOptions]);
|
|
6208
|
-
return obsQuery;
|
|
6209
|
-
};
|
|
6210
|
-
InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
|
|
6211
|
-
var _this = this;
|
|
6212
|
-
React.useEffect(function () {
|
|
6177
|
+
var result = index_js.useSyncExternalStore(React.useCallback(function () {
|
|
6213
6178
|
if (_this.renderPromises) {
|
|
6214
|
-
return;
|
|
6179
|
+
return function () { };
|
|
6215
6180
|
}
|
|
6216
6181
|
var onNext = function () {
|
|
6217
6182
|
var previousResult = _this.result;
|
|
@@ -6219,7 +6184,7 @@ var InternalState = (function () {
|
|
|
6219
6184
|
if (previousResult &&
|
|
6220
6185
|
previousResult.loading === result.loading &&
|
|
6221
6186
|
previousResult.networkStatus === result.networkStatus &&
|
|
6222
|
-
|
|
6187
|
+
equality.equal(previousResult.data, result.data)) {
|
|
6223
6188
|
return;
|
|
6224
6189
|
}
|
|
6225
6190
|
_this.setResult(result);
|
|
@@ -6240,7 +6205,7 @@ var InternalState = (function () {
|
|
|
6240
6205
|
var previousResult = _this.result;
|
|
6241
6206
|
if (!previousResult ||
|
|
6242
6207
|
(previousResult && previousResult.loading) ||
|
|
6243
|
-
!
|
|
6208
|
+
!equality.equal(error, previousResult.error)) {
|
|
6244
6209
|
_this.setResult({
|
|
6245
6210
|
data: (previousResult && previousResult.data),
|
|
6246
6211
|
error: error,
|
|
@@ -6255,7 +6220,117 @@ var InternalState = (function () {
|
|
|
6255
6220
|
obsQuery,
|
|
6256
6221
|
this.renderPromises,
|
|
6257
6222
|
this.client.disableNetworkFetches,
|
|
6258
|
-
]);
|
|
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;
|
|
6259
6334
|
};
|
|
6260
6335
|
InternalState.prototype.setResult = function (nextResult) {
|
|
6261
6336
|
var previousResult = this.result;
|
|
@@ -6277,30 +6352,10 @@ var InternalState = (function () {
|
|
|
6277
6352
|
}
|
|
6278
6353
|
};
|
|
6279
6354
|
InternalState.prototype.getCurrentResult = function () {
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
result = this.result = this.observable.getCurrentResult();
|
|
6283
|
-
this.handleErrorOrCompleted(result);
|
|
6284
|
-
}
|
|
6285
|
-
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
6286
|
-
this.queryHookOptions.ssr === false) {
|
|
6287
|
-
result = {
|
|
6288
|
-
loading: true,
|
|
6289
|
-
data: void 0,
|
|
6290
|
-
error: void 0,
|
|
6291
|
-
networkStatus: exports.NetworkStatus.loading,
|
|
6292
|
-
};
|
|
6355
|
+
if (!this.result) {
|
|
6356
|
+
this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
|
|
6293
6357
|
}
|
|
6294
|
-
|
|
6295
|
-
this.queryHookOptions.fetchPolicy === 'standby') {
|
|
6296
|
-
result = {
|
|
6297
|
-
loading: false,
|
|
6298
|
-
data: void 0,
|
|
6299
|
-
error: void 0,
|
|
6300
|
-
networkStatus: exports.NetworkStatus.ready,
|
|
6301
|
-
};
|
|
6302
|
-
}
|
|
6303
|
-
return result;
|
|
6358
|
+
return this.result;
|
|
6304
6359
|
};
|
|
6305
6360
|
InternalState.prototype.toQueryResult = function (result) {
|
|
6306
6361
|
var queryResult = this.toQueryResultCache.get(result);
|
|
@@ -6328,34 +6383,52 @@ var InternalState = (function () {
|
|
|
6328
6383
|
};
|
|
6329
6384
|
return InternalState;
|
|
6330
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
|
+
}
|
|
6331
6401
|
|
|
6332
6402
|
var EAGER_METHODS = [
|
|
6333
6403
|
'refetch',
|
|
6404
|
+
'reobserve',
|
|
6334
6405
|
'fetchMore',
|
|
6335
6406
|
'updateQuery',
|
|
6336
6407
|
'startPolling',
|
|
6337
6408
|
'subscribeToMore',
|
|
6338
6409
|
];
|
|
6339
|
-
function useLazyQuery(query,
|
|
6340
|
-
var
|
|
6341
|
-
var
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
}
|
|
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
|
+
});
|
|
6348
6422
|
var eagerMethods = React.useMemo(function () {
|
|
6349
6423
|
var eagerMethods = {};
|
|
6350
6424
|
var _loop_1 = function (key) {
|
|
6351
6425
|
var method = result[key];
|
|
6352
6426
|
eagerMethods[key] = function () {
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6427
|
+
if (!execOptionsRef.current) {
|
|
6428
|
+
execOptionsRef.current = Object.create(null);
|
|
6429
|
+
internalState.forceUpdate();
|
|
6356
6430
|
}
|
|
6357
|
-
|
|
6358
|
-
return method.apply(void 0, args);
|
|
6431
|
+
return method.apply(this, arguments);
|
|
6359
6432
|
};
|
|
6360
6433
|
};
|
|
6361
6434
|
for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
|
|
@@ -6364,15 +6437,24 @@ function useLazyQuery(query, optionsOrFunction) {
|
|
|
6364
6437
|
}
|
|
6365
6438
|
return eagerMethods;
|
|
6366
6439
|
}, []);
|
|
6367
|
-
result.error = result.error || void 0;
|
|
6368
6440
|
Object.assign(result, eagerMethods);
|
|
6369
6441
|
var execute = React.useCallback(function (executeOptions) {
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
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();
|
|
6376
6458
|
promise.catch(function () { });
|
|
6377
6459
|
return promise;
|
|
6378
6460
|
}, []);
|
|
@@ -6428,7 +6510,7 @@ function useMutation(mutation, options) {
|
|
|
6428
6510
|
error: error,
|
|
6429
6511
|
client: client,
|
|
6430
6512
|
};
|
|
6431
|
-
if (ref.current.isMounted && !
|
|
6513
|
+
if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
|
|
6432
6514
|
setResult(ref.current.result = result_1);
|
|
6433
6515
|
}
|
|
6434
6516
|
}
|
|
@@ -6446,7 +6528,7 @@ function useMutation(mutation, options) {
|
|
|
6446
6528
|
called: true,
|
|
6447
6529
|
client: client,
|
|
6448
6530
|
};
|
|
6449
|
-
if (!
|
|
6531
|
+
if (!equality.equal(ref.current.result, result_2)) {
|
|
6450
6532
|
setResult(ref.current.result = result_2);
|
|
6451
6533
|
}
|
|
6452
6534
|
}
|
|
@@ -6509,7 +6591,7 @@ function useSubscription(subscription, options) {
|
|
|
6509
6591
|
subscription !== ref.current.subscription ||
|
|
6510
6592
|
(options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
|
|
6511
6593
|
!(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
|
|
6512
|
-
!
|
|
6594
|
+
!equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
|
|
6513
6595
|
setResult({
|
|
6514
6596
|
loading: true,
|
|
6515
6597
|
data: void 0,
|
|
@@ -6596,7 +6678,6 @@ exports.HttpLink = HttpLink;
|
|
|
6596
6678
|
exports.InMemoryCache = InMemoryCache;
|
|
6597
6679
|
exports.MissingFieldError = MissingFieldError;
|
|
6598
6680
|
exports.ObservableQuery = ObservableQuery;
|
|
6599
|
-
exports.applyNextFetchPolicy = applyNextFetchPolicy;
|
|
6600
6681
|
exports.checkFetcher = checkFetcher;
|
|
6601
6682
|
exports.concat = concat;
|
|
6602
6683
|
exports.createHttpLink = createHttpLink;
|