@apollo/client 3.7.8 → 3.7.10
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/README.md +1 -1
- package/apollo-client.cjs +186 -168
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +20 -21
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +20 -21
- package/cache/core/types/DataProxy.d.ts +3 -2
- package/cache/core/types/DataProxy.d.ts.map +1 -1
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/inmemory/helpers.d.ts +2 -2
- package/cache/inmemory/helpers.d.ts.map +1 -1
- package/cache/inmemory/helpers.js +2 -2
- package/cache/inmemory/helpers.js.map +1 -1
- package/core/ApolloClient.d.ts +3 -3
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +10 -4
- package/core/ApolloClient.js.map +1 -1
- package/core/core.cjs +11 -5
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +11 -5
- package/invariantErrorCodes.js +1 -1
- package/package.json +8 -8
- package/react/hooks/hooks.cjs +2 -1
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +2 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +2 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/utilities/common/arrays.d.ts +1 -0
- package/utilities/common/arrays.d.ts.map +1 -1
- package/utilities/common/arrays.js +1 -0
- package/utilities/common/arrays.js.map +1 -1
- package/utilities/graphql/getFromAST.d.ts.map +1 -1
- package/utilities/graphql/getFromAST.js +7 -3
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +167 -90
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/utilities.cjs +175 -103
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +175 -103
- package/version.js +1 -1
package/utilities/utilities.cjs
CHANGED
|
@@ -364,17 +364,21 @@ function checkDocument(doc) {
|
|
|
364
364
|
}
|
|
365
365
|
function getOperationDefinition(doc) {
|
|
366
366
|
checkDocument(doc);
|
|
367
|
-
return doc.definitions.filter(function (definition) {
|
|
367
|
+
return doc.definitions.filter(function (definition) {
|
|
368
|
+
return definition.kind === 'OperationDefinition';
|
|
369
|
+
})[0];
|
|
368
370
|
}
|
|
369
371
|
function getOperationName(doc) {
|
|
370
372
|
return (doc.definitions
|
|
371
373
|
.filter(function (definition) {
|
|
372
|
-
return definition.kind === 'OperationDefinition' && definition.name;
|
|
374
|
+
return definition.kind === 'OperationDefinition' && !!definition.name;
|
|
373
375
|
})
|
|
374
376
|
.map(function (x) { return x.name.value; })[0] || null);
|
|
375
377
|
}
|
|
376
378
|
function getFragmentDefinitions(doc) {
|
|
377
|
-
return doc.definitions.filter(function (definition) {
|
|
379
|
+
return doc.definitions.filter(function (definition) {
|
|
380
|
+
return definition.kind === 'FragmentDefinition';
|
|
381
|
+
});
|
|
378
382
|
}
|
|
379
383
|
function getQueryDefinition(doc) {
|
|
380
384
|
var queryDef = getOperationDefinition(doc);
|
|
@@ -423,26 +427,20 @@ function getDefaultValues(definition) {
|
|
|
423
427
|
return defaultValues;
|
|
424
428
|
}
|
|
425
429
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
if (test.call(this, elem, i, array)) {
|
|
430
|
-
array[target++] = elem;
|
|
431
|
-
}
|
|
432
|
-
}, context);
|
|
433
|
-
array.length = target;
|
|
434
|
-
return array;
|
|
430
|
+
var isArray = Array.isArray;
|
|
431
|
+
function isNonEmptyArray(value) {
|
|
432
|
+
return Array.isArray(value) && value.length > 0;
|
|
435
433
|
}
|
|
436
434
|
|
|
437
435
|
var TYPENAME_FIELD = {
|
|
438
|
-
kind:
|
|
436
|
+
kind: graphql.Kind.FIELD,
|
|
439
437
|
name: {
|
|
440
|
-
kind:
|
|
438
|
+
kind: graphql.Kind.NAME,
|
|
441
439
|
value: '__typename',
|
|
442
440
|
},
|
|
443
441
|
};
|
|
444
442
|
function isEmpty(op, fragmentMap) {
|
|
445
|
-
return !op || op.selectionSet.selections.every(function (selection) { return selection.kind ===
|
|
443
|
+
return !op || op.selectionSet.selections.every(function (selection) { return selection.kind === graphql.Kind.FRAGMENT_SPREAD &&
|
|
446
444
|
isEmpty(fragmentMap[selection.name.value], fragmentMap); });
|
|
447
445
|
}
|
|
448
446
|
function nullIfDocIsEmpty(doc) {
|
|
@@ -451,84 +449,190 @@ function nullIfDocIsEmpty(doc) {
|
|
|
451
449
|
: doc;
|
|
452
450
|
}
|
|
453
451
|
function getDirectiveMatcher(directives) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
452
|
+
var nameSet = new Set();
|
|
453
|
+
var tests = [];
|
|
454
|
+
directives.forEach(function (directive) {
|
|
455
|
+
if (directive.name) {
|
|
456
|
+
nameSet.add(directive.name);
|
|
457
|
+
}
|
|
458
|
+
else if (directive.test) {
|
|
459
|
+
tests.push(directive.test);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
return function (directive) { return (nameSet.has(directive.name.value) ||
|
|
463
|
+
tests.some(function (test) { return test(directive); })); };
|
|
464
|
+
}
|
|
465
|
+
function makeInUseGetterFunction(defaultKey) {
|
|
466
|
+
var map = new Map();
|
|
467
|
+
return function inUseGetterFunction(key) {
|
|
468
|
+
if (key === void 0) { key = defaultKey; }
|
|
469
|
+
var inUse = map.get(key);
|
|
470
|
+
if (!inUse) {
|
|
471
|
+
map.set(key, inUse = {
|
|
472
|
+
variables: new Set,
|
|
473
|
+
fragmentSpreads: new Set,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
return inUse;
|
|
459
477
|
};
|
|
460
478
|
}
|
|
461
479
|
function removeDirectivesFromDocument(directives, doc) {
|
|
462
|
-
var
|
|
463
|
-
var
|
|
464
|
-
var
|
|
465
|
-
|
|
466
|
-
|
|
480
|
+
var getInUseByOperationName = makeInUseGetterFunction("");
|
|
481
|
+
var getInUseByFragmentName = makeInUseGetterFunction("");
|
|
482
|
+
var getInUse = function (ancestors) {
|
|
483
|
+
for (var p = 0, ancestor = void 0; p < ancestors.length && (ancestor = ancestors[p]); ++p) {
|
|
484
|
+
if (isArray(ancestor))
|
|
485
|
+
continue;
|
|
486
|
+
if (ancestor.kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
487
|
+
return getInUseByOperationName(ancestor.name && ancestor.name.value);
|
|
488
|
+
}
|
|
489
|
+
if (ancestor.kind === graphql.Kind.FRAGMENT_DEFINITION) {
|
|
490
|
+
return getInUseByFragmentName(ancestor.name.value);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
__DEV__ && globals.invariant.error("Could not find operation or fragment");
|
|
494
|
+
return null;
|
|
495
|
+
};
|
|
496
|
+
var operationCount = 0;
|
|
497
|
+
for (var i = doc.definitions.length - 1; i >= 0; --i) {
|
|
498
|
+
if (doc.definitions[i].kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
499
|
+
++operationCount;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
var directiveMatcher = getDirectiveMatcher(directives);
|
|
503
|
+
var hasRemoveDirective = directives.some(function (directive) { return directive.remove; });
|
|
504
|
+
var shouldRemoveField = function (nodeDirectives) { return (hasRemoveDirective &&
|
|
505
|
+
nodeDirectives &&
|
|
506
|
+
nodeDirectives.some(directiveMatcher)); };
|
|
507
|
+
var originalFragmentDefsByPath = new Map();
|
|
508
|
+
var firstVisitMadeChanges = false;
|
|
509
|
+
var fieldOrInlineFragmentVisitor = {
|
|
510
|
+
enter: function (node) {
|
|
511
|
+
if (shouldRemoveField(node.directives)) {
|
|
512
|
+
firstVisitMadeChanges = true;
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
};
|
|
517
|
+
var docWithoutDirectiveSubtrees = graphql.visit(doc, {
|
|
518
|
+
Field: fieldOrInlineFragmentVisitor,
|
|
519
|
+
InlineFragment: fieldOrInlineFragmentVisitor,
|
|
520
|
+
VariableDefinition: {
|
|
521
|
+
enter: function () {
|
|
522
|
+
return false;
|
|
523
|
+
},
|
|
524
|
+
},
|
|
467
525
|
Variable: {
|
|
468
|
-
enter: function (node, _key,
|
|
469
|
-
|
|
470
|
-
|
|
526
|
+
enter: function (node, _key, _parent, _path, ancestors) {
|
|
527
|
+
var inUse = getInUse(ancestors);
|
|
528
|
+
if (inUse) {
|
|
529
|
+
inUse.variables.add(node.name.value);
|
|
471
530
|
}
|
|
472
531
|
},
|
|
473
532
|
},
|
|
474
|
-
|
|
475
|
-
enter: function (node) {
|
|
476
|
-
if (
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
if (arg.value.kind === 'Variable') {
|
|
484
|
-
variablesToRemove.push({
|
|
485
|
-
name: arg.value.name.value,
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
if (node.selectionSet) {
|
|
491
|
-
getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(function (frag) {
|
|
492
|
-
fragmentSpreadsToRemove.push({
|
|
493
|
-
name: frag.name.value,
|
|
494
|
-
});
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
533
|
+
FragmentSpread: {
|
|
534
|
+
enter: function (node, _key, _parent, _path, ancestors) {
|
|
535
|
+
if (shouldRemoveField(node.directives)) {
|
|
536
|
+
firstVisitMadeChanges = true;
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
var inUse = getInUse(ancestors);
|
|
540
|
+
if (inUse) {
|
|
541
|
+
inUse.fragmentSpreads.add(node.name.value);
|
|
499
542
|
}
|
|
500
543
|
},
|
|
501
544
|
},
|
|
502
|
-
|
|
503
|
-
enter: function (node) {
|
|
504
|
-
|
|
545
|
+
FragmentDefinition: {
|
|
546
|
+
enter: function (node, _key, _parent, path) {
|
|
547
|
+
originalFragmentDefsByPath.set(JSON.stringify(path), node);
|
|
548
|
+
},
|
|
549
|
+
leave: function (node, _key, _parent, path) {
|
|
550
|
+
var originalNode = originalFragmentDefsByPath.get(JSON.stringify(path));
|
|
551
|
+
if (node === originalNode) {
|
|
552
|
+
return node;
|
|
553
|
+
}
|
|
554
|
+
if (operationCount > 0 &&
|
|
555
|
+
node.selectionSet.selections.every(function (selection) { return (selection.kind === graphql.Kind.FIELD &&
|
|
556
|
+
selection.name.value === '__typename'); })) {
|
|
557
|
+
getInUseByFragmentName(node.name.value).removed = true;
|
|
558
|
+
firstVisitMadeChanges = true;
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
505
561
|
},
|
|
506
562
|
},
|
|
507
563
|
Directive: {
|
|
508
|
-
|
|
509
|
-
if (
|
|
564
|
+
leave: function (node) {
|
|
565
|
+
if (directiveMatcher(node)) {
|
|
566
|
+
firstVisitMadeChanges = true;
|
|
510
567
|
return null;
|
|
511
568
|
}
|
|
512
569
|
},
|
|
513
570
|
},
|
|
514
|
-
})
|
|
515
|
-
if (
|
|
516
|
-
|
|
517
|
-
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
|
|
518
|
-
}
|
|
519
|
-
if (modifiedDoc &&
|
|
520
|
-
filterInPlace(fragmentSpreadsToRemove, function (fs) { return !!fs.name && !fragmentSpreadsInUse[fs.name]; })
|
|
521
|
-
.length) {
|
|
522
|
-
modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
|
|
571
|
+
});
|
|
572
|
+
if (!firstVisitMadeChanges) {
|
|
573
|
+
return doc;
|
|
523
574
|
}
|
|
524
|
-
|
|
575
|
+
var populateTransitiveVars = function (inUse) {
|
|
576
|
+
if (!inUse.transitiveVars) {
|
|
577
|
+
inUse.transitiveVars = new Set(inUse.variables);
|
|
578
|
+
if (!inUse.removed) {
|
|
579
|
+
inUse.fragmentSpreads.forEach(function (childFragmentName) {
|
|
580
|
+
populateTransitiveVars(getInUseByFragmentName(childFragmentName)).transitiveVars.forEach(function (varName) {
|
|
581
|
+
inUse.transitiveVars.add(varName);
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return inUse;
|
|
587
|
+
};
|
|
588
|
+
var allFragmentNamesUsed = new Set();
|
|
589
|
+
docWithoutDirectiveSubtrees.definitions.forEach(function (def) {
|
|
590
|
+
if (def.kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
591
|
+
populateTransitiveVars(getInUseByOperationName(def.name && def.name.value)).fragmentSpreads.forEach(function (childFragmentName) {
|
|
592
|
+
allFragmentNamesUsed.add(childFragmentName);
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
else if (def.kind === graphql.Kind.FRAGMENT_DEFINITION &&
|
|
596
|
+
operationCount === 0 &&
|
|
597
|
+
!getInUseByFragmentName(def.name.value).removed) {
|
|
598
|
+
allFragmentNamesUsed.add(def.name.value);
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
allFragmentNamesUsed.forEach(function (fragmentName) {
|
|
602
|
+
populateTransitiveVars(getInUseByFragmentName(fragmentName)).fragmentSpreads.forEach(function (childFragmentName) {
|
|
603
|
+
allFragmentNamesUsed.add(childFragmentName);
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
var fragmentWillBeRemoved = function (fragmentName) { return !!(!allFragmentNamesUsed.has(fragmentName) ||
|
|
607
|
+
getInUseByFragmentName(fragmentName).removed); };
|
|
608
|
+
var enterVisitor = {
|
|
609
|
+
enter: function (node) {
|
|
610
|
+
if (fragmentWillBeRemoved(node.name.value)) {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
};
|
|
615
|
+
return nullIfDocIsEmpty(graphql.visit(docWithoutDirectiveSubtrees, {
|
|
616
|
+
FragmentSpread: enterVisitor,
|
|
617
|
+
FragmentDefinition: enterVisitor,
|
|
618
|
+
OperationDefinition: {
|
|
619
|
+
leave: function (node) {
|
|
620
|
+
if (node.variableDefinitions) {
|
|
621
|
+
var usedVariableNames_1 = populateTransitiveVars(getInUseByOperationName(node.name && node.name.value)).transitiveVars;
|
|
622
|
+
if (usedVariableNames_1.size < node.variableDefinitions.length) {
|
|
623
|
+
return tslib.__assign(tslib.__assign({}, node), { variableDefinitions: node.variableDefinitions.filter(function (varDef) { return usedVariableNames_1.has(varDef.variable.name.value); }) });
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
}));
|
|
525
629
|
}
|
|
526
630
|
var addTypenameToDocument = Object.assign(function (doc) {
|
|
527
631
|
return graphql.visit(doc, {
|
|
528
632
|
SelectionSet: {
|
|
529
633
|
enter: function (node, _key, parent) {
|
|
530
634
|
if (parent &&
|
|
531
|
-
parent.kind ===
|
|
635
|
+
parent.kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
532
636
|
return;
|
|
533
637
|
}
|
|
534
638
|
var selections = node.selections;
|
|
@@ -578,7 +682,7 @@ function getArgumentMatcher(config) {
|
|
|
578
682
|
return function argumentMatcher(argument) {
|
|
579
683
|
return config.some(function (aConfig) {
|
|
580
684
|
return argument.value &&
|
|
581
|
-
argument.value.kind ===
|
|
685
|
+
argument.value.kind === graphql.Kind.VARIABLE &&
|
|
582
686
|
argument.value.name &&
|
|
583
687
|
(aConfig.name === argument.value.name.value ||
|
|
584
688
|
(aConfig.test && aConfig.test(argument)));
|
|
@@ -633,19 +737,6 @@ function removeFragmentSpreadFromDocument(config, doc) {
|
|
|
633
737
|
FragmentDefinition: { enter: enter },
|
|
634
738
|
}));
|
|
635
739
|
}
|
|
636
|
-
function getAllFragmentSpreadsFromSelectionSet(selectionSet) {
|
|
637
|
-
var allFragments = [];
|
|
638
|
-
selectionSet.selections.forEach(function (selection) {
|
|
639
|
-
if ((isField(selection) || isInlineFragment(selection)) &&
|
|
640
|
-
selection.selectionSet) {
|
|
641
|
-
getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(function (frag) { return allFragments.push(frag); });
|
|
642
|
-
}
|
|
643
|
-
else if (selection.kind === 'FragmentSpread') {
|
|
644
|
-
allFragments.push(selection);
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
return allFragments;
|
|
648
|
-
}
|
|
649
740
|
function buildQueryFromSelectionSet(document) {
|
|
650
741
|
var definition = getMainDefinition(document);
|
|
651
742
|
var definitionOperation = definition.operation;
|
|
@@ -669,22 +760,6 @@ function removeClientSetsFromDocument(document) {
|
|
|
669
760
|
remove: true,
|
|
670
761
|
},
|
|
671
762
|
], document);
|
|
672
|
-
if (modifiedDoc) {
|
|
673
|
-
modifiedDoc = graphql.visit(modifiedDoc, {
|
|
674
|
-
FragmentDefinition: {
|
|
675
|
-
enter: function (node) {
|
|
676
|
-
if (node.selectionSet) {
|
|
677
|
-
var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
|
|
678
|
-
return isField(selection) && selection.name.value === '__typename';
|
|
679
|
-
});
|
|
680
|
-
if (isTypenameOnly) {
|
|
681
|
-
return null;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
},
|
|
685
|
-
},
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
763
|
return modifiedDoc;
|
|
689
764
|
}
|
|
690
765
|
|
|
@@ -1181,10 +1256,6 @@ var Concast = (function (_super) {
|
|
|
1181
1256
|
}(zenObservableTs.Observable));
|
|
1182
1257
|
fixObservableSubclass(Concast);
|
|
1183
1258
|
|
|
1184
|
-
function isNonEmptyArray(value) {
|
|
1185
|
-
return Array.isArray(value) && value.length > 0;
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
1259
|
function isExecutionPatchIncrementalResult(value) {
|
|
1189
1260
|
return "incremental" in value;
|
|
1190
1261
|
}
|
|
@@ -1287,6 +1358,7 @@ exports.hasAllDirectives = hasAllDirectives;
|
|
|
1287
1358
|
exports.hasAnyDirectives = hasAnyDirectives;
|
|
1288
1359
|
exports.hasClientExports = hasClientExports;
|
|
1289
1360
|
exports.hasDirectives = hasDirectives;
|
|
1361
|
+
exports.isArray = isArray;
|
|
1290
1362
|
exports.isDocumentNode = isDocumentNode;
|
|
1291
1363
|
exports.isField = isField;
|
|
1292
1364
|
exports.isInlineFragment = isInlineFragment;
|