@apollo/client 3.7.8 → 3.7.9

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 CHANGED
@@ -37,7 +37,7 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
37
37
 
38
38
  - [Apollo Studio](https://www.apollographql.com/studio/develop/) – A free, end-to-end platform for managing your GraphQL lifecycle. Track your GraphQL schemas in a hosted registry to create a source of truth for everything in your graph. Studio provides an IDE (Apollo Explorer) so you can explore data, collaborate on queries, observe usage, and safely make schema changes.
39
39
  - [Apollo Federation](https://www.apollographql.com/apollo-federation) – The industry-standard open architecture for building a distributed graph. Use Apollo’s gateway to compose a unified graph from multiple subgraphs, determine a query plan, and route requests across your services.
40
- - [Apollo Client](https://www.apollographql.com/apollo-client/) – The most popular GraphQL client for the web. Apollo also builds and maintains [Apollo iOS](https://github.com/apollographql/apollo-ios) and [Apollo Android](https://github.com/apollographql/apollo-android).
40
+ - [Apollo Client](https://www.apollographql.com/apollo-client/) – The most popular GraphQL client for the web. Apollo also builds and maintains [Apollo iOS](https://github.com/apollographql/apollo-ios) and [Apollo Kotlin](https://github.com/apollographql/apollo-kotlin).
41
41
  - [Apollo Server](https://www.apollographql.com/docs/apollo-server/) – A production-ready JavaScript GraphQL server that connects to any microservice, API, or database. Compatible with all popular JavaScript frameworks and deployable in serverless environments.
42
42
 
43
43
  ## Learn how to build with Apollo
package/apollo-client.cjs CHANGED
@@ -439,26 +439,20 @@ function getDefaultValues(definition) {
439
439
  return defaultValues;
440
440
  }
441
441
 
442
- function filterInPlace(array, test, context) {
443
- var target = 0;
444
- array.forEach(function (elem, i) {
445
- if (test.call(this, elem, i, array)) {
446
- array[target++] = elem;
447
- }
448
- }, context);
449
- array.length = target;
450
- return array;
442
+ var isArray = Array.isArray;
443
+ function isNonEmptyArray(value) {
444
+ return Array.isArray(value) && value.length > 0;
451
445
  }
452
446
 
453
447
  var TYPENAME_FIELD = {
454
- kind: 'Field',
448
+ kind: graphql.Kind.FIELD,
455
449
  name: {
456
- kind: 'Name',
450
+ kind: graphql.Kind.NAME,
457
451
  value: '__typename',
458
452
  },
459
453
  };
460
454
  function isEmpty(op, fragmentMap) {
461
- return !op || op.selectionSet.selections.every(function (selection) { return selection.kind === 'FragmentSpread' &&
455
+ return !op || op.selectionSet.selections.every(function (selection) { return selection.kind === graphql.Kind.FRAGMENT_SPREAD &&
462
456
  isEmpty(fragmentMap[selection.name.value], fragmentMap); });
463
457
  }
464
458
  function nullIfDocIsEmpty(doc) {
@@ -467,84 +461,190 @@ function nullIfDocIsEmpty(doc) {
467
461
  : doc;
468
462
  }
469
463
  function getDirectiveMatcher(directives) {
470
- return function directiveMatcher(directive) {
471
- return directives.some(function (dir) {
472
- return (dir.name && dir.name === directive.name.value) ||
473
- (dir.test && dir.test(directive));
474
- });
464
+ var nameSet = new Set();
465
+ var tests = [];
466
+ directives.forEach(function (directive) {
467
+ if (directive.name) {
468
+ nameSet.add(directive.name);
469
+ }
470
+ else if (directive.test) {
471
+ tests.push(directive.test);
472
+ }
473
+ });
474
+ return function (directive) { return (nameSet.has(directive.name.value) ||
475
+ tests.some(function (test) { return test(directive); })); };
476
+ }
477
+ function makeInUseGetterFunction(defaultKey) {
478
+ var map = new Map();
479
+ return function inUseGetterFunction(key) {
480
+ if (key === void 0) { key = defaultKey; }
481
+ var inUse = map.get(key);
482
+ if (!inUse) {
483
+ map.set(key, inUse = {
484
+ variables: new Set,
485
+ fragmentSpreads: new Set,
486
+ });
487
+ }
488
+ return inUse;
475
489
  };
476
490
  }
477
491
  function removeDirectivesFromDocument(directives, doc) {
478
- var variablesInUse = Object.create(null);
479
- var variablesToRemove = [];
480
- var fragmentSpreadsInUse = Object.create(null);
481
- var fragmentSpreadsToRemove = [];
482
- var modifiedDoc = nullIfDocIsEmpty(graphql.visit(doc, {
492
+ var getInUseByOperationName = makeInUseGetterFunction("");
493
+ var getInUseByFragmentName = makeInUseGetterFunction("");
494
+ var getInUse = function (ancestors) {
495
+ for (var p = 0, ancestor = void 0; p < ancestors.length && (ancestor = ancestors[p]); ++p) {
496
+ if (isArray(ancestor))
497
+ continue;
498
+ if (ancestor.kind === graphql.Kind.OPERATION_DEFINITION) {
499
+ return getInUseByOperationName(ancestor.name && ancestor.name.value);
500
+ }
501
+ if (ancestor.kind === graphql.Kind.FRAGMENT_DEFINITION) {
502
+ return getInUseByFragmentName(ancestor.name.value);
503
+ }
504
+ }
505
+ __DEV__ && tsInvariant.invariant.error("Could not find operation or fragment");
506
+ return null;
507
+ };
508
+ var operationCount = 0;
509
+ for (var i = doc.definitions.length - 1; i >= 0; --i) {
510
+ if (doc.definitions[i].kind === graphql.Kind.OPERATION_DEFINITION) {
511
+ ++operationCount;
512
+ }
513
+ }
514
+ var directiveMatcher = getDirectiveMatcher(directives);
515
+ var hasRemoveDirective = directives.some(function (directive) { return directive.remove; });
516
+ var shouldRemoveField = function (nodeDirectives) { return (hasRemoveDirective &&
517
+ nodeDirectives &&
518
+ nodeDirectives.some(directiveMatcher)); };
519
+ var originalFragmentDefsByPath = new Map();
520
+ var firstVisitMadeChanges = false;
521
+ var fieldOrInlineFragmentVisitor = {
522
+ enter: function (node) {
523
+ if (shouldRemoveField(node.directives)) {
524
+ firstVisitMadeChanges = true;
525
+ return null;
526
+ }
527
+ },
528
+ };
529
+ var docWithoutDirectiveSubtrees = graphql.visit(doc, {
530
+ Field: fieldOrInlineFragmentVisitor,
531
+ InlineFragment: fieldOrInlineFragmentVisitor,
532
+ VariableDefinition: {
533
+ enter: function () {
534
+ return false;
535
+ },
536
+ },
483
537
  Variable: {
484
- enter: function (node, _key, parent) {
485
- if (parent.kind !== 'VariableDefinition') {
486
- variablesInUse[node.name.value] = true;
538
+ enter: function (node, _key, _parent, _path, ancestors) {
539
+ var inUse = getInUse(ancestors);
540
+ if (inUse) {
541
+ inUse.variables.add(node.name.value);
487
542
  }
488
543
  },
489
544
  },
490
- Field: {
491
- enter: function (node) {
492
- if (directives && node.directives) {
493
- var shouldRemoveField = directives.some(function (directive) { return directive.remove; });
494
- if (shouldRemoveField &&
495
- node.directives &&
496
- node.directives.some(getDirectiveMatcher(directives))) {
497
- if (node.arguments) {
498
- node.arguments.forEach(function (arg) {
499
- if (arg.value.kind === 'Variable') {
500
- variablesToRemove.push({
501
- name: arg.value.name.value,
502
- });
503
- }
504
- });
505
- }
506
- if (node.selectionSet) {
507
- getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(function (frag) {
508
- fragmentSpreadsToRemove.push({
509
- name: frag.name.value,
510
- });
511
- });
512
- }
513
- return null;
514
- }
545
+ FragmentSpread: {
546
+ enter: function (node, _key, _parent, _path, ancestors) {
547
+ if (shouldRemoveField(node.directives)) {
548
+ firstVisitMadeChanges = true;
549
+ return null;
550
+ }
551
+ var inUse = getInUse(ancestors);
552
+ if (inUse) {
553
+ inUse.fragmentSpreads.add(node.name.value);
515
554
  }
516
555
  },
517
556
  },
518
- FragmentSpread: {
519
- enter: function (node) {
520
- fragmentSpreadsInUse[node.name.value] = true;
557
+ FragmentDefinition: {
558
+ enter: function (node, _key, _parent, path) {
559
+ originalFragmentDefsByPath.set(JSON.stringify(path), node);
560
+ },
561
+ leave: function (node, _key, _parent, path) {
562
+ var originalNode = originalFragmentDefsByPath.get(JSON.stringify(path));
563
+ if (node === originalNode) {
564
+ return node;
565
+ }
566
+ if (operationCount > 0 &&
567
+ node.selectionSet.selections.every(function (selection) { return (selection.kind === graphql.Kind.FIELD &&
568
+ selection.name.value === '__typename'); })) {
569
+ getInUseByFragmentName(node.name.value).removed = true;
570
+ firstVisitMadeChanges = true;
571
+ return null;
572
+ }
521
573
  },
522
574
  },
523
575
  Directive: {
524
- enter: function (node) {
525
- if (getDirectiveMatcher(directives)(node)) {
576
+ leave: function (node) {
577
+ if (directiveMatcher(node)) {
578
+ firstVisitMadeChanges = true;
526
579
  return null;
527
580
  }
528
581
  },
529
582
  },
583
+ });
584
+ if (!firstVisitMadeChanges) {
585
+ return doc;
586
+ }
587
+ var populateTransitiveVars = function (inUse) {
588
+ if (!inUse.transitiveVars) {
589
+ inUse.transitiveVars = new Set(inUse.variables);
590
+ if (!inUse.removed) {
591
+ inUse.fragmentSpreads.forEach(function (childFragmentName) {
592
+ populateTransitiveVars(getInUseByFragmentName(childFragmentName)).transitiveVars.forEach(function (varName) {
593
+ inUse.transitiveVars.add(varName);
594
+ });
595
+ });
596
+ }
597
+ }
598
+ return inUse;
599
+ };
600
+ var allFragmentNamesUsed = new Set();
601
+ docWithoutDirectiveSubtrees.definitions.forEach(function (def) {
602
+ if (def.kind === graphql.Kind.OPERATION_DEFINITION) {
603
+ populateTransitiveVars(getInUseByOperationName(def.name && def.name.value)).fragmentSpreads.forEach(function (childFragmentName) {
604
+ allFragmentNamesUsed.add(childFragmentName);
605
+ });
606
+ }
607
+ else if (def.kind === graphql.Kind.FRAGMENT_DEFINITION &&
608
+ operationCount === 0 &&
609
+ !getInUseByFragmentName(def.name.value).removed) {
610
+ allFragmentNamesUsed.add(def.name.value);
611
+ }
612
+ });
613
+ allFragmentNamesUsed.forEach(function (fragmentName) {
614
+ populateTransitiveVars(getInUseByFragmentName(fragmentName)).fragmentSpreads.forEach(function (childFragmentName) {
615
+ allFragmentNamesUsed.add(childFragmentName);
616
+ });
617
+ });
618
+ var fragmentWillBeRemoved = function (fragmentName) { return !!(!allFragmentNamesUsed.has(fragmentName) ||
619
+ getInUseByFragmentName(fragmentName).removed); };
620
+ var enterVisitor = {
621
+ enter: function (node) {
622
+ if (fragmentWillBeRemoved(node.name.value)) {
623
+ return null;
624
+ }
625
+ },
626
+ };
627
+ return nullIfDocIsEmpty(graphql.visit(docWithoutDirectiveSubtrees, {
628
+ FragmentSpread: enterVisitor,
629
+ FragmentDefinition: enterVisitor,
630
+ OperationDefinition: {
631
+ leave: function (node) {
632
+ if (node.variableDefinitions) {
633
+ var usedVariableNames_1 = populateTransitiveVars(getInUseByOperationName(node.name && node.name.value)).transitiveVars;
634
+ if (usedVariableNames_1.size < node.variableDefinitions.length) {
635
+ return tslib.__assign(tslib.__assign({}, node), { variableDefinitions: node.variableDefinitions.filter(function (varDef) { return usedVariableNames_1.has(varDef.variable.name.value); }) });
636
+ }
637
+ }
638
+ },
639
+ },
530
640
  }));
531
- if (modifiedDoc &&
532
- filterInPlace(variablesToRemove, function (v) { return !!v.name && !variablesInUse[v.name]; }).length) {
533
- modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
534
- }
535
- if (modifiedDoc &&
536
- filterInPlace(fragmentSpreadsToRemove, function (fs) { return !!fs.name && !fragmentSpreadsInUse[fs.name]; })
537
- .length) {
538
- modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
539
- }
540
- return modifiedDoc;
541
641
  }
542
642
  var addTypenameToDocument = Object.assign(function (doc) {
543
643
  return graphql.visit(doc, {
544
644
  SelectionSet: {
545
645
  enter: function (node, _key, parent) {
546
646
  if (parent &&
547
- parent.kind === 'OperationDefinition') {
647
+ parent.kind === graphql.Kind.OPERATION_DEFINITION) {
548
648
  return;
549
649
  }
550
650
  var selections = node.selections;
@@ -590,78 +690,6 @@ var connectionRemoveConfig = {
590
690
  function removeConnectionDirectiveFromDocument(doc) {
591
691
  return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
592
692
  }
593
- function getArgumentMatcher(config) {
594
- return function argumentMatcher(argument) {
595
- return config.some(function (aConfig) {
596
- return argument.value &&
597
- argument.value.kind === 'Variable' &&
598
- argument.value.name &&
599
- (aConfig.name === argument.value.name.value ||
600
- (aConfig.test && aConfig.test(argument)));
601
- });
602
- };
603
- }
604
- function removeArgumentsFromDocument(config, doc) {
605
- var argMatcher = getArgumentMatcher(config);
606
- return nullIfDocIsEmpty(graphql.visit(doc, {
607
- OperationDefinition: {
608
- enter: function (node) {
609
- return tslib.__assign(tslib.__assign({}, node), { variableDefinitions: node.variableDefinitions ? node.variableDefinitions.filter(function (varDef) {
610
- return !config.some(function (arg) { return arg.name === varDef.variable.name.value; });
611
- }) : [] });
612
- },
613
- },
614
- Field: {
615
- enter: function (node) {
616
- var shouldRemoveField = config.some(function (argConfig) { return argConfig.remove; });
617
- if (shouldRemoveField) {
618
- var argMatchCount_1 = 0;
619
- if (node.arguments) {
620
- node.arguments.forEach(function (arg) {
621
- if (argMatcher(arg)) {
622
- argMatchCount_1 += 1;
623
- }
624
- });
625
- }
626
- if (argMatchCount_1 === 1) {
627
- return null;
628
- }
629
- }
630
- },
631
- },
632
- Argument: {
633
- enter: function (node) {
634
- if (argMatcher(node)) {
635
- return null;
636
- }
637
- },
638
- },
639
- }));
640
- }
641
- function removeFragmentSpreadFromDocument(config, doc) {
642
- function enter(node) {
643
- if (config.some(function (def) { return def.name === node.name.value; })) {
644
- return null;
645
- }
646
- }
647
- return nullIfDocIsEmpty(graphql.visit(doc, {
648
- FragmentSpread: { enter: enter },
649
- FragmentDefinition: { enter: enter },
650
- }));
651
- }
652
- function getAllFragmentSpreadsFromSelectionSet(selectionSet) {
653
- var allFragments = [];
654
- selectionSet.selections.forEach(function (selection) {
655
- if ((isField(selection) || isInlineFragment(selection)) &&
656
- selection.selectionSet) {
657
- getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(function (frag) { return allFragments.push(frag); });
658
- }
659
- else if (selection.kind === 'FragmentSpread') {
660
- allFragments.push(selection);
661
- }
662
- });
663
- return allFragments;
664
- }
665
693
  function buildQueryFromSelectionSet(document) {
666
694
  var definition = getMainDefinition(document);
667
695
  var definitionOperation = definition.operation;
@@ -685,22 +713,6 @@ function removeClientSetsFromDocument(document) {
685
713
  remove: true,
686
714
  },
687
715
  ], document);
688
- if (modifiedDoc) {
689
- modifiedDoc = graphql.visit(modifiedDoc, {
690
- FragmentDefinition: {
691
- enter: function (node) {
692
- if (node.selectionSet) {
693
- var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
694
- return isField(selection) && selection.name.value === '__typename';
695
- });
696
- if (isTypenameOnly) {
697
- return null;
698
- }
699
- }
700
- },
701
- },
702
- });
703
- }
704
716
  return modifiedDoc;
705
717
  }
706
718
 
@@ -1049,10 +1061,6 @@ var Concast = (function (_super) {
1049
1061
  }(zenObservableTs.Observable));
1050
1062
  fixObservableSubclass(Concast);
1051
1063
 
1052
- function isNonEmptyArray(value) {
1053
- return Array.isArray(value) && value.length > 0;
1054
- }
1055
-
1056
1064
  function isExecutionPatchIncrementalResult(value) {
1057
1065
  return "incremental" in value;
1058
1066
  }
@@ -1345,7 +1353,7 @@ var concat = ApolloLink.concat;
1345
1353
 
1346
1354
  var execute = ApolloLink.execute;
1347
1355
 
1348
- var version = '3.7.8';
1356
+ var version = '3.7.9';
1349
1357
 
1350
1358
  function isNodeResponse(value) {
1351
1359
  return !!value.body;
@@ -2041,7 +2049,6 @@ var hasOwn = Object.prototype.hasOwnProperty;
2041
2049
  function isNullish(value) {
2042
2050
  return value === null || value === void 0;
2043
2051
  }
2044
- var isArray = Array.isArray;
2045
2052
  function defaultDataIdFromObject(_a, context) {
2046
2053
  var __typename = _a.__typename, id = _a.id, _id = _a._id;
2047
2054
  if (typeof __typename === "string") {