@apollo/client 3.8.0-alpha.10 → 3.8.0-alpha.11
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 +248 -235
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +2 -0
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +2 -0
- package/cache/core/cache.d.ts +1 -0
- package/cache/core/cache.d.ts.map +1 -1
- package/cache/core/cache.js +1 -0
- package/cache/core/cache.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +1 -0
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +1 -0
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/core/ApolloClient.js +6 -6
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +1 -2
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +4 -8
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +2 -2
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +13 -17
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +13 -17
- package/core/networkStatus.d.ts +1 -0
- package/core/networkStatus.d.ts.map +1 -1
- package/core/networkStatus.js +3 -0
- package/core/networkStatus.js.map +1 -1
- package/core/types.d.ts +3 -0
- package/core/types.d.ts.map +1 -1
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +0 -1
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +35 -30
- package/package.json +2 -2
- package/react/cache/QuerySubscription.d.ts +26 -0
- package/react/cache/QuerySubscription.d.ts.map +1 -0
- package/react/cache/QuerySubscription.js +88 -0
- package/react/cache/QuerySubscription.js.map +1 -0
- package/react/cache/SuspenseCache.d.ts +9 -13
- package/react/cache/SuspenseCache.d.ts.map +1 -1
- package/react/cache/SuspenseCache.js +17 -40
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +2 -2
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +2 -2
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +2 -2
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -2
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +111 -155
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +111 -155
- package/react/hooks/internal/__use.d.ts +2 -0
- package/react/hooks/internal/__use.d.ts.map +1 -0
- package/react/hooks/internal/__use.js +13 -0
- package/react/hooks/internal/__use.js.map +1 -0
- package/react/hooks/internal/index.d.ts +2 -0
- package/react/hooks/internal/index.d.ts.map +1 -1
- package/react/hooks/internal/index.js +2 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.js +2 -2
- package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
- package/react/hooks/internal/useStrictModeSafeCleanupEffect.d.ts +2 -0
- package/react/hooks/internal/useStrictModeSafeCleanupEffect.d.ts.map +1 -0
- package/react/hooks/internal/useStrictModeSafeCleanupEffect.js +11 -0
- package/react/hooks/internal/useStrictModeSafeCleanupEffect.js.map +1 -0
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useSuspenseCache.js +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +7 -2
- package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
- package/react/hooks/useSuspenseQuery.js +66 -153
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/parser/index.js +5 -5
- package/react/parser/parser.cjs +5 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +5 -5
- package/react/react.cjs +112 -38
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +112 -38
- package/react/types/types.d.ts +0 -2
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +1 -1
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +1 -1
- package/testing/core/mocking/mockLink.js +1 -1
- package/testing/testing.cjs +110 -38
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +110 -38
- package/utilities/common/mergeOptions.js +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/graphql/directives.js +4 -4
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/promises/decoration.d.ts +15 -0
- package/utilities/promises/decoration.d.ts.map +1 -0
- package/utilities/promises/decoration.js +25 -0
- package/utilities/promises/decoration.js.map +1 -0
- package/utilities/utilities.cjs +17 -17
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +17 -17
- package/version.js +1 -1
- package/cache/inmemory/__mocks__/optimism.d.ts +0 -2
- package/cache/inmemory/__mocks__/optimism.d.ts.map +0 -1
- package/cache/inmemory/__mocks__/optimism.js +0 -14
- package/cache/inmemory/__mocks__/optimism.js.map +0 -1
package/apollo-client.cjs
CHANGED
|
@@ -63,7 +63,7 @@ function shouldInclude(_a, variables) {
|
|
|
63
63
|
var evaledValue = false;
|
|
64
64
|
if (ifArgument.value.kind === 'Variable') {
|
|
65
65
|
evaledValue = variables && variables[ifArgument.value.name.value];
|
|
66
|
-
__DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0,
|
|
66
|
+
__DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 42);
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
69
|
evaledValue = ifArgument.value.value;
|
|
@@ -71,6 +71,7 @@ function shouldInclude(_a, variables) {
|
|
|
71
71
|
return directive.name.value === 'skip' ? !evaledValue : evaledValue;
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
+
var hasAnyDirectives = function (names, root) { return hasDirectives(names, root, false); };
|
|
74
75
|
function hasDirectives(names, root, all) {
|
|
75
76
|
var nameSet = new Set(names);
|
|
76
77
|
var uniqueCount = nameSet.size;
|
|
@@ -99,13 +100,13 @@ function getInclusionDirectives(directives) {
|
|
|
99
100
|
return;
|
|
100
101
|
var directiveArguments = directive.arguments;
|
|
101
102
|
var directiveName = directive.name.value;
|
|
102
|
-
__DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1,
|
|
103
|
+
__DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 43);
|
|
103
104
|
var ifArgument = directiveArguments[0];
|
|
104
|
-
__DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if',
|
|
105
|
+
__DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 44);
|
|
105
106
|
var ifValue = ifArgument.value;
|
|
106
107
|
__DEV__ ? tsInvariant.invariant(ifValue &&
|
|
107
108
|
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
|
|
108
|
-
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'),
|
|
109
|
+
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 45);
|
|
109
110
|
result.push({ directive: directive, ifArgument: ifArgument });
|
|
110
111
|
});
|
|
111
112
|
}
|
|
@@ -118,14 +119,14 @@ function getFragmentQueryDocument(document, fragmentName) {
|
|
|
118
119
|
document.definitions.forEach(function (definition) {
|
|
119
120
|
if (definition.kind === 'OperationDefinition') {
|
|
120
121
|
throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
|
|
121
|
-
'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(
|
|
122
|
+
'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(46);
|
|
122
123
|
}
|
|
123
124
|
if (definition.kind === 'FragmentDefinition') {
|
|
124
125
|
fragments.push(definition);
|
|
125
126
|
}
|
|
126
127
|
});
|
|
127
128
|
if (typeof actualFragmentName === 'undefined') {
|
|
128
|
-
__DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : tsInvariant.invariant(fragments.length === 1,
|
|
129
|
+
__DEV__ ? tsInvariant.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : tsInvariant.invariant(fragments.length === 1, 47);
|
|
129
130
|
actualFragmentName = fragments[0].name.value;
|
|
130
131
|
}
|
|
131
132
|
var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
|
|
@@ -166,7 +167,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
|
|
|
166
167
|
return fragmentMap(fragmentName);
|
|
167
168
|
}
|
|
168
169
|
var fragment = fragmentMap && fragmentMap[fragmentName];
|
|
169
|
-
__DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment,
|
|
170
|
+
__DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 48);
|
|
170
171
|
return fragment || null;
|
|
171
172
|
}
|
|
172
173
|
default:
|
|
@@ -250,7 +251,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
|
|
|
250
251
|
else {
|
|
251
252
|
throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
|
|
252
253
|
'is not supported. Use variables instead of inline arguments to ' +
|
|
253
|
-
'overcome this limitation.') : new tsInvariant.InvariantError(
|
|
254
|
+
'overcome this limitation.') : new tsInvariant.InvariantError(57);
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
257
|
function storeKeyNameFromField(field, variables) {
|
|
@@ -384,16 +385,16 @@ function isInlineFragment(selection) {
|
|
|
384
385
|
}
|
|
385
386
|
|
|
386
387
|
function checkDocument(doc) {
|
|
387
|
-
__DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document',
|
|
388
|
+
__DEV__ ? tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc && doc.kind === 'Document', 49);
|
|
388
389
|
var operations = doc.definitions
|
|
389
390
|
.filter(function (d) { return d.kind !== 'FragmentDefinition'; })
|
|
390
391
|
.map(function (definition) {
|
|
391
392
|
if (definition.kind !== 'OperationDefinition') {
|
|
392
|
-
throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(
|
|
393
|
+
throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(50);
|
|
393
394
|
}
|
|
394
395
|
return definition;
|
|
395
396
|
});
|
|
396
|
-
__DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1,
|
|
397
|
+
__DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 51);
|
|
397
398
|
return doc;
|
|
398
399
|
}
|
|
399
400
|
function getOperationDefinition(doc) {
|
|
@@ -416,14 +417,14 @@ function getFragmentDefinitions(doc) {
|
|
|
416
417
|
}
|
|
417
418
|
function getQueryDefinition(doc) {
|
|
418
419
|
var queryDef = getOperationDefinition(doc);
|
|
419
|
-
__DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query',
|
|
420
|
+
__DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 52);
|
|
420
421
|
return queryDef;
|
|
421
422
|
}
|
|
422
423
|
function getFragmentDefinition(doc) {
|
|
423
|
-
__DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document',
|
|
424
|
-
__DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1,
|
|
424
|
+
__DEV__ ? tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : tsInvariant.invariant(doc.kind === 'Document', 53);
|
|
425
|
+
__DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 54);
|
|
425
426
|
var fragmentDef = doc.definitions[0];
|
|
426
|
-
__DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition',
|
|
427
|
+
__DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 55);
|
|
427
428
|
return fragmentDef;
|
|
428
429
|
}
|
|
429
430
|
function getMainDefinition(queryDoc) {
|
|
@@ -446,7 +447,7 @@ function getMainDefinition(queryDoc) {
|
|
|
446
447
|
if (fragmentDefinition) {
|
|
447
448
|
return fragmentDefinition;
|
|
448
449
|
}
|
|
449
|
-
throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(
|
|
450
|
+
throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(56);
|
|
450
451
|
}
|
|
451
452
|
function getDefaultValues(definition) {
|
|
452
453
|
var defaultValues = Object.create(null);
|
|
@@ -1167,7 +1168,7 @@ function stringifyForDisplay(value) {
|
|
|
1167
1168
|
|
|
1168
1169
|
function mergeOptions(defaults, options) {
|
|
1169
1170
|
return compact(defaults, options, options.variables && {
|
|
1170
|
-
variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
|
|
1171
|
+
variables: compact(tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables)),
|
|
1171
1172
|
});
|
|
1172
1173
|
}
|
|
1173
1174
|
|
|
@@ -1395,7 +1396,7 @@ var concat = ApolloLink.concat;
|
|
|
1395
1396
|
|
|
1396
1397
|
var execute = ApolloLink.execute;
|
|
1397
1398
|
|
|
1398
|
-
var version = '3.8.0-alpha.
|
|
1399
|
+
var version = '3.8.0-alpha.11';
|
|
1399
1400
|
|
|
1400
1401
|
function asyncIterator(source) {
|
|
1401
1402
|
var _a;
|
|
@@ -1968,6 +1969,7 @@ var HttpLink = (function (_super) {
|
|
|
1968
1969
|
|
|
1969
1970
|
var ApolloCache = (function () {
|
|
1970
1971
|
function ApolloCache() {
|
|
1972
|
+
this.assumeImmutableResults = false;
|
|
1971
1973
|
this.getFragmentDoc = optimism.wrap(getFragmentQueryDocument);
|
|
1972
1974
|
}
|
|
1973
1975
|
ApolloCache.prototype.batch = function (options) {
|
|
@@ -3973,6 +3975,7 @@ var InMemoryCache = (function (_super) {
|
|
|
3973
3975
|
var _this = _super.call(this) || this;
|
|
3974
3976
|
_this.watches = new Set();
|
|
3975
3977
|
_this.typenameDocumentCache = new Map();
|
|
3978
|
+
_this.assumeImmutableResults = true;
|
|
3976
3979
|
_this.makeVar = makeVar;
|
|
3977
3980
|
_this.txCount = 0;
|
|
3978
3981
|
_this.config = normalizeConfig(config);
|
|
@@ -4317,6 +4320,9 @@ exports.NetworkStatus = void 0;
|
|
|
4317
4320
|
function isNetworkRequestInFlight(networkStatus) {
|
|
4318
4321
|
return networkStatus ? networkStatus < 7 : false;
|
|
4319
4322
|
}
|
|
4323
|
+
function isNetworkRequestSettled(networkStatus) {
|
|
4324
|
+
return networkStatus === 7 || networkStatus === 8;
|
|
4325
|
+
}
|
|
4320
4326
|
|
|
4321
4327
|
var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
|
|
4322
4328
|
var ObservableQuery = (function (_super) {
|
|
@@ -4324,14 +4330,13 @@ var ObservableQuery = (function (_super) {
|
|
|
4324
4330
|
function ObservableQuery(_a) {
|
|
4325
4331
|
var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
|
|
4326
4332
|
var _this = _super.call(this, function (observer) {
|
|
4327
|
-
var _a = options.fetchOnFirstSubscribe, fetchOnFirstSubscribe = _a === void 0 ? true : _a;
|
|
4328
4333
|
try {
|
|
4329
4334
|
var subObserver = observer._subscription._observer;
|
|
4330
4335
|
if (subObserver && !subObserver.error) {
|
|
4331
4336
|
subObserver.error = defaultSubscriptionObserverErrorCallback;
|
|
4332
4337
|
}
|
|
4333
4338
|
}
|
|
4334
|
-
catch (
|
|
4339
|
+
catch (_a) { }
|
|
4335
4340
|
var first = !_this.observers.size;
|
|
4336
4341
|
_this.observers.add(observer);
|
|
4337
4342
|
var last = _this.last;
|
|
@@ -4341,7 +4346,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4341
4346
|
else if (last && last.result) {
|
|
4342
4347
|
observer.next && observer.next(last.result);
|
|
4343
4348
|
}
|
|
4344
|
-
if (first
|
|
4349
|
+
if (first) {
|
|
4345
4350
|
_this.reobserve().catch(function () { });
|
|
4346
4351
|
}
|
|
4347
4352
|
return function () {
|
|
@@ -4704,7 +4709,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4704
4709
|
}
|
|
4705
4710
|
return this.last;
|
|
4706
4711
|
};
|
|
4707
|
-
ObservableQuery.prototype.
|
|
4712
|
+
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
4708
4713
|
var _this = this;
|
|
4709
4714
|
this.isTornDown = false;
|
|
4710
4715
|
var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
|
|
@@ -4747,10 +4752,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4747
4752
|
this.observer = observer;
|
|
4748
4753
|
}
|
|
4749
4754
|
concast.addObserver(observer);
|
|
4750
|
-
return concast;
|
|
4751
|
-
};
|
|
4752
|
-
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
4753
|
-
return this.reobserveAsConcast(newOptions, newNetworkStatus).promise;
|
|
4755
|
+
return concast.promise;
|
|
4754
4756
|
};
|
|
4755
4757
|
ObservableQuery.prototype.observe = function () {
|
|
4756
4758
|
this.reportResult(this.getCurrentResult(false), this.variables);
|
|
@@ -5412,7 +5414,7 @@ function shouldWriteResult(result, errorPolicy) {
|
|
|
5412
5414
|
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
5413
5415
|
var QueryManager = (function () {
|
|
5414
5416
|
function QueryManager(_a) {
|
|
5415
|
-
var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState,
|
|
5417
|
+
var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e;
|
|
5416
5418
|
this.clientAwareness = {};
|
|
5417
5419
|
this.queries = new Map();
|
|
5418
5420
|
this.fetchCancelFns = new Map();
|
|
@@ -5428,7 +5430,7 @@ var QueryManager = (function () {
|
|
|
5428
5430
|
this.clientAwareness = clientAwareness;
|
|
5429
5431
|
this.localState = localState || new LocalState({ cache: cache });
|
|
5430
5432
|
this.ssrMode = ssrMode;
|
|
5431
|
-
this.assumeImmutableResults =
|
|
5433
|
+
this.assumeImmutableResults = assumeImmutableResults;
|
|
5432
5434
|
if ((this.onBroadcast = onBroadcast)) {
|
|
5433
5435
|
this.mutationStore = Object.create(null);
|
|
5434
5436
|
}
|
|
@@ -6291,20 +6293,20 @@ var ApolloClient = (function () {
|
|
|
6291
6293
|
var _this = this;
|
|
6292
6294
|
this.resetStoreCallbacks = [];
|
|
6293
6295
|
this.clearStoreCallbacks = [];
|
|
6296
|
+
if (!options.cache) {
|
|
6297
|
+
throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
|
|
6298
|
+
"in the options object. \n" +
|
|
6299
|
+
"For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
|
|
6300
|
+
}
|
|
6294
6301
|
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
|
|
6295
6302
|
!window.__APOLLO_CLIENT__ &&
|
|
6296
|
-
__DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ?
|
|
6303
|
+
__DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
|
|
6297
6304
|
var link = options.link;
|
|
6298
6305
|
if (!link) {
|
|
6299
6306
|
link = uri
|
|
6300
6307
|
? new HttpLink({ uri: uri, credentials: credentials, headers: headers })
|
|
6301
6308
|
: ApolloLink.empty();
|
|
6302
6309
|
}
|
|
6303
|
-
if (!cache) {
|
|
6304
|
-
throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
|
|
6305
|
-
"in the options object. \n" +
|
|
6306
|
-
"For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
|
|
6307
|
-
}
|
|
6308
6310
|
this.link = link;
|
|
6309
6311
|
this.cache = cache;
|
|
6310
6312
|
this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
|
|
@@ -6542,7 +6544,7 @@ var ApolloConsumer = function (props) {
|
|
|
6542
6544
|
var ApolloContext = getApolloContext();
|
|
6543
6545
|
return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
|
|
6544
6546
|
__DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
|
|
6545
|
-
'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client,
|
|
6547
|
+
'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 29);
|
|
6546
6548
|
return props.children(context.client);
|
|
6547
6549
|
}));
|
|
6548
6550
|
};
|
|
@@ -6559,7 +6561,7 @@ var ApolloProvider = function (_a) {
|
|
|
6559
6561
|
context = Object.assign({}, context, { suspenseCache: suspenseCache });
|
|
6560
6562
|
}
|
|
6561
6563
|
__DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
|
|
6562
|
-
'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client,
|
|
6564
|
+
'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 30);
|
|
6563
6565
|
return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
|
|
6564
6566
|
}));
|
|
6565
6567
|
};
|
|
@@ -6569,7 +6571,7 @@ function useApolloClient(override) {
|
|
|
6569
6571
|
var client = override || context.client;
|
|
6570
6572
|
__DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
|
|
6571
6573
|
'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
|
|
6572
|
-
'instance in via options.') : tsInvariant.invariant(!!client,
|
|
6574
|
+
'instance in via options.') : tsInvariant.invariant(!!client, 33);
|
|
6573
6575
|
return client;
|
|
6574
6576
|
}
|
|
6575
6577
|
|
|
@@ -6647,7 +6649,7 @@ function parser(document) {
|
|
|
6647
6649
|
var variables, type, name;
|
|
6648
6650
|
__DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
|
|
6649
6651
|
"DocumentNode. You may need to use 'graphql-tag' or another method " +
|
|
6650
|
-
"to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind,
|
|
6652
|
+
"to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 36);
|
|
6651
6653
|
var fragments = [];
|
|
6652
6654
|
var queries = [];
|
|
6653
6655
|
var mutations = [];
|
|
@@ -6675,11 +6677,11 @@ function parser(document) {
|
|
|
6675
6677
|
__DEV__ ? tsInvariant.invariant(!fragments.length ||
|
|
6676
6678
|
(queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
|
|
6677
6679
|
"You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
|
|
6678
|
-
(queries.length || mutations.length || subscriptions.length),
|
|
6680
|
+
(queries.length || mutations.length || subscriptions.length), 37);
|
|
6679
6681
|
__DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
|
|
6680
6682
|
"".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
|
|
6681
6683
|
"subscriptions and ".concat(mutations.length, " mutations. ") +
|
|
6682
|
-
"You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1,
|
|
6684
|
+
"You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 38);
|
|
6683
6685
|
type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
|
|
6684
6686
|
if (!queries.length && !mutations.length)
|
|
6685
6687
|
type = exports.DocumentType.Subscription;
|
|
@@ -6690,7 +6692,7 @@ function parser(document) {
|
|
|
6690
6692
|
: subscriptions;
|
|
6691
6693
|
__DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
|
|
6692
6694
|
"".concat(definitions.length, " definitions. ") +
|
|
6693
|
-
"You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1,
|
|
6695
|
+
"You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 39);
|
|
6694
6696
|
var definition = definitions[0];
|
|
6695
6697
|
variables = definition.variableDefinitions || [];
|
|
6696
6698
|
if (definition.name && definition.name.kind === 'Name') {
|
|
@@ -6708,7 +6710,7 @@ function verifyDocumentType(document, type) {
|
|
|
6708
6710
|
var requiredOperationName = operationName(type);
|
|
6709
6711
|
var usedOperationName = operationName(operation.type);
|
|
6710
6712
|
__DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
|
|
6711
|
-
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type,
|
|
6713
|
+
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 40);
|
|
6712
6714
|
}
|
|
6713
6715
|
|
|
6714
6716
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
@@ -7353,124 +7355,123 @@ function useDeepMemo(memoFn, deps) {
|
|
|
7353
7355
|
return ref.current.value;
|
|
7354
7356
|
}
|
|
7355
7357
|
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7358
|
+
function useStrictModeSafeCleanupEffect(cleanup) {
|
|
7359
|
+
var timeout;
|
|
7360
|
+
React.useEffect(function () {
|
|
7361
|
+
clearTimeout(timeout);
|
|
7362
|
+
return function () {
|
|
7363
|
+
timeout = setTimeout(cleanup);
|
|
7364
|
+
};
|
|
7365
|
+
}, []);
|
|
7366
|
+
}
|
|
7367
|
+
|
|
7368
|
+
function isStatefulPromise(promise) {
|
|
7369
|
+
return 'status' in promise;
|
|
7370
|
+
}
|
|
7371
|
+
function wrapPromiseWithState(promise) {
|
|
7372
|
+
if (isStatefulPromise(promise)) {
|
|
7373
|
+
return promise;
|
|
7374
|
+
}
|
|
7375
|
+
var pendingPromise = promise;
|
|
7376
|
+
pendingPromise.status = 'pending';
|
|
7377
|
+
pendingPromise.then(function (value) {
|
|
7378
|
+
if (pendingPromise.status === 'pending') {
|
|
7379
|
+
var fulfilledPromise = pendingPromise;
|
|
7380
|
+
fulfilledPromise.status = 'fulfilled';
|
|
7381
|
+
fulfilledPromise.value = value;
|
|
7382
|
+
}
|
|
7383
|
+
}, function (reason) {
|
|
7384
|
+
if (pendingPromise.status === 'pending') {
|
|
7385
|
+
var rejectedPromise = pendingPromise;
|
|
7386
|
+
rejectedPromise.status = 'rejected';
|
|
7387
|
+
rejectedPromise.reason = reason;
|
|
7388
|
+
}
|
|
7389
|
+
});
|
|
7390
|
+
return promise;
|
|
7391
|
+
}
|
|
7392
|
+
|
|
7393
|
+
function __use(promise) {
|
|
7394
|
+
var statefulPromise = wrapPromiseWithState(promise);
|
|
7395
|
+
switch (statefulPromise.status) {
|
|
7396
|
+
case 'pending':
|
|
7397
|
+
throw statefulPromise;
|
|
7398
|
+
case 'rejected':
|
|
7399
|
+
throw statefulPromise.reason;
|
|
7400
|
+
case 'fulfilled':
|
|
7401
|
+
return statefulPromise.value;
|
|
7402
|
+
}
|
|
7403
|
+
}
|
|
7359
7404
|
|
|
7360
7405
|
function useSuspenseCache(override) {
|
|
7361
7406
|
var context = React.useContext(getApolloContext());
|
|
7362
7407
|
var suspenseCache = override || context.suspenseCache;
|
|
7363
7408
|
__DEV__ ? tsInvariant.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context or passed in as an option. ' +
|
|
7364
7409
|
'Wrap the root component in an <ApolloProvider> and provide a suspenseCache, ' +
|
|
7365
|
-
'or pass a SuspenseCache instance in via options.') : tsInvariant.invariant(suspenseCache,
|
|
7410
|
+
'or pass a SuspenseCache instance in via options.') : tsInvariant.invariant(suspenseCache, 34);
|
|
7366
7411
|
return suspenseCache;
|
|
7367
7412
|
}
|
|
7368
7413
|
|
|
7369
|
-
var SUPPORTED_FETCH_POLICIES = [
|
|
7370
|
-
'cache-first',
|
|
7371
|
-
'network-only',
|
|
7372
|
-
'no-cache',
|
|
7373
|
-
'cache-and-network',
|
|
7374
|
-
];
|
|
7375
|
-
var DEFAULT_FETCH_POLICY = 'cache-first';
|
|
7376
|
-
var DEFAULT_SUSPENSE_POLICY = 'always';
|
|
7377
|
-
var DEFAULT_ERROR_POLICY = 'none';
|
|
7378
7414
|
function useSuspenseQuery_experimental(query, options) {
|
|
7379
7415
|
if (options === void 0) { options = Object.create(null); }
|
|
7380
|
-
var
|
|
7416
|
+
var didPreviouslySuspend = React.useRef(false);
|
|
7381
7417
|
var client = useApolloClient(options.client);
|
|
7382
|
-
var
|
|
7383
|
-
var
|
|
7384
|
-
var
|
|
7385
|
-
var
|
|
7386
|
-
var
|
|
7387
|
-
var
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
var result =
|
|
7391
|
-
var
|
|
7392
|
-
var
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
}
|
|
7412
|
-
React.useEffect(function () {
|
|
7413
|
-
var variables = watchQueryOptions.variables, query = watchQueryOptions.query;
|
|
7414
|
-
var previousOpts = previousWatchQueryOptionsRef.current;
|
|
7415
|
-
if (variables !== previousOpts.variables || query !== previousOpts.query) {
|
|
7416
|
-
suspenseCache.remove(previousOpts.query, previousOpts.variables);
|
|
7417
|
-
suspenseCache.add(query, variables, {
|
|
7418
|
-
promise: observable.reobserve({ query: query, variables: variables }),
|
|
7419
|
-
observable: observable,
|
|
7420
|
-
});
|
|
7421
|
-
previousWatchQueryOptionsRef.current = watchQueryOptions;
|
|
7422
|
-
}
|
|
7423
|
-
}, [watchQueryOptions]);
|
|
7424
|
-
React.useEffect(function () {
|
|
7425
|
-
return function () {
|
|
7426
|
-
suspenseCache.remove(query, variables);
|
|
7427
|
-
};
|
|
7428
|
-
}, []);
|
|
7429
|
-
var fetchMore = React.useCallback(function (options) {
|
|
7430
|
-
var promise = observable.fetchMore(options);
|
|
7431
|
-
suspenseCache.add(query, watchQueryOptions.variables, {
|
|
7432
|
-
promise: promise,
|
|
7433
|
-
observable: observable,
|
|
7434
|
-
});
|
|
7435
|
-
return promise;
|
|
7436
|
-
}, [observable]);
|
|
7437
|
-
var refetch = React.useCallback(function (variables) {
|
|
7438
|
-
var promise = observable.refetch(variables);
|
|
7439
|
-
suspenseCache.add(query, watchQueryOptions.variables, {
|
|
7440
|
-
promise: promise,
|
|
7441
|
-
observable: observable,
|
|
7442
|
-
});
|
|
7443
|
-
return promise;
|
|
7444
|
-
}, [observable]);
|
|
7445
|
-
var subscribeToMore = React.useCallback(function (options) { return observable.subscribeToMore(options); }, [observable]);
|
|
7418
|
+
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
7419
|
+
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
|
|
7420
|
+
var _a = watchQueryOptions.returnPartialData, returnPartialData = _a === void 0 ? false : _a, variables = watchQueryOptions.variables;
|
|
7421
|
+
var _b = options.suspensePolicy, suspensePolicy = _b === void 0 ? 'always' : _b;
|
|
7422
|
+
var shouldSuspend = suspensePolicy === 'always' || !didPreviouslySuspend.current;
|
|
7423
|
+
var subscription = suspenseCache.getSubscription(client, query, variables, function () { return client.watchQuery(watchQueryOptions); });
|
|
7424
|
+
var dispose = useTrackedSubscriptions(subscription);
|
|
7425
|
+
useStrictModeSafeCleanupEffect(dispose);
|
|
7426
|
+
var result = useSyncExternalStore(subscription.listen, function () { return subscription.result; }, function () { return subscription.result; });
|
|
7427
|
+
var previousVariables = React.useRef(variables);
|
|
7428
|
+
var previousData = React.useRef(result.data);
|
|
7429
|
+
if (!equality.equal(variables, previousVariables.current)) {
|
|
7430
|
+
if (result.networkStatus !== exports.NetworkStatus.ready) {
|
|
7431
|
+
result = tslib.__assign(tslib.__assign({}, result), { data: previousData.current, networkStatus: exports.NetworkStatus.setVariables });
|
|
7432
|
+
}
|
|
7433
|
+
previousVariables.current = variables;
|
|
7434
|
+
previousData.current = result.data;
|
|
7435
|
+
}
|
|
7436
|
+
if (result.networkStatus === exports.NetworkStatus.error ||
|
|
7437
|
+
(shouldSuspend &&
|
|
7438
|
+
!shouldUseCachedResult(subscription.result, {
|
|
7439
|
+
returnPartialData: returnPartialData,
|
|
7440
|
+
fetchPolicy: options.fetchPolicy,
|
|
7441
|
+
}))) {
|
|
7442
|
+
__use(subscription.promise);
|
|
7443
|
+
}
|
|
7444
|
+
didPreviouslySuspend.current = true;
|
|
7445
|
+
var fetchMore = React.useCallback(function (options) { return subscription.fetchMore(options); }, [subscription]);
|
|
7446
|
+
var refetch = React.useCallback(function (variables) { return subscription.refetch(variables); }, [subscription]);
|
|
7447
|
+
var subscribeToMore = React.useCallback(function (options) { return subscription.observable.subscribeToMore(options); }, [subscription]);
|
|
7446
7448
|
return React.useMemo(function () {
|
|
7447
7449
|
return {
|
|
7448
7450
|
client: client,
|
|
7449
7451
|
data: result.data,
|
|
7450
|
-
error:
|
|
7452
|
+
error: toApolloError(result),
|
|
7451
7453
|
networkStatus: result.networkStatus,
|
|
7452
7454
|
fetchMore: fetchMore,
|
|
7453
7455
|
refetch: refetch,
|
|
7454
7456
|
subscribeToMore: subscribeToMore,
|
|
7455
7457
|
};
|
|
7456
|
-
}, [
|
|
7457
|
-
client,
|
|
7458
|
-
fetchMore,
|
|
7459
|
-
refetch,
|
|
7460
|
-
result,
|
|
7461
|
-
observable,
|
|
7462
|
-
errorPolicy,
|
|
7463
|
-
subscribeToMore,
|
|
7464
|
-
]);
|
|
7458
|
+
}, [client, fetchMore, refetch, result, subscribeToMore]);
|
|
7465
7459
|
}
|
|
7466
7460
|
function validateOptions(options) {
|
|
7467
|
-
var query = options.query,
|
|
7461
|
+
var query = options.query, fetchPolicy = options.fetchPolicy, returnPartialData = options.returnPartialData;
|
|
7468
7462
|
verifyDocumentType(query, exports.DocumentType.Query);
|
|
7469
7463
|
validateFetchPolicy(fetchPolicy);
|
|
7470
7464
|
validatePartialDataReturn(fetchPolicy, returnPartialData);
|
|
7471
7465
|
}
|
|
7472
7466
|
function validateFetchPolicy(fetchPolicy) {
|
|
7473
|
-
|
|
7467
|
+
if (fetchPolicy === void 0) { fetchPolicy = 'cache-first'; }
|
|
7468
|
+
var supportedFetchPolicies = [
|
|
7469
|
+
'cache-first',
|
|
7470
|
+
'network-only',
|
|
7471
|
+
'no-cache',
|
|
7472
|
+
'cache-and-network',
|
|
7473
|
+
];
|
|
7474
|
+
__DEV__ ? tsInvariant.invariant(supportedFetchPolicies.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : tsInvariant.invariant(supportedFetchPolicies.includes(fetchPolicy), 35);
|
|
7474
7475
|
}
|
|
7475
7476
|
function validatePartialDataReturn(fetchPolicy, returnPartialData) {
|
|
7476
7477
|
if (fetchPolicy === 'no-cache' && returnPartialData) {
|
|
@@ -7482,125 +7483,137 @@ function toApolloError(result) {
|
|
|
7482
7483
|
? new ApolloError({ graphQLErrors: result.errors })
|
|
7483
7484
|
: result.error;
|
|
7484
7485
|
}
|
|
7485
|
-
function
|
|
7486
|
-
var
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
resolve(value);
|
|
7492
|
-
subscription.unsubscribe();
|
|
7493
|
-
},
|
|
7494
|
-
error: reject,
|
|
7495
|
-
});
|
|
7496
|
-
});
|
|
7497
|
-
}
|
|
7498
|
-
return concast.promise;
|
|
7486
|
+
function useTrackedSubscriptions(subscription) {
|
|
7487
|
+
var trackedSubscriptions = React.useRef(new Set());
|
|
7488
|
+
trackedSubscriptions.current.add(subscription);
|
|
7489
|
+
return function dispose() {
|
|
7490
|
+
trackedSubscriptions.current.forEach(function (sub) { return sub.dispose(); });
|
|
7491
|
+
};
|
|
7499
7492
|
}
|
|
7500
7493
|
function useWatchQueryOptions(_a) {
|
|
7501
|
-
var query = _a.query, options = _a.options
|
|
7502
|
-
var
|
|
7503
|
-
var watchQueryOptions = useDeepMemo(function () {
|
|
7504
|
-
var errorPolicy = options.errorPolicy, fetchPolicy = options.fetchPolicy, _a = options.suspensePolicy, suspensePolicy = _a === void 0 ? DEFAULT_SUSPENSE_POLICY : _a, variables = options.variables, watchQueryOptions = tslib.__rest(options, ["errorPolicy", "fetchPolicy", "suspensePolicy", "variables"]);
|
|
7505
|
-
return tslib.__assign(tslib.__assign({}, watchQueryOptions), { query: query, errorPolicy: errorPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.errorPolicy) || DEFAULT_ERROR_POLICY, fetchPolicy: fetchPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.fetchPolicy) || DEFAULT_FETCH_POLICY, notifyOnNetworkStatusChange: suspensePolicy === 'always', fetchOnFirstSubscribe: false, variables: compact(tslib.__assign(tslib.__assign({}, defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.variables), variables)) });
|
|
7506
|
-
}, [options, query, defaultOptions]);
|
|
7494
|
+
var query = _a.query, options = _a.options;
|
|
7495
|
+
var watchQueryOptions = useDeepMemo(function () { return (tslib.__assign(tslib.__assign({}, options), { query: query, notifyOnNetworkStatusChange: true, nextFetchPolicy: void 0 })); }, [options, query]);
|
|
7507
7496
|
if (__DEV__) {
|
|
7508
7497
|
validateOptions(watchQueryOptions);
|
|
7509
7498
|
}
|
|
7510
7499
|
return watchQueryOptions;
|
|
7511
7500
|
}
|
|
7512
|
-
function
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
var subscribeTimeoutRef = React.useRef();
|
|
7519
|
-
if (!resultRef.current) {
|
|
7520
|
-
resultRef.current = observable.getCurrentResult();
|
|
7501
|
+
function shouldUseCachedResult(result, _a) {
|
|
7502
|
+
var returnPartialData = _a.returnPartialData, fetchPolicy = _a.fetchPolicy;
|
|
7503
|
+
if (result.networkStatus === exports.NetworkStatus.refetch ||
|
|
7504
|
+
result.networkStatus === exports.NetworkStatus.fetchMore ||
|
|
7505
|
+
result.networkStatus === exports.NetworkStatus.error) {
|
|
7506
|
+
return false;
|
|
7521
7507
|
}
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
}, []);
|
|
7528
|
-
return useSyncExternalStore(React.useCallback(function (forceUpdate) {
|
|
7529
|
-
clearTimeout(subscribeTimeoutRef.current);
|
|
7530
|
-
function handleUpdate() {
|
|
7531
|
-
var previousResult = resultRef.current;
|
|
7532
|
-
var result = observable.getCurrentResult();
|
|
7533
|
-
if (previousResult.loading === result.loading &&
|
|
7534
|
-
previousResult.networkStatus === result.networkStatus &&
|
|
7535
|
-
equality.equal(previousResult.data, result.data)) {
|
|
7536
|
-
return;
|
|
7537
|
-
}
|
|
7538
|
-
resultRef.current = result;
|
|
7539
|
-
if (isMountedRef.current) {
|
|
7540
|
-
forceUpdate();
|
|
7541
|
-
}
|
|
7508
|
+
switch (fetchPolicy) {
|
|
7509
|
+
case void 0:
|
|
7510
|
+
case 'cache-first':
|
|
7511
|
+
case 'cache-and-network': {
|
|
7512
|
+
return Boolean(result.data && (!result.partial || returnPartialData));
|
|
7542
7513
|
}
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
next: handleUpdate,
|
|
7547
|
-
error: handleUpdate,
|
|
7548
|
-
});
|
|
7549
|
-
var result = resultRef.current;
|
|
7550
|
-
if (result.networkStatus !== observable['queryInfo'].networkStatus &&
|
|
7551
|
-
result.networkStatus === exports.NetworkStatus.ready) {
|
|
7552
|
-
observable['queryInfo'].markReady();
|
|
7553
|
-
}
|
|
7554
|
-
});
|
|
7555
|
-
return function () {
|
|
7556
|
-
subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
|
|
7557
|
-
};
|
|
7558
|
-
}, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
|
|
7514
|
+
default:
|
|
7515
|
+
return false;
|
|
7516
|
+
}
|
|
7559
7517
|
}
|
|
7560
7518
|
|
|
7561
|
-
|
|
7562
|
-
function
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7519
|
+
function wrapWithCustomPromise(concast) {
|
|
7520
|
+
return new Promise(function (resolve, reject) {
|
|
7521
|
+
var subscription = concast.subscribe({
|
|
7522
|
+
next: function (value) {
|
|
7523
|
+
resolve(value);
|
|
7524
|
+
subscription.unsubscribe();
|
|
7525
|
+
},
|
|
7526
|
+
error: reject,
|
|
7527
|
+
});
|
|
7528
|
+
});
|
|
7529
|
+
}
|
|
7530
|
+
var isMultipartQuery = optimism.wrap(function (query) {
|
|
7531
|
+
return hasAnyDirectives(['defer', 'stream'], query);
|
|
7532
|
+
});
|
|
7533
|
+
var QuerySubscription = (function () {
|
|
7534
|
+
function QuerySubscription(observable, options) {
|
|
7535
|
+
if (options === void 0) { options = Object.create(null); }
|
|
7536
|
+
var _a;
|
|
7537
|
+
this.listeners = new Set();
|
|
7538
|
+
this.listen = this.listen.bind(this);
|
|
7539
|
+
this.handleNext = this.handleNext.bind(this);
|
|
7540
|
+
this.handleError = this.handleError.bind(this);
|
|
7541
|
+
this.dispose = this.dispose.bind(this);
|
|
7542
|
+
this.observable = observable;
|
|
7543
|
+
this.result = observable.getCurrentResult();
|
|
7544
|
+
if (options.onDispose) {
|
|
7545
|
+
this.onDispose = options.onDispose;
|
|
7546
|
+
}
|
|
7547
|
+
this.subscription = observable.subscribe({
|
|
7548
|
+
next: this.handleNext,
|
|
7549
|
+
error: this.handleError,
|
|
7550
|
+
});
|
|
7551
|
+
__DEV__ ? tsInvariant.invariant(observable['concast'], 'Unexpected error: A concast was not found on the observable.') : tsInvariant.invariant(observable['concast'], 28);
|
|
7552
|
+
var concast = observable['concast'];
|
|
7553
|
+
this.promise = isMultipartQuery(observable.query)
|
|
7554
|
+
? wrapWithCustomPromise(concast)
|
|
7555
|
+
: concast.promise;
|
|
7556
|
+
this.autoDisposeTimeoutId = setTimeout(this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
|
|
7557
|
+
}
|
|
7558
|
+
QuerySubscription.prototype.listen = function (listener) {
|
|
7559
|
+
var _this = this;
|
|
7560
|
+
clearTimeout(this.autoDisposeTimeoutId);
|
|
7561
|
+
this.listeners.add(listener);
|
|
7562
|
+
return function () {
|
|
7563
|
+
_this.listeners.delete(listener);
|
|
7578
7564
|
};
|
|
7579
|
-
map.set(variablesKey, entry);
|
|
7580
|
-
this.queries.set(query, map);
|
|
7581
|
-
return entry;
|
|
7582
7565
|
};
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
return
|
|
7586
|
-
.get(query)) === null || _a === void 0 ? void 0 : _a.get(this.getVariablesKey(variables));
|
|
7566
|
+
QuerySubscription.prototype.refetch = function (variables) {
|
|
7567
|
+
this.promise = this.observable.refetch(variables);
|
|
7568
|
+
return this.promise;
|
|
7587
7569
|
};
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7570
|
+
QuerySubscription.prototype.fetchMore = function (options) {
|
|
7571
|
+
this.promise = this.observable.fetchMore(options);
|
|
7572
|
+
return this.promise;
|
|
7573
|
+
};
|
|
7574
|
+
QuerySubscription.prototype.dispose = function () {
|
|
7575
|
+
this.subscription.unsubscribe();
|
|
7576
|
+
this.onDispose();
|
|
7577
|
+
};
|
|
7578
|
+
QuerySubscription.prototype.onDispose = function () {
|
|
7579
|
+
};
|
|
7580
|
+
QuerySubscription.prototype.handleNext = function (result) {
|
|
7581
|
+
if (isNetworkRequestSettled(result.networkStatus) &&
|
|
7582
|
+
this.result.data &&
|
|
7583
|
+
result.data === void 0) {
|
|
7584
|
+
result.data = this.result.data;
|
|
7600
7585
|
}
|
|
7586
|
+
this.result = result;
|
|
7587
|
+
this.deliver(result);
|
|
7588
|
+
};
|
|
7589
|
+
QuerySubscription.prototype.handleError = function (error) {
|
|
7590
|
+
var result = tslib.__assign(tslib.__assign({}, this.result), { error: error, networkStatus: exports.NetworkStatus.error });
|
|
7591
|
+
this.result = result;
|
|
7592
|
+
this.deliver(result);
|
|
7601
7593
|
};
|
|
7602
|
-
|
|
7603
|
-
|
|
7594
|
+
QuerySubscription.prototype.deliver = function (result) {
|
|
7595
|
+
this.listeners.forEach(function (listener) { return listener(result); });
|
|
7596
|
+
};
|
|
7597
|
+
return QuerySubscription;
|
|
7598
|
+
}());
|
|
7599
|
+
|
|
7600
|
+
var SuspenseCache = (function () {
|
|
7601
|
+
function SuspenseCache(options) {
|
|
7602
|
+
if (options === void 0) { options = Object.create(null); }
|
|
7603
|
+
this.cacheKeys = new trie.Trie(canUseWeakMap, function (cacheKey) { return cacheKey; });
|
|
7604
|
+
this.subscriptions = new Map();
|
|
7605
|
+
this.options = options;
|
|
7606
|
+
}
|
|
7607
|
+
SuspenseCache.prototype.getSubscription = function (client, query, variables, createObservable) {
|
|
7608
|
+
var _this = this;
|
|
7609
|
+
var cacheKey = this.cacheKeys.lookup(client, query, canonicalStringify(variables));
|
|
7610
|
+
if (!this.subscriptions.has(cacheKey)) {
|
|
7611
|
+
this.subscriptions.set(cacheKey, new QuerySubscription(createObservable(), {
|
|
7612
|
+
autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,
|
|
7613
|
+
onDispose: function () { return _this.subscriptions.delete(cacheKey); },
|
|
7614
|
+
}));
|
|
7615
|
+
}
|
|
7616
|
+
return this.subscriptions.get(cacheKey);
|
|
7604
7617
|
};
|
|
7605
7618
|
return SuspenseCache;
|
|
7606
7619
|
}());
|