@apollo/client 3.7.2 → 3.8.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs +250 -30
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/config/jest/setup.d.ts +1 -1
- package/config/jest/setup.d.ts.map +1 -1
- package/config/jest/setup.js +1 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +3 -2
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +6 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/core.cjs +10 -5
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +10 -5
- package/core/watchQueryOptions.d.ts +1 -0
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +35 -23
- package/package.json +17 -3
- package/react/cache/SuspenseCache.d.ts +18 -0
- package/react/cache/SuspenseCache.d.ts.map +1 -0
- package/react/cache/SuspenseCache.js +49 -0
- package/react/cache/SuspenseCache.js.map +1 -0
- package/react/cache/index.d.ts +2 -0
- package/react/cache/index.d.ts.map +1 -0
- package/react/cache/index.js +2 -0
- package/react/cache/index.js.map +1 -0
- package/react/context/ApolloContext.d.ts +2 -0
- package/react/context/ApolloContext.d.ts.map +1 -1
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/ApolloProvider.d.ts +2 -0
- package/react/context/ApolloProvider.d.ts.map +1 -1
- package/react/context/ApolloProvider.js +4 -1
- package/react/context/ApolloProvider.js.map +1 -1
- package/react/context/context.cjs +4 -1
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +4 -1
- package/react/hooks/compareResults.d.ts +3 -0
- package/react/hooks/compareResults.d.ts.map +1 -0
- package/react/hooks/compareResults.js +63 -0
- package/react/hooks/compareResults.js.map +1 -0
- package/react/hooks/hooks.cjs +167 -3
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +167 -3
- package/react/hooks/index.d.ts +1 -0
- package/react/hooks/index.d.ts.map +1 -1
- package/react/hooks/index.js +1 -0
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/internal/index.d.ts +2 -0
- package/react/hooks/internal/index.d.ts.map +1 -0
- package/react/hooks/internal/index.js +2 -0
- package/react/hooks/internal/index.js.map +1 -0
- package/react/hooks/internal/useDeepMemo.d.ts +3 -0
- package/react/hooks/internal/useDeepMemo.d.ts.map +1 -0
- package/react/hooks/internal/useDeepMemo.js +10 -0
- package/react/hooks/internal/useDeepMemo.js.map +1 -0
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +5 -3
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSuspenseCache.d.ts +2 -0
- package/react/hooks/useSuspenseCache.d.ts.map +1 -0
- package/react/hooks/useSuspenseCache.js +10 -0
- package/react/hooks/useSuspenseCache.js.map +1 -0
- package/react/hooks/useSuspenseQuery.d.ts +10 -0
- package/react/hooks/useSuspenseQuery.d.ts.map +1 -0
- package/react/hooks/useSuspenseQuery.js +157 -0
- package/react/hooks/useSuspenseQuery.js.map +1 -0
- package/react/index.d.ts +1 -0
- package/react/index.d.ts.map +1 -1
- package/react/index.js +1 -0
- package/react/index.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 +49 -2
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +49 -2
- package/react/types/types.d.ts +9 -1
- 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/react/MockedProvider.d.ts +3 -0
- package/testing/react/MockedProvider.d.ts.map +1 -1
- package/testing/react/MockedProvider.js +8 -3
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +54 -3
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +54 -3
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/globals/index.js +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/utilities.cjs +16 -16
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +16 -16
- package/version.js +1 -1
package/apollo-client.cjs
CHANGED
|
@@ -45,7 +45,7 @@ function shouldInclude(_a, variables) {
|
|
|
45
45
|
var evaledValue = false;
|
|
46
46
|
if (ifArgument.value.kind === 'Variable') {
|
|
47
47
|
evaledValue = variables && variables[ifArgument.value.name.value];
|
|
48
|
-
__DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0,
|
|
48
|
+
__DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 41);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
51
|
evaledValue = ifArgument.value.value;
|
|
@@ -81,13 +81,13 @@ function getInclusionDirectives(directives) {
|
|
|
81
81
|
return;
|
|
82
82
|
var directiveArguments = directive.arguments;
|
|
83
83
|
var directiveName = directive.name.value;
|
|
84
|
-
__DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1,
|
|
84
|
+
__DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 42);
|
|
85
85
|
var ifArgument = directiveArguments[0];
|
|
86
|
-
__DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if',
|
|
86
|
+
__DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 43);
|
|
87
87
|
var ifValue = ifArgument.value;
|
|
88
88
|
__DEV__ ? tsInvariant.invariant(ifValue &&
|
|
89
89
|
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
|
|
90
|
-
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'),
|
|
90
|
+
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 44);
|
|
91
91
|
result.push({ directive: directive, ifArgument: ifArgument });
|
|
92
92
|
});
|
|
93
93
|
}
|
|
@@ -100,14 +100,14 @@ function getFragmentQueryDocument(document, fragmentName) {
|
|
|
100
100
|
document.definitions.forEach(function (definition) {
|
|
101
101
|
if (definition.kind === 'OperationDefinition') {
|
|
102
102
|
throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
|
|
103
|
-
'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(
|
|
103
|
+
'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(45);
|
|
104
104
|
}
|
|
105
105
|
if (definition.kind === 'FragmentDefinition') {
|
|
106
106
|
fragments.push(definition);
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
109
|
if (typeof actualFragmentName === 'undefined') {
|
|
110
|
-
__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,
|
|
110
|
+
__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, 46);
|
|
111
111
|
actualFragmentName = fragments[0].name.value;
|
|
112
112
|
}
|
|
113
113
|
var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
|
|
@@ -148,7 +148,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
|
|
|
148
148
|
return fragmentMap(fragmentName);
|
|
149
149
|
}
|
|
150
150
|
var fragment = fragmentMap && fragmentMap[fragmentName];
|
|
151
|
-
__DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment,
|
|
151
|
+
__DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 47);
|
|
152
152
|
return fragment || null;
|
|
153
153
|
}
|
|
154
154
|
default:
|
|
@@ -232,7 +232,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
|
|
|
232
232
|
else {
|
|
233
233
|
throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
|
|
234
234
|
'is not supported. Use variables instead of inline arguments to ' +
|
|
235
|
-
'overcome this limitation.') : new tsInvariant.InvariantError(
|
|
235
|
+
'overcome this limitation.') : new tsInvariant.InvariantError(56);
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
function storeKeyNameFromField(field, variables) {
|
|
@@ -366,16 +366,16 @@ function isInlineFragment(selection) {
|
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
function checkDocument(doc) {
|
|
369
|
-
__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',
|
|
369
|
+
__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', 48);
|
|
370
370
|
var operations = doc.definitions
|
|
371
371
|
.filter(function (d) { return d.kind !== 'FragmentDefinition'; })
|
|
372
372
|
.map(function (definition) {
|
|
373
373
|
if (definition.kind !== 'OperationDefinition') {
|
|
374
|
-
throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(
|
|
374
|
+
throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(49);
|
|
375
375
|
}
|
|
376
376
|
return definition;
|
|
377
377
|
});
|
|
378
|
-
__DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1,
|
|
378
|
+
__DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 50);
|
|
379
379
|
return doc;
|
|
380
380
|
}
|
|
381
381
|
function getOperationDefinition(doc) {
|
|
@@ -394,14 +394,14 @@ function getFragmentDefinitions(doc) {
|
|
|
394
394
|
}
|
|
395
395
|
function getQueryDefinition(doc) {
|
|
396
396
|
var queryDef = getOperationDefinition(doc);
|
|
397
|
-
__DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query',
|
|
397
|
+
__DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 51);
|
|
398
398
|
return queryDef;
|
|
399
399
|
}
|
|
400
400
|
function getFragmentDefinition(doc) {
|
|
401
|
-
__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',
|
|
402
|
-
__DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1,
|
|
401
|
+
__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', 52);
|
|
402
|
+
__DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 53);
|
|
403
403
|
var fragmentDef = doc.definitions[0];
|
|
404
|
-
__DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition',
|
|
404
|
+
__DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 54);
|
|
405
405
|
return fragmentDef;
|
|
406
406
|
}
|
|
407
407
|
function getMainDefinition(queryDoc) {
|
|
@@ -424,7 +424,7 @@ function getMainDefinition(queryDoc) {
|
|
|
424
424
|
if (fragmentDefinition) {
|
|
425
425
|
return fragmentDefinition;
|
|
426
426
|
}
|
|
427
|
-
throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(
|
|
427
|
+
throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(55);
|
|
428
428
|
}
|
|
429
429
|
function getDefaultValues(definition) {
|
|
430
430
|
var defaultValues = Object.create(null);
|
|
@@ -1300,7 +1300,7 @@ var concat = ApolloLink.concat;
|
|
|
1300
1300
|
|
|
1301
1301
|
var execute = ApolloLink.execute;
|
|
1302
1302
|
|
|
1303
|
-
var version = '3.
|
|
1303
|
+
var version = '3.8.0-alpha.0';
|
|
1304
1304
|
|
|
1305
1305
|
function isNodeResponse(value) {
|
|
1306
1306
|
return !!value.body;
|
|
@@ -4233,13 +4233,14 @@ var ObservableQuery = (function (_super) {
|
|
|
4233
4233
|
function ObservableQuery(_a) {
|
|
4234
4234
|
var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
|
|
4235
4235
|
var _this = _super.call(this, function (observer) {
|
|
4236
|
+
var _a = options.fetchOnFirstSubscribe, fetchOnFirstSubscribe = _a === void 0 ? true : _a;
|
|
4236
4237
|
try {
|
|
4237
4238
|
var subObserver = observer._subscription._observer;
|
|
4238
4239
|
if (subObserver && !subObserver.error) {
|
|
4239
4240
|
subObserver.error = defaultSubscriptionObserverErrorCallback;
|
|
4240
4241
|
}
|
|
4241
4242
|
}
|
|
4242
|
-
catch (
|
|
4243
|
+
catch (_b) { }
|
|
4243
4244
|
var first = !_this.observers.size;
|
|
4244
4245
|
_this.observers.add(observer);
|
|
4245
4246
|
var last = _this.last;
|
|
@@ -4249,7 +4250,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4249
4250
|
else if (last && last.result) {
|
|
4250
4251
|
observer.next && observer.next(last.result);
|
|
4251
4252
|
}
|
|
4252
|
-
if (first) {
|
|
4253
|
+
if (first && fetchOnFirstSubscribe) {
|
|
4253
4254
|
_this.reobserve().catch(function () { });
|
|
4254
4255
|
}
|
|
4255
4256
|
return function () {
|
|
@@ -5175,13 +5176,13 @@ var QueryInfo = (function () {
|
|
|
5175
5176
|
};
|
|
5176
5177
|
QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
|
|
5177
5178
|
var _this = this;
|
|
5179
|
+
var merger = new DeepMerger();
|
|
5178
5180
|
var graphQLErrors = isNonEmptyArray(result.errors)
|
|
5179
5181
|
? result.errors.slice(0)
|
|
5180
5182
|
: [];
|
|
5181
5183
|
this.reset();
|
|
5182
5184
|
if ('incremental' in result && isNonEmptyArray(result.incremental)) {
|
|
5183
5185
|
var mergedData_1 = this.getDiff().result;
|
|
5184
|
-
var merger_1 = new DeepMerger();
|
|
5185
5186
|
result.incremental.forEach(function (_a) {
|
|
5186
5187
|
var data = _a.data, path = _a.path, errors = _a.errors;
|
|
5187
5188
|
for (var i = path.length - 1; i >= 0; --i) {
|
|
@@ -5194,10 +5195,14 @@ var QueryInfo = (function () {
|
|
|
5194
5195
|
if (errors) {
|
|
5195
5196
|
graphQLErrors.push.apply(graphQLErrors, errors);
|
|
5196
5197
|
}
|
|
5197
|
-
mergedData_1 =
|
|
5198
|
+
mergedData_1 = merger.merge(mergedData_1, data);
|
|
5198
5199
|
});
|
|
5199
5200
|
result.data = mergedData_1;
|
|
5200
5201
|
}
|
|
5202
|
+
else if ('hasNext' in result && result.hasNext) {
|
|
5203
|
+
var diff = this.getDiff();
|
|
5204
|
+
result.data = merger.merge(diff.result, result.data);
|
|
5205
|
+
}
|
|
5201
5206
|
this.graphQLErrors = graphQLErrors;
|
|
5202
5207
|
if (options.fetchPolicy === 'no-cache') {
|
|
5203
5208
|
this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
|
|
@@ -6369,13 +6374,16 @@ var ApolloConsumer = function (props) {
|
|
|
6369
6374
|
};
|
|
6370
6375
|
|
|
6371
6376
|
var ApolloProvider = function (_a) {
|
|
6372
|
-
var client = _a.client, children = _a.children;
|
|
6377
|
+
var client = _a.client, suspenseCache = _a.suspenseCache, children = _a.children;
|
|
6373
6378
|
var ApolloContext = getApolloContext();
|
|
6374
6379
|
return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
|
|
6375
6380
|
if (context === void 0) { context = {}; }
|
|
6376
6381
|
if (client && context.client !== client) {
|
|
6377
6382
|
context = Object.assign({}, context, { client: client });
|
|
6378
6383
|
}
|
|
6384
|
+
if (suspenseCache) {
|
|
6385
|
+
context = Object.assign({}, context, { suspenseCache: suspenseCache });
|
|
6386
|
+
}
|
|
6379
6387
|
__DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
|
|
6380
6388
|
'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 28);
|
|
6381
6389
|
return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
|
|
@@ -6465,7 +6473,7 @@ function parser(document) {
|
|
|
6465
6473
|
var variables, type, name;
|
|
6466
6474
|
__DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
|
|
6467
6475
|
"DocumentNode. You may need to use 'graphql-tag' or another method " +
|
|
6468
|
-
"to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind,
|
|
6476
|
+
"to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 34);
|
|
6469
6477
|
var fragments = [];
|
|
6470
6478
|
var queries = [];
|
|
6471
6479
|
var mutations = [];
|
|
@@ -6493,11 +6501,11 @@ function parser(document) {
|
|
|
6493
6501
|
__DEV__ ? tsInvariant.invariant(!fragments.length ||
|
|
6494
6502
|
(queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
|
|
6495
6503
|
"You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
|
|
6496
|
-
(queries.length || mutations.length || subscriptions.length),
|
|
6504
|
+
(queries.length || mutations.length || subscriptions.length), 35);
|
|
6497
6505
|
__DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
|
|
6498
6506
|
"".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
|
|
6499
6507
|
"subscriptions and ".concat(mutations.length, " mutations. ") +
|
|
6500
|
-
"You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1,
|
|
6508
|
+
"You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 36);
|
|
6501
6509
|
type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
|
|
6502
6510
|
if (!queries.length && !mutations.length)
|
|
6503
6511
|
type = exports.DocumentType.Subscription;
|
|
@@ -6508,7 +6516,7 @@ function parser(document) {
|
|
|
6508
6516
|
: subscriptions;
|
|
6509
6517
|
__DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
|
|
6510
6518
|
"".concat(definitions.length, " definitions. ") +
|
|
6511
|
-
"You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1,
|
|
6519
|
+
"You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 37);
|
|
6512
6520
|
var definition = definitions[0];
|
|
6513
6521
|
variables = definition.variableDefinitions || [];
|
|
6514
6522
|
if (definition.name && definition.name.kind === 'Name') {
|
|
@@ -6526,7 +6534,7 @@ function verifyDocumentType(document, type) {
|
|
|
6526
6534
|
var requiredOperationName = operationName(type);
|
|
6527
6535
|
var usedOperationName = operationName(operation.type);
|
|
6528
6536
|
__DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
|
|
6529
|
-
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type,
|
|
6537
|
+
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 38);
|
|
6530
6538
|
}
|
|
6531
6539
|
|
|
6532
6540
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
@@ -6753,16 +6761,18 @@ var InternalState = (function () {
|
|
|
6753
6761
|
}
|
|
6754
6762
|
this.result = nextResult;
|
|
6755
6763
|
this.forceUpdate();
|
|
6756
|
-
this.handleErrorOrCompleted(nextResult);
|
|
6764
|
+
this.handleErrorOrCompleted(nextResult, previousResult);
|
|
6757
6765
|
};
|
|
6758
|
-
InternalState.prototype.handleErrorOrCompleted = function (result) {
|
|
6766
|
+
InternalState.prototype.handleErrorOrCompleted = function (result, previousResult) {
|
|
6759
6767
|
var _this = this;
|
|
6760
6768
|
if (!result.loading) {
|
|
6761
6769
|
Promise.resolve().then(function () {
|
|
6762
6770
|
if (result.error) {
|
|
6763
6771
|
_this.onError(result.error);
|
|
6764
6772
|
}
|
|
6765
|
-
else if (result.data
|
|
6773
|
+
else if (result.data &&
|
|
6774
|
+
(previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus) !== result.networkStatus &&
|
|
6775
|
+
result.networkStatus === exports.NetworkStatus.ready) {
|
|
6766
6776
|
_this.onCompleted(result.data);
|
|
6767
6777
|
}
|
|
6768
6778
|
}).catch(function (error) {
|
|
@@ -7131,6 +7141,214 @@ function diffToResult(diff) {
|
|
|
7131
7141
|
return result;
|
|
7132
7142
|
}
|
|
7133
7143
|
|
|
7144
|
+
function useDeepMemo(memoFn, deps) {
|
|
7145
|
+
var ref = React.useRef();
|
|
7146
|
+
if (!ref.current || !equality.equal(ref.current.deps, deps)) {
|
|
7147
|
+
ref.current = { value: memoFn(), deps: deps };
|
|
7148
|
+
}
|
|
7149
|
+
return ref.current.value;
|
|
7150
|
+
}
|
|
7151
|
+
|
|
7152
|
+
function useSuspenseCache() {
|
|
7153
|
+
var suspenseCache = React.useContext(getApolloContext()).suspenseCache;
|
|
7154
|
+
__DEV__ ? tsInvariant.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context. Wrap the root component ' +
|
|
7155
|
+
'in an <ApolloProvider> and provide a suspenseCache.') : tsInvariant.invariant(suspenseCache, 32);
|
|
7156
|
+
return suspenseCache;
|
|
7157
|
+
}
|
|
7158
|
+
|
|
7159
|
+
var SUPPORTED_FETCH_POLICIES = [
|
|
7160
|
+
'cache-first',
|
|
7161
|
+
'network-only',
|
|
7162
|
+
'no-cache',
|
|
7163
|
+
'cache-and-network',
|
|
7164
|
+
];
|
|
7165
|
+
var DEFAULT_FETCH_POLICY = 'cache-first';
|
|
7166
|
+
var DEFAULT_SUSPENSE_POLICY = 'always';
|
|
7167
|
+
var DEFAULT_ERROR_POLICY = 'none';
|
|
7168
|
+
function useSuspenseQuery_experimental(query, options) {
|
|
7169
|
+
if (options === void 0) { options = Object.create(null); }
|
|
7170
|
+
var suspenseCache = useSuspenseCache();
|
|
7171
|
+
var client = useApolloClient(options.client);
|
|
7172
|
+
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options, client: client });
|
|
7173
|
+
var previousWatchQueryOptionsRef = React.useRef(watchQueryOptions);
|
|
7174
|
+
var fetchPolicy = watchQueryOptions.fetchPolicy, errorPolicy = watchQueryOptions.errorPolicy, returnPartialData = watchQueryOptions.returnPartialData, variables = watchQueryOptions.variables;
|
|
7175
|
+
var cacheEntry = suspenseCache.lookup(query, variables);
|
|
7176
|
+
var observable = React.useState(function () {
|
|
7177
|
+
return (cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.observable) || client.watchQuery(watchQueryOptions);
|
|
7178
|
+
})[0];
|
|
7179
|
+
var result = useObservableQueryResult(observable);
|
|
7180
|
+
if (result.error && errorPolicy === 'none') {
|
|
7181
|
+
throw result.error;
|
|
7182
|
+
}
|
|
7183
|
+
if (result.loading) {
|
|
7184
|
+
if (!cacheEntry) {
|
|
7185
|
+
cacheEntry = suspenseCache.add(query, variables, {
|
|
7186
|
+
promise: observable.reobserve(watchQueryOptions),
|
|
7187
|
+
observable: observable,
|
|
7188
|
+
});
|
|
7189
|
+
}
|
|
7190
|
+
var hasFullResult = result.data && !result.partial;
|
|
7191
|
+
var usePartialResult = returnPartialData && result.partial && result.data;
|
|
7192
|
+
var hasUsableResult = usePartialResult ||
|
|
7193
|
+
(fetchPolicy === 'cache-and-network' && hasFullResult);
|
|
7194
|
+
if (!hasUsableResult && !cacheEntry.fulfilled) {
|
|
7195
|
+
throw cacheEntry.promise;
|
|
7196
|
+
}
|
|
7197
|
+
}
|
|
7198
|
+
React.useEffect(function () {
|
|
7199
|
+
var variables = watchQueryOptions.variables, query = watchQueryOptions.query;
|
|
7200
|
+
var previousOpts = previousWatchQueryOptionsRef.current;
|
|
7201
|
+
if (variables !== previousOpts.variables || query !== previousOpts.query) {
|
|
7202
|
+
suspenseCache.remove(previousOpts.query, previousOpts.variables);
|
|
7203
|
+
suspenseCache.add(query, variables, {
|
|
7204
|
+
promise: observable.reobserve({ query: query, variables: variables }),
|
|
7205
|
+
observable: observable,
|
|
7206
|
+
});
|
|
7207
|
+
previousWatchQueryOptionsRef.current = watchQueryOptions;
|
|
7208
|
+
}
|
|
7209
|
+
}, [watchQueryOptions]);
|
|
7210
|
+
React.useEffect(function () {
|
|
7211
|
+
return function () {
|
|
7212
|
+
suspenseCache.remove(query, variables);
|
|
7213
|
+
};
|
|
7214
|
+
}, []);
|
|
7215
|
+
return React.useMemo(function () {
|
|
7216
|
+
return {
|
|
7217
|
+
data: result.data,
|
|
7218
|
+
error: errorPolicy === 'all' ? toApolloError(result) : void 0,
|
|
7219
|
+
fetchMore: function (options) {
|
|
7220
|
+
var promise = observable.fetchMore(options);
|
|
7221
|
+
suspenseCache.add(query, watchQueryOptions.variables, {
|
|
7222
|
+
promise: promise,
|
|
7223
|
+
observable: observable,
|
|
7224
|
+
});
|
|
7225
|
+
return promise;
|
|
7226
|
+
},
|
|
7227
|
+
refetch: function (variables) {
|
|
7228
|
+
var promise = observable.refetch(variables);
|
|
7229
|
+
suspenseCache.add(query, watchQueryOptions.variables, {
|
|
7230
|
+
promise: promise,
|
|
7231
|
+
observable: observable,
|
|
7232
|
+
});
|
|
7233
|
+
return promise;
|
|
7234
|
+
},
|
|
7235
|
+
};
|
|
7236
|
+
}, [result, observable, errorPolicy]);
|
|
7237
|
+
}
|
|
7238
|
+
function validateOptions(options) {
|
|
7239
|
+
var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;
|
|
7240
|
+
verifyDocumentType(query, exports.DocumentType.Query);
|
|
7241
|
+
validateFetchPolicy(fetchPolicy);
|
|
7242
|
+
validatePartialDataReturn(fetchPolicy, returnPartialData);
|
|
7243
|
+
}
|
|
7244
|
+
function validateFetchPolicy(fetchPolicy) {
|
|
7245
|
+
__DEV__ ? tsInvariant.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : tsInvariant.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), 33);
|
|
7246
|
+
}
|
|
7247
|
+
function validatePartialDataReturn(fetchPolicy, returnPartialData) {
|
|
7248
|
+
if (fetchPolicy === 'no-cache' && returnPartialData) {
|
|
7249
|
+
__DEV__ && tsInvariant.invariant.warn('Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.');
|
|
7250
|
+
}
|
|
7251
|
+
}
|
|
7252
|
+
function toApolloError(result) {
|
|
7253
|
+
return isNonEmptyArray(result.errors)
|
|
7254
|
+
? new ApolloError({ graphQLErrors: result.errors })
|
|
7255
|
+
: result.error;
|
|
7256
|
+
}
|
|
7257
|
+
function useWatchQueryOptions(_a) {
|
|
7258
|
+
var query = _a.query, options = _a.options, client = _a.client;
|
|
7259
|
+
var defaultOptions = client.defaultOptions.watchQuery;
|
|
7260
|
+
var watchQueryOptions = useDeepMemo(function () {
|
|
7261
|
+
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"]);
|
|
7262
|
+
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)) });
|
|
7263
|
+
}, [options, query, defaultOptions]);
|
|
7264
|
+
if (__DEV__) {
|
|
7265
|
+
validateOptions(watchQueryOptions);
|
|
7266
|
+
}
|
|
7267
|
+
return watchQueryOptions;
|
|
7268
|
+
}
|
|
7269
|
+
function useObservableQueryResult(observable) {
|
|
7270
|
+
var resultRef = React.useRef();
|
|
7271
|
+
var isMountedRef = React.useRef(false);
|
|
7272
|
+
if (!resultRef.current) {
|
|
7273
|
+
resultRef.current = observable.getCurrentResult();
|
|
7274
|
+
}
|
|
7275
|
+
React.useLayoutEffect(function () {
|
|
7276
|
+
isMountedRef.current = true;
|
|
7277
|
+
return function () {
|
|
7278
|
+
isMountedRef.current = false;
|
|
7279
|
+
};
|
|
7280
|
+
}, []);
|
|
7281
|
+
return useSyncExternalStore(React.useCallback(function (forceUpdate) {
|
|
7282
|
+
function handleUpdate() {
|
|
7283
|
+
var previousResult = resultRef.current;
|
|
7284
|
+
var result = observable.getCurrentResult();
|
|
7285
|
+
if (previousResult.loading === result.loading &&
|
|
7286
|
+
previousResult.networkStatus === result.networkStatus &&
|
|
7287
|
+
equality.equal(previousResult.data, result.data)) {
|
|
7288
|
+
return;
|
|
7289
|
+
}
|
|
7290
|
+
resultRef.current = result;
|
|
7291
|
+
if (isMountedRef.current) {
|
|
7292
|
+
forceUpdate();
|
|
7293
|
+
}
|
|
7294
|
+
}
|
|
7295
|
+
var subscription = observable.subscribe({
|
|
7296
|
+
next: handleUpdate,
|
|
7297
|
+
error: handleUpdate,
|
|
7298
|
+
});
|
|
7299
|
+
return function () {
|
|
7300
|
+
subscription.unsubscribe();
|
|
7301
|
+
};
|
|
7302
|
+
}, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
|
|
7303
|
+
}
|
|
7304
|
+
|
|
7305
|
+
var SuspenseCache = (function () {
|
|
7306
|
+
function SuspenseCache() {
|
|
7307
|
+
this.queries = new Map();
|
|
7308
|
+
}
|
|
7309
|
+
SuspenseCache.prototype.add = function (query, variables, _a) {
|
|
7310
|
+
var promise = _a.promise, observable = _a.observable;
|
|
7311
|
+
var variablesKey = this.getVariablesKey(variables);
|
|
7312
|
+
var map = this.queries.get(query) || new Map();
|
|
7313
|
+
var entry = {
|
|
7314
|
+
observable: observable,
|
|
7315
|
+
fulfilled: false,
|
|
7316
|
+
promise: promise
|
|
7317
|
+
.catch(function () {
|
|
7318
|
+
})
|
|
7319
|
+
.finally(function () {
|
|
7320
|
+
entry.fulfilled = true;
|
|
7321
|
+
}),
|
|
7322
|
+
};
|
|
7323
|
+
map.set(variablesKey, entry);
|
|
7324
|
+
this.queries.set(query, map);
|
|
7325
|
+
return entry;
|
|
7326
|
+
};
|
|
7327
|
+
SuspenseCache.prototype.lookup = function (query, variables) {
|
|
7328
|
+
var _a;
|
|
7329
|
+
return (_a = this.queries
|
|
7330
|
+
.get(query)) === null || _a === void 0 ? void 0 : _a.get(this.getVariablesKey(variables));
|
|
7331
|
+
};
|
|
7332
|
+
SuspenseCache.prototype.remove = function (query, variables) {
|
|
7333
|
+
var map = this.queries.get(query);
|
|
7334
|
+
if (!map) {
|
|
7335
|
+
return;
|
|
7336
|
+
}
|
|
7337
|
+
var key = this.getVariablesKey(variables);
|
|
7338
|
+
var entry = map.get(key);
|
|
7339
|
+
if (entry && !entry.observable.hasObservers()) {
|
|
7340
|
+
map.delete(key);
|
|
7341
|
+
}
|
|
7342
|
+
if (map.size === 0) {
|
|
7343
|
+
this.queries.delete(query);
|
|
7344
|
+
}
|
|
7345
|
+
};
|
|
7346
|
+
SuspenseCache.prototype.getVariablesKey = function (variables) {
|
|
7347
|
+
return canonicalStringify(variables || Object.create(null));
|
|
7348
|
+
};
|
|
7349
|
+
return SuspenseCache;
|
|
7350
|
+
}());
|
|
7351
|
+
|
|
7134
7352
|
exports.setLogVerbosity = tsInvariant.setVerbosity;
|
|
7135
7353
|
exports.Observable = zenObservableTs.Observable;
|
|
7136
7354
|
exports.disableExperimentalFragmentVariables = graphqlTag.disableExperimentalFragmentVariables;
|
|
@@ -7148,6 +7366,7 @@ exports.HttpLink = HttpLink;
|
|
|
7148
7366
|
exports.InMemoryCache = InMemoryCache;
|
|
7149
7367
|
exports.MissingFieldError = MissingFieldError;
|
|
7150
7368
|
exports.ObservableQuery = ObservableQuery;
|
|
7369
|
+
exports.SuspenseCache = SuspenseCache;
|
|
7151
7370
|
exports.checkFetcher = checkFetcher;
|
|
7152
7371
|
exports.concat = concat;
|
|
7153
7372
|
exports.createHttpLink = createHttpLink;
|
|
@@ -7185,4 +7404,5 @@ exports.useMutation = useMutation;
|
|
|
7185
7404
|
exports.useQuery = useQuery;
|
|
7186
7405
|
exports.useReactiveVar = useReactiveVar;
|
|
7187
7406
|
exports.useSubscription = useSubscription;
|
|
7407
|
+
exports.useSuspenseQuery_experimental = useSuspenseQuery_experimental;
|
|
7188
7408
|
//# sourceMappingURL=apollo-client.cjs.map
|