@apollo/client 3.7.0-beta.7 → 3.7.0-rc.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.
Files changed (142) hide show
  1. package/apollo-client.cjs +142 -115
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +160 -37
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +160 -37
  7. package/cache/core/cache.d.ts +1 -1
  8. package/cache/core/cache.d.ts.map +1 -1
  9. package/cache/core/cache.js +3 -3
  10. package/cache/core/cache.js.map +1 -1
  11. package/cache/index.d.ts +2 -1
  12. package/cache/index.d.ts.map +1 -1
  13. package/cache/index.js +1 -0
  14. package/cache/index.js.map +1 -1
  15. package/cache/inmemory/fragmentRegistry.d.ts +8 -0
  16. package/cache/inmemory/fragmentRegistry.d.ts.map +1 -0
  17. package/cache/inmemory/fragmentRegistry.js +113 -0
  18. package/cache/inmemory/fragmentRegistry.js.map +1 -0
  19. package/cache/inmemory/helpers.d.ts +9 -3
  20. package/cache/inmemory/helpers.d.ts.map +1 -1
  21. package/cache/inmemory/helpers.js +23 -6
  22. package/cache/inmemory/helpers.js.map +1 -1
  23. package/cache/inmemory/inMemoryCache.d.ts +1 -0
  24. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  25. package/cache/inmemory/inMemoryCache.js +9 -1
  26. package/cache/inmemory/inMemoryCache.js.map +1 -1
  27. package/cache/inmemory/readFromStore.d.ts +2 -1
  28. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  29. package/cache/inmemory/readFromStore.js +10 -14
  30. package/cache/inmemory/readFromStore.js.map +1 -1
  31. package/cache/inmemory/types.d.ts +2 -0
  32. package/cache/inmemory/types.d.ts.map +1 -1
  33. package/cache/inmemory/types.js.map +1 -1
  34. package/cache/inmemory/writeToStore.d.ts +5 -3
  35. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  36. package/cache/inmemory/writeToStore.js +12 -19
  37. package/cache/inmemory/writeToStore.js.map +1 -1
  38. package/core/ApolloClient.js +2 -2
  39. package/core/LocalState.js +1 -1
  40. package/core/ObservableQuery.js +1 -1
  41. package/core/QueryInfo.d.ts +1 -1
  42. package/core/QueryInfo.d.ts.map +1 -1
  43. package/core/QueryInfo.js +2 -2
  44. package/core/QueryInfo.js.map +1 -1
  45. package/core/QueryManager.d.ts.map +1 -1
  46. package/core/QueryManager.js +21 -19
  47. package/core/QueryManager.js.map +1 -1
  48. package/core/core.cjs +28 -26
  49. package/core/core.cjs.map +1 -1
  50. package/core/core.cjs.native.js +28 -26
  51. package/invariantErrorCodes.js +59 -49
  52. package/link/batch-http/batch-http.cjs +2 -2
  53. package/link/batch-http/batch-http.cjs.map +1 -1
  54. package/link/batch-http/batch-http.cjs.native.js +2 -2
  55. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  56. package/link/batch-http/batchHttpLink.js +2 -2
  57. package/link/batch-http/batchHttpLink.js.map +1 -1
  58. package/link/core/ApolloLink.js +1 -1
  59. package/link/core/core.cjs +1 -1
  60. package/link/core/core.cjs.map +1 -1
  61. package/link/core/core.cjs.native.js +1 -1
  62. package/link/http/checkFetcher.js +1 -1
  63. package/link/http/createHttpLink.d.ts.map +1 -1
  64. package/link/http/createHttpLink.js +2 -2
  65. package/link/http/createHttpLink.js.map +1 -1
  66. package/link/http/http.cjs +21 -11
  67. package/link/http/http.cjs.map +1 -1
  68. package/link/http/http.cjs.native.js +21 -11
  69. package/link/http/selectHttpOptionsAndBody.d.ts +2 -0
  70. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  71. package/link/http/selectHttpOptionsAndBody.js +17 -7
  72. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  73. package/link/http/serializeFetchParameter.js +1 -1
  74. package/link/persisted-queries/index.js +2 -2
  75. package/link/persisted-queries/persisted-queries.cjs +2 -2
  76. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  77. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  78. package/link/utils/utils.cjs +1 -1
  79. package/link/utils/utils.cjs.map +1 -1
  80. package/link/utils/utils.cjs.native.js +1 -1
  81. package/link/utils/validateOperation.js +1 -1
  82. package/package.json +13 -13
  83. package/react/context/ApolloConsumer.js +1 -1
  84. package/react/context/ApolloProvider.js +1 -1
  85. package/react/context/context.cjs +2 -2
  86. package/react/context/context.cjs.map +1 -1
  87. package/react/context/context.cjs.native.js +2 -2
  88. package/react/hoc/hoc-utils.js +1 -1
  89. package/react/hoc/hoc.cjs +2 -2
  90. package/react/hoc/hoc.cjs.map +1 -1
  91. package/react/hoc/hoc.cjs.native.js +2 -2
  92. package/react/hoc/withApollo.js +1 -1
  93. package/react/hooks/hooks.cjs +4 -2
  94. package/react/hooks/hooks.cjs.map +1 -1
  95. package/react/hooks/hooks.cjs.native.js +4 -2
  96. package/react/hooks/useApolloClient.js +1 -1
  97. package/react/hooks/useFragment.d.ts +1 -3
  98. package/react/hooks/useFragment.d.ts.map +1 -1
  99. package/react/hooks/useFragment.js.map +1 -1
  100. package/react/hooks/useQuery.d.ts.map +1 -1
  101. package/react/hooks/useQuery.js +1 -1
  102. package/react/hooks/useQuery.js.map +1 -1
  103. package/react/hooks/useSubscription.d.ts.map +1 -1
  104. package/react/hooks/useSubscription.js +2 -0
  105. package/react/hooks/useSubscription.js.map +1 -1
  106. package/react/parser/index.js +5 -5
  107. package/react/parser/parser.cjs +5 -5
  108. package/react/parser/parser.cjs.map +1 -1
  109. package/react/parser/parser.cjs.native.js +5 -5
  110. package/react/types/types.d.ts +1 -1
  111. package/react/types/types.d.ts.map +1 -1
  112. package/react/types/types.js.map +1 -1
  113. package/testing/core/core.cjs +2 -2
  114. package/testing/core/core.cjs.map +1 -1
  115. package/testing/core/core.cjs.native.js +2 -2
  116. package/testing/core/mocking/mockLink.js +2 -2
  117. package/testing/core/mocking/mockLink.js.map +1 -1
  118. package/utilities/globals/globals.cjs +1 -1
  119. package/utilities/globals/globals.cjs.map +1 -1
  120. package/utilities/globals/globals.cjs.native.js +1 -1
  121. package/utilities/globals/index.js +1 -1
  122. package/utilities/graphql/directives.d.ts +3 -1
  123. package/utilities/graphql/directives.d.ts.map +1 -1
  124. package/utilities/graphql/directives.js +12 -11
  125. package/utilities/graphql/directives.js.map +1 -1
  126. package/utilities/graphql/fragments.d.ts +2 -1
  127. package/utilities/graphql/fragments.d.ts.map +1 -1
  128. package/utilities/graphql/fragments.js +9 -5
  129. package/utilities/graphql/fragments.js.map +1 -1
  130. package/utilities/graphql/getFromAST.js +8 -8
  131. package/utilities/graphql/storeUtils.js +1 -1
  132. package/utilities/graphql/transform.d.ts.map +1 -1
  133. package/utilities/graphql/transform.js +3 -5
  134. package/utilities/graphql/transform.js.map +1 -1
  135. package/utilities/index.d.ts +2 -2
  136. package/utilities/index.d.ts.map +1 -1
  137. package/utilities/index.js +1 -1
  138. package/utilities/index.js.map +1 -1
  139. package/utilities/utilities.cjs +35 -30
  140. package/utilities/utilities.cjs.map +1 -1
  141. package/utilities/utilities.cjs.native.js +35 -30
  142. 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, 37);
48
+ __DEV__ ? tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : tsInvariant.invariant(evaledValue !== void 0, 39);
49
49
  }
50
50
  else {
51
51
  evaledValue = ifArgument.value.value;
@@ -53,22 +53,21 @@ function shouldInclude(_a, variables) {
53
53
  return directive.name.value === 'skip' ? !evaledValue : evaledValue;
54
54
  });
55
55
  }
56
- function hasDirectives(names, root) {
56
+ function hasDirectives(names, root, all) {
57
57
  var nameSet = new Set(names);
58
- var nameCount = nameSet.size;
58
+ var uniqueCount = nameSet.size;
59
59
  graphql.visit(root, {
60
60
  Directive: function (node) {
61
- if (nameSet.delete(node.name.value)) {
61
+ if (nameSet.delete(node.name.value) &&
62
+ (!all || !nameSet.size)) {
62
63
  return graphql.BREAK;
63
64
  }
64
65
  },
65
66
  });
66
- return nameSet.size < nameCount;
67
+ return all ? !nameSet.size : nameSet.size < uniqueCount;
67
68
  }
68
69
  function hasClientExports(document) {
69
- return (document &&
70
- hasDirectives(['client'], document) &&
71
- hasDirectives(['export'], document));
70
+ return document && hasDirectives(['client', 'export'], document, true);
72
71
  }
73
72
  function isInclusionDirective(_a) {
74
73
  var value = _a.name.value;
@@ -82,13 +81,13 @@ function getInclusionDirectives(directives) {
82
81
  return;
83
82
  var directiveArguments = directive.arguments;
84
83
  var directiveName = directive.name.value;
85
- __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 38);
84
+ __DEV__ ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 40);
86
85
  var ifArgument = directiveArguments[0];
87
- __DEV__ ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 39);
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', 41);
88
87
  var ifValue = ifArgument.value;
89
88
  __DEV__ ? tsInvariant.invariant(ifValue &&
90
89
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : tsInvariant.invariant(ifValue &&
91
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 40);
90
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 42);
92
91
  result.push({ directive: directive, ifArgument: ifArgument });
93
92
  });
94
93
  }
@@ -101,14 +100,14 @@ function getFragmentQueryDocument(document, fragmentName) {
101
100
  document.definitions.forEach(function (definition) {
102
101
  if (definition.kind === 'OperationDefinition') {
103
102
  throw __DEV__ ? new tsInvariant.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
104
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(41);
103
+ 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new tsInvariant.InvariantError(43);
105
104
  }
106
105
  if (definition.kind === 'FragmentDefinition') {
107
106
  fragments.push(definition);
108
107
  }
109
108
  });
110
109
  if (typeof actualFragmentName === 'undefined') {
111
- __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, 42);
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, 44);
112
111
  actualFragmentName = fragments[0].name.value;
113
112
  }
114
113
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -144,9 +143,13 @@ function getFragmentFromSelection(selection, fragmentMap) {
144
143
  case 'InlineFragment':
145
144
  return selection;
146
145
  case 'FragmentSpread': {
147
- var fragment = fragmentMap && fragmentMap[selection.name.value];
148
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value, ".")) : tsInvariant.invariant(fragment, 43);
149
- return fragment;
146
+ var fragmentName = selection.name.value;
147
+ if (typeof fragmentMap === "function") {
148
+ return fragmentMap(fragmentName);
149
+ }
150
+ var fragment = fragmentMap && fragmentMap[fragmentName];
151
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(fragmentName)) : tsInvariant.invariant(fragment, 45);
152
+ return fragment || null;
150
153
  }
151
154
  default:
152
155
  return null;
@@ -229,7 +232,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
229
232
  else {
230
233
  throw __DEV__ ? new tsInvariant.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
231
234
  'is not supported. Use variables instead of inline arguments to ' +
232
- 'overcome this limitation.') : new tsInvariant.InvariantError(52);
235
+ 'overcome this limitation.') : new tsInvariant.InvariantError(54);
233
236
  }
234
237
  }
235
238
  function storeKeyNameFromField(field, variables) {
@@ -363,16 +366,16 @@ function isInlineFragment(selection) {
363
366
  }
364
367
 
365
368
  function checkDocument(doc) {
366
- __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', 44);
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', 46);
367
370
  var operations = doc.definitions
368
371
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
369
372
  .map(function (definition) {
370
373
  if (definition.kind !== 'OperationDefinition') {
371
- throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(45);
374
+ throw __DEV__ ? new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new tsInvariant.InvariantError(47);
372
375
  }
373
376
  return definition;
374
377
  });
375
- __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 46);
378
+ __DEV__ ? tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : tsInvariant.invariant(operations.length <= 1, 48);
376
379
  return doc;
377
380
  }
378
381
  function getOperationDefinition(doc) {
@@ -391,14 +394,14 @@ function getFragmentDefinitions(doc) {
391
394
  }
392
395
  function getQueryDefinition(doc) {
393
396
  var queryDef = getOperationDefinition(doc);
394
- __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 47);
397
+ __DEV__ ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 49);
395
398
  return queryDef;
396
399
  }
397
400
  function getFragmentDefinition(doc) {
398
- __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', 48);
399
- __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 49);
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', 50);
402
+ __DEV__ ? tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : tsInvariant.invariant(doc.definitions.length <= 1, 51);
400
403
  var fragmentDef = doc.definitions[0];
401
- __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 50);
404
+ __DEV__ ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 52);
402
405
  return fragmentDef;
403
406
  }
404
407
  function getMainDefinition(queryDoc) {
@@ -421,7 +424,7 @@ function getMainDefinition(queryDoc) {
421
424
  if (fragmentDefinition) {
422
425
  return fragmentDefinition;
423
426
  }
424
- throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(51);
427
+ throw __DEV__ ? new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new tsInvariant.InvariantError(53);
425
428
  }
426
429
  function getDefaultValues(definition) {
427
430
  var defaultValues = Object.create(null);
@@ -454,11 +457,9 @@ var TYPENAME_FIELD = {
454
457
  value: '__typename',
455
458
  },
456
459
  };
457
- function isEmpty(op, fragments) {
458
- return op.selectionSet.selections.every(function (selection) {
459
- return selection.kind === 'FragmentSpread' &&
460
- isEmpty(fragments[selection.name.value], fragments);
461
- });
460
+ function isEmpty(op, fragmentMap) {
461
+ return !op || op.selectionSet.selections.every(function (selection) { return selection.kind === 'FragmentSpread' &&
462
+ isEmpty(fragmentMap[selection.name.value], fragmentMap); });
462
463
  }
463
464
  function nullIfDocIsEmpty(doc) {
464
465
  return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))
@@ -1150,7 +1151,7 @@ function validateOperation(operation) {
1150
1151
  for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
1151
1152
  var key = _a[_i];
1152
1153
  if (OPERATION_FIELDS.indexOf(key) < 0) {
1153
- throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: ".concat(key)) : new tsInvariant.InvariantError(24);
1154
+ throw __DEV__ ? new tsInvariant.InvariantError("illegal argument: ".concat(key)) : new tsInvariant.InvariantError(26);
1154
1155
  }
1155
1156
  }
1156
1157
  return operation;
@@ -1273,7 +1274,7 @@ var ApolloLink = (function () {
1273
1274
  return ApolloLink.concat(this, next);
1274
1275
  };
1275
1276
  ApolloLink.prototype.request = function (operation, forward) {
1276
- throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(19);
1277
+ throw __DEV__ ? new tsInvariant.InvariantError('request is not implemented') : new tsInvariant.InvariantError(21);
1277
1278
  };
1278
1279
  ApolloLink.prototype.onError = function (error, observer) {
1279
1280
  if (observer && observer.error) {
@@ -1299,7 +1300,7 @@ var concat = ApolloLink.concat;
1299
1300
 
1300
1301
  var execute = ApolloLink.execute;
1301
1302
 
1302
- var version = '3.7.0-beta.7';
1303
+ var version = '3.7.0-rc.0';
1303
1304
 
1304
1305
  function isNodeResponse(value) {
1305
1306
  return !!value.body;
@@ -1604,7 +1605,7 @@ var serializeFetchParameter = function (p, label) {
1604
1605
  serialized = JSON.stringify(p);
1605
1606
  }
1606
1607
  catch (e) {
1607
- var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new tsInvariant.InvariantError(21);
1608
+ var parseError = __DEV__ ? new tsInvariant.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new tsInvariant.InvariantError(23);
1608
1609
  parseError.parseError = e;
1609
1610
  throw parseError;
1610
1611
  }
@@ -1614,6 +1615,7 @@ var serializeFetchParameter = function (p, label) {
1614
1615
  var defaultHttpOptions = {
1615
1616
  includeQuery: true,
1616
1617
  includeExtensions: false,
1618
+ preserveHeaderCase: false,
1617
1619
  };
1618
1620
  var defaultHeaders = {
1619
1621
  accept: '*/*',
@@ -1645,12 +1647,13 @@ function selectHttpOptionsAndBodyInternal(operation, printer) {
1645
1647
  var options = {};
1646
1648
  var http = {};
1647
1649
  configs.forEach(function (config) {
1648
- options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), headersToLowerCase(config.headers)) });
1650
+ options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), config.headers) });
1649
1651
  if (config.credentials) {
1650
1652
  options.credentials = config.credentials;
1651
1653
  }
1652
1654
  http = tslib.__assign(tslib.__assign({}, http), config.http);
1653
1655
  });
1656
+ options.headers = removeDuplicateHeaders(options.headers, http.preserveHeaderCase);
1654
1657
  var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
1655
1658
  var body = { operationName: operationName, variables: variables };
1656
1659
  if (http.includeExtensions)
@@ -1662,20 +1665,28 @@ function selectHttpOptionsAndBodyInternal(operation, printer) {
1662
1665
  body: body,
1663
1666
  };
1664
1667
  }
1665
- function headersToLowerCase(headers) {
1666
- if (headers) {
1667
- var normalized_1 = Object.create(null);
1668
+ function removeDuplicateHeaders(headers, preserveHeaderCase) {
1669
+ if (!preserveHeaderCase) {
1670
+ var normalizedHeaders_1 = Object.create(null);
1668
1671
  Object.keys(Object(headers)).forEach(function (name) {
1669
- normalized_1[name.toLowerCase()] = headers[name];
1672
+ normalizedHeaders_1[name.toLowerCase()] = headers[name];
1670
1673
  });
1671
- return normalized_1;
1674
+ return normalizedHeaders_1;
1672
1675
  }
1673
- return headers;
1676
+ var headerData = Object.create(null);
1677
+ Object.keys(Object(headers)).forEach(function (name) {
1678
+ headerData[name.toLowerCase()] = { originalName: name, value: headers[name] };
1679
+ });
1680
+ var normalizedHeaders = Object.create(null);
1681
+ Object.keys(headerData).forEach(function (name) {
1682
+ normalizedHeaders[headerData[name].originalName] = headerData[name].value;
1683
+ });
1684
+ return normalizedHeaders;
1674
1685
  }
1675
1686
 
1676
1687
  var checkFetcher = function (fetcher) {
1677
1688
  if (!fetcher && typeof fetch === 'undefined') {
1678
- throw __DEV__ ? new tsInvariant.InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ") : new tsInvariant.InvariantError(20);
1689
+ throw __DEV__ ? new tsInvariant.InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ") : new tsInvariant.InvariantError(22);
1679
1690
  }
1680
1691
  };
1681
1692
 
@@ -1746,12 +1757,12 @@ function rewriteURIForGET(chosenURI, body) {
1746
1757
  var backupFetch = maybe(function () { return fetch; });
1747
1758
  var createHttpLink = function (linkOptions) {
1748
1759
  if (linkOptions === void 0) { linkOptions = {}; }
1749
- var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, preferredFetch = linkOptions.fetch, _b = linkOptions.print, print = _b === void 0 ? defaultPrinter : _b, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, _c = linkOptions.includeUnusedVariables, includeUnusedVariables = _c === void 0 ? false : _c, requestOptions = tslib.__rest(linkOptions, ["uri", "fetch", "print", "includeExtensions", "useGETForQueries", "includeUnusedVariables"]);
1760
+ var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, preferredFetch = linkOptions.fetch, _b = linkOptions.print, print = _b === void 0 ? defaultPrinter : _b, includeExtensions = linkOptions.includeExtensions, preserveHeaderCase = linkOptions.preserveHeaderCase, useGETForQueries = linkOptions.useGETForQueries, _c = linkOptions.includeUnusedVariables, includeUnusedVariables = _c === void 0 ? false : _c, requestOptions = tslib.__rest(linkOptions, ["uri", "fetch", "print", "includeExtensions", "preserveHeaderCase", "useGETForQueries", "includeUnusedVariables"]);
1750
1761
  if (__DEV__) {
1751
1762
  checkFetcher(preferredFetch || backupFetch);
1752
1763
  }
1753
1764
  var linkConfig = {
1754
- http: { includeExtensions: includeExtensions },
1765
+ http: { includeExtensions: includeExtensions, preserveHeaderCase: preserveHeaderCase },
1755
1766
  options: requestOptions.fetchOptions,
1756
1767
  credentials: requestOptions.credentials,
1757
1768
  headers: requestOptions.headers,
@@ -1881,6 +1892,9 @@ var ApolloCache = (function () {
1881
1892
  ApolloCache.prototype.transformDocument = function (document) {
1882
1893
  return document;
1883
1894
  };
1895
+ ApolloCache.prototype.transformForLink = function (document) {
1896
+ return document;
1897
+ };
1884
1898
  ApolloCache.prototype.identify = function (object) {
1885
1899
  return;
1886
1900
  };
@@ -1890,9 +1904,6 @@ var ApolloCache = (function () {
1890
1904
  ApolloCache.prototype.modify = function (options) {
1891
1905
  return false;
1892
1906
  };
1893
- ApolloCache.prototype.transformForLink = function (document) {
1894
- return document;
1895
- };
1896
1907
  ApolloCache.prototype.readQuery = function (options, optimistic) {
1897
1908
  if (optimistic === void 0) { optimistic = !!options.optimistic; }
1898
1909
  return this.read(tslib.__assign(tslib.__assign({}, options), { rootId: options.id || 'ROOT_QUERY', optimistic: optimistic }));
@@ -1972,18 +1983,23 @@ var MissingFieldError = (function (_super) {
1972
1983
  }(Error));
1973
1984
 
1974
1985
  var hasOwn = Object.prototype.hasOwnProperty;
1986
+ function isNullish(value) {
1987
+ return value === null || value === void 0;
1988
+ }
1989
+ var isArray = Array.isArray;
1975
1990
  function defaultDataIdFromObject(_a, context) {
1976
1991
  var __typename = _a.__typename, id = _a.id, _id = _a._id;
1977
1992
  if (typeof __typename === "string") {
1978
1993
  if (context) {
1979
1994
  context.keyObject =
1980
- id !== void 0 ? { id: id } :
1981
- _id !== void 0 ? { _id: _id } :
1995
+ !isNullish(id) ? { id: id } :
1996
+ !isNullish(_id) ? { _id: _id } :
1982
1997
  void 0;
1983
1998
  }
1984
- if (id === void 0)
1999
+ if (isNullish(id) && !isNullish(_id)) {
1985
2000
  id = _id;
1986
- if (id !== void 0) {
2001
+ }
2002
+ if (!isNullish(id)) {
1987
2003
  return "".concat(__typename, ":").concat((typeof id === "number" ||
1988
2004
  typeof id === "string") ? id : JSON.stringify(id));
1989
2005
  }
@@ -2036,7 +2052,19 @@ function storeValueIsStoreObject(value) {
2036
2052
  function makeProcessedFieldsMerger() {
2037
2053
  return new DeepMerger;
2038
2054
  }
2039
- var isArray = function (a) { return Array.isArray(a); };
2055
+ function extractFragmentContext(document, fragments) {
2056
+ var fragmentMap = createFragmentMap(getFragmentDefinitions(document));
2057
+ return {
2058
+ fragmentMap: fragmentMap,
2059
+ lookupFragment: function (name) {
2060
+ var def = fragmentMap[name];
2061
+ if (!def && fragments) {
2062
+ def = fragments.lookup(name);
2063
+ }
2064
+ return def || null;
2065
+ },
2066
+ };
2067
+ }
2040
2068
 
2041
2069
  var DELETE = Object.create(null);
2042
2070
  var delModifier = function () { return DELETE; };
@@ -2676,15 +2704,7 @@ var StoreReader = (function () {
2676
2704
  selectionSet: getMainDefinition(query).selectionSet,
2677
2705
  objectOrReference: rootRef,
2678
2706
  enclosingRef: rootRef,
2679
- context: {
2680
- store: store,
2681
- query: query,
2682
- policies: policies,
2683
- variables: variables,
2684
- varString: canonicalStringify(variables),
2685
- canonizeResults: canonizeResults,
2686
- fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
2687
- },
2707
+ context: tslib.__assign({ store: store, query: query, policies: policies, variables: variables, varString: canonicalStringify(variables), canonizeResults: canonizeResults }, extractFragmentContext(query, this.config.fragments)),
2688
2708
  });
2689
2709
  var missing;
2690
2710
  if (execResult.missing) {
@@ -2785,7 +2805,10 @@ var StoreReader = (function () {
2785
2805
  }
2786
2806
  }
2787
2807
  else {
2788
- var fragment = getFragmentFromSelection(selection, context.fragmentMap);
2808
+ var fragment = getFragmentFromSelection(selection, context.lookupFragment);
2809
+ if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
2810
+ throw __DEV__ ? new tsInvariant.InvariantError("No fragment named ".concat(selection.name.value)) : new tsInvariant.InvariantError(5);
2811
+ }
2789
2812
  if (fragment && policies.fragmentMatches(fragment, typename)) {
2790
2813
  fragment.selectionSet.selections.forEach(workSet.add, workSet);
2791
2814
  }
@@ -2865,7 +2888,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
2865
2888
  var workSet_1 = new Set([fieldValue]);
2866
2889
  workSet_1.forEach(function (value) {
2867
2890
  if (isNonNullObject(value)) {
2868
- __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type ".concat(getTypenameFromStoreObject(store, value), " returned for query field ").concat(field.name.value)) : tsInvariant.invariant(!isReference(value), 5);
2891
+ __DEV__ ? tsInvariant.invariant(!isReference(value), "Missing selection set for object of type ".concat(getTypenameFromStoreObject(store, value), " returned for query field ").concat(field.name.value)) : tsInvariant.invariant(!isReference(value), 6);
2869
2892
  Object.values(value).forEach(workSet_1.add, workSet_1);
2870
2893
  }
2871
2894
  });
@@ -3468,9 +3491,10 @@ function getContextFlavor(context, clientOnly, deferred) {
3468
3491
  return flavored;
3469
3492
  }
3470
3493
  var StoreWriter = (function () {
3471
- function StoreWriter(cache, reader) {
3494
+ function StoreWriter(cache, reader, fragments) {
3472
3495
  this.cache = cache;
3473
3496
  this.reader = reader;
3497
+ this.fragments = fragments;
3474
3498
  }
3475
3499
  StoreWriter.prototype.writeToStore = function (store, _a) {
3476
3500
  var _this = this;
@@ -3478,21 +3502,9 @@ var StoreWriter = (function () {
3478
3502
  var operationDefinition = getOperationDefinition(query);
3479
3503
  var merger = makeProcessedFieldsMerger();
3480
3504
  variables = tslib.__assign(tslib.__assign({}, getDefaultValues(operationDefinition)), variables);
3481
- var context = {
3482
- store: store,
3483
- written: Object.create(null),
3484
- merge: function (existing, incoming) {
3505
+ var context = tslib.__assign(tslib.__assign({ store: store, written: Object.create(null), merge: function (existing, incoming) {
3485
3506
  return merger.merge(existing, incoming);
3486
- },
3487
- variables: variables,
3488
- varString: canonicalStringify(variables),
3489
- fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
3490
- overwrite: !!overwrite,
3491
- incomingById: new Map,
3492
- clientOnly: false,
3493
- deferred: false,
3494
- flavors: new Map,
3495
- };
3507
+ }, variables: variables, varString: canonicalStringify(variables) }, extractFragmentContext(query, this.fragments)), { overwrite: !!overwrite, incomingById: new Map, clientOnly: false, deferred: false, flavors: new Map });
3496
3508
  var ref = this.processSelectionSet({
3497
3509
  result: result || Object.create(null),
3498
3510
  dataId: dataId,
@@ -3501,7 +3513,7 @@ var StoreWriter = (function () {
3501
3513
  context: context,
3502
3514
  });
3503
3515
  if (!isReference(ref)) {
3504
- throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new tsInvariant.InvariantError(6);
3516
+ throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new tsInvariant.InvariantError(7);
3505
3517
  }
3506
3518
  context.incomingById.forEach(function (_a, dataId) {
3507
3519
  var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
@@ -3708,7 +3720,10 @@ var StoreWriter = (function () {
3708
3720
  fieldMap.set(selection, getContextFlavor(context, clientOnly, deferred));
3709
3721
  }
3710
3722
  else {
3711
- var fragment = getFragmentFromSelection(selection, context.fragmentMap);
3723
+ var fragment = getFragmentFromSelection(selection, context.lookupFragment);
3724
+ if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
3725
+ throw __DEV__ ? new tsInvariant.InvariantError("No fragment named ".concat(selection.name.value)) : new tsInvariant.InvariantError(8);
3726
+ }
3712
3727
  if (fragment &&
3713
3728
  policies.fragmentMatches(fragment, typename, result, context.variables)) {
3714
3729
  flatten(fragment.selectionSet, getContextFlavor(context, clientOnly, deferred));
@@ -3880,6 +3895,7 @@ var InMemoryCache = (function (_super) {
3880
3895
  InMemoryCache.prototype.resetResultCache = function (resetResultIdentities) {
3881
3896
  var _this = this;
3882
3897
  var previousReader = this.storeReader;
3898
+ var fragments = this.config.fragments;
3883
3899
  this.storeWriter = new StoreWriter(this, this.storeReader = new StoreReader({
3884
3900
  cache: this,
3885
3901
  addTypename: this.addTypename,
@@ -3888,7 +3904,8 @@ var InMemoryCache = (function (_super) {
3888
3904
  canon: resetResultIdentities
3889
3905
  ? void 0
3890
3906
  : previousReader && previousReader.canon,
3891
- }));
3907
+ fragments: fragments,
3908
+ }), fragments);
3892
3909
  this.maybeBroadcastWatch = optimism.wrap(function (c, options) {
3893
3910
  return _this.broadcastWatch(c, options);
3894
3911
  }, {
@@ -4115,6 +4132,12 @@ var InMemoryCache = (function (_super) {
4115
4132
  }
4116
4133
  return document;
4117
4134
  };
4135
+ InMemoryCache.prototype.transformForLink = function (document) {
4136
+ var fragments = this.config.fragments;
4137
+ return fragments
4138
+ ? fragments.transform(document)
4139
+ : document;
4140
+ };
4118
4141
  InMemoryCache.prototype.broadcastWatches = function (options) {
4119
4142
  var _this = this;
4120
4143
  if (!this.txCount) {
@@ -4541,7 +4564,7 @@ var ObservableQuery = (function (_super) {
4541
4564
  pollingInfo.interval === pollInterval) {
4542
4565
  return;
4543
4566
  }
4544
- __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 10);
4567
+ __DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 12);
4545
4568
  var info = pollingInfo || (this.pollingInfo = {});
4546
4569
  info.interval = pollInterval;
4547
4570
  var maybeFetch = function () {
@@ -4853,7 +4876,7 @@ var LocalState = (function () {
4853
4876
  }
4854
4877
  else {
4855
4878
  fragment = fragmentMap[selection.name.value];
4856
- __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value)) : tsInvariant.invariant(fragment, 9);
4879
+ __DEV__ ? tsInvariant.invariant(fragment, "No fragment named ".concat(selection.name.value)) : tsInvariant.invariant(fragment, 11);
4857
4880
  }
4858
4881
  if (fragment && fragment.typeCondition) {
4859
4882
  typeCondition = fragment.typeCondition.name.value;
@@ -5136,7 +5159,7 @@ var QueryInfo = (function () {
5136
5159
  equality.equal(variables, lastWrite.variables) &&
5137
5160
  equality.equal(result.data, lastWrite.result.data));
5138
5161
  };
5139
- QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
5162
+ QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
5140
5163
  var _this = this;
5141
5164
  var graphQLErrors = isNonEmptyArray(result.errors)
5142
5165
  ? result.errors.slice(0)
@@ -5170,7 +5193,7 @@ var QueryInfo = (function () {
5170
5193
  this.cache.performTransaction(function (cache) {
5171
5194
  if (_this.shouldWrite(result, options.variables)) {
5172
5195
  cache.writeQuery({
5173
- query: _this.document,
5196
+ query: document,
5174
5197
  data: result.data,
5175
5198
  variables: options.variables,
5176
5199
  overwrite: cacheWriteBehavior === 1,
@@ -5262,7 +5285,7 @@ var QueryManager = (function () {
5262
5285
  this.queries.forEach(function (_info, queryId) {
5263
5286
  _this.stopQueryNoBroadcast(queryId);
5264
5287
  });
5265
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(11));
5288
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(13));
5266
5289
  };
5267
5290
  QueryManager.prototype.cancelPendingFetches = function (error) {
5268
5291
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -5272,22 +5295,23 @@ var QueryManager = (function () {
5272
5295
  var _b, _c;
5273
5296
  var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
5274
5297
  return tslib.__awaiter(this, void 0, void 0, function () {
5275
- var mutationId, mutationStoreValue, self;
5276
- return tslib.__generator(this, function (_h) {
5277
- switch (_h.label) {
5298
+ var mutationId, _h, document, hasClientExports, mutationStoreValue, self;
5299
+ return tslib.__generator(this, function (_j) {
5300
+ switch (_j.label) {
5278
5301
  case 0:
5279
- __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
5302
+ __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 14);
5280
5303
  __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
5281
5304
  fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") : tsInvariant.invariant(fetchPolicy === 'network-only' ||
5282
- fetchPolicy === 'no-cache', 13);
5305
+ fetchPolicy === 'no-cache', 15);
5283
5306
  mutationId = this.generateMutationId();
5284
- mutation = this.transform(mutation).document;
5307
+ _h = this.transform(mutation), document = _h.document, hasClientExports = _h.hasClientExports;
5308
+ mutation = this.cache.transformForLink(document);
5285
5309
  variables = this.getVariables(mutation, variables);
5286
- if (!this.transform(mutation).hasClientExports) return [3, 2];
5310
+ if (!hasClientExports) return [3, 2];
5287
5311
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
5288
5312
  case 1:
5289
- variables = (_h.sent());
5290
- _h.label = 2;
5313
+ variables = (_j.sent());
5314
+ _j.label = 2;
5291
5315
  case 2:
5292
5316
  mutationStoreValue = this.mutationStore &&
5293
5317
  (this.mutationStore[mutationId] = {
@@ -5508,9 +5532,9 @@ var QueryManager = (function () {
5508
5532
  var transformCache = this.transformCache;
5509
5533
  if (!transformCache.has(document)) {
5510
5534
  var transformed = this.cache.transformDocument(document);
5511
- var forLink = removeConnectionDirectiveFromDocument(this.cache.transformForLink(transformed));
5535
+ var noConnection = removeConnectionDirectiveFromDocument(transformed);
5512
5536
  var clientQuery = this.localState.clientQuery(transformed);
5513
- var serverQuery = forLink && this.localState.serverQuery(forLink);
5537
+ var serverQuery = noConnection && this.localState.serverQuery(noConnection);
5514
5538
  var cacheEntry_1 = {
5515
5539
  document: transformed,
5516
5540
  hasClientExports: hasClientExports(transformed),
@@ -5564,10 +5588,10 @@ var QueryManager = (function () {
5564
5588
  var _this = this;
5565
5589
  if (queryId === void 0) { queryId = this.generateQueryId(); }
5566
5590
  __DEV__ ? tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
5567
- 'in the query option.') : tsInvariant.invariant(options.query, 14);
5568
- __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 15);
5569
- __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 16);
5570
- __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 17);
5591
+ 'in the query option.') : tsInvariant.invariant(options.query, 16);
5592
+ __DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 17);
5593
+ __DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 18);
5594
+ __DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 19);
5571
5595
  return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
5572
5596
  };
5573
5597
  QueryManager.prototype.generateQueryId = function () {
@@ -5592,7 +5616,7 @@ var QueryManager = (function () {
5592
5616
  if (options === void 0) { options = {
5593
5617
  discardWatches: true,
5594
5618
  }; }
5595
- this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(18));
5619
+ this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(20));
5596
5620
  this.queries.forEach(function (queryInfo) {
5597
5621
  if (queryInfo.observableQuery) {
5598
5622
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -5814,7 +5838,8 @@ var QueryManager = (function () {
5814
5838
  QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
5815
5839
  var requestId = queryInfo.lastRequestId = this.generateRequestId();
5816
5840
  options = cloneDeep(options);
5817
- return asyncMap(this.getObservableFromLink(queryInfo.document, options.context, options.variables), function (result) {
5841
+ var linkDocument = this.cache.transformForLink(this.transform(queryInfo.document).document);
5842
+ return asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
5818
5843
  var graphQLErrors = isNonEmptyArray(result.errors)
5819
5844
  ? result.errors.slice(0)
5820
5845
  : [];
@@ -5832,7 +5857,7 @@ var QueryManager = (function () {
5832
5857
  graphQLErrors: graphQLErrors,
5833
5858
  }));
5834
5859
  }
5835
- queryInfo.markResult(result, options, cacheWriteBehavior);
5860
+ queryInfo.markResult(result, linkDocument, options, cacheWriteBehavior);
5836
5861
  queryInfo.markReady();
5837
5862
  }
5838
5863
  var aqr = {
@@ -6092,7 +6117,7 @@ var ApolloClient = (function () {
6092
6117
  if (!cache) {
6093
6118
  throw __DEV__ ? new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
6094
6119
  "in the options object. \n" +
6095
- "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(7);
6120
+ "For more information, please visit: https://go.apollo.dev/c/docs") : new tsInvariant.InvariantError(9);
6096
6121
  }
6097
6122
  this.link = link;
6098
6123
  this.cache = cache;
@@ -6189,7 +6214,7 @@ var ApolloClient = (function () {
6189
6214
  __DEV__ ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
6190
6215
  'client.query can only return a single result. Please use client.watchQuery ' +
6191
6216
  'to receive multiple results from the cache and the network, or consider ' +
6192
- 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 8);
6217
+ 'using a different fetchPolicy, such as cache-first or network-only.') : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 10);
6193
6218
  if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
6194
6219
  options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
6195
6220
  }
@@ -6325,7 +6350,7 @@ var ApolloConsumer = function (props) {
6325
6350
  var ApolloContext = getApolloContext();
6326
6351
  return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
6327
6352
  __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
6328
- 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 25);
6353
+ 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 27);
6329
6354
  return props.children(context.client);
6330
6355
  }));
6331
6356
  };
@@ -6339,7 +6364,7 @@ var ApolloProvider = function (_a) {
6339
6364
  context = Object.assign({}, context, { client: client });
6340
6365
  }
6341
6366
  __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
6342
- 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 26);
6367
+ 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 28);
6343
6368
  return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
6344
6369
  }));
6345
6370
  };
@@ -6349,7 +6374,7 @@ function useApolloClient(override) {
6349
6374
  var client = override || context.client;
6350
6375
  __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
6351
6376
  'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
6352
- 'instance in via options.') : tsInvariant.invariant(!!client, 29);
6377
+ 'instance in via options.') : tsInvariant.invariant(!!client, 31);
6353
6378
  return client;
6354
6379
  }
6355
6380
 
@@ -6427,7 +6452,7 @@ function parser(document) {
6427
6452
  var variables, type, name;
6428
6453
  __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of ".concat(document, " passed to parser was not a valid GraphQL ") +
6429
6454
  "DocumentNode. You may need to use 'graphql-tag' or another method " +
6430
- "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 30);
6455
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 32);
6431
6456
  var fragments = [];
6432
6457
  var queries = [];
6433
6458
  var mutations = [];
@@ -6455,11 +6480,11 @@ function parser(document) {
6455
6480
  __DEV__ ? tsInvariant.invariant(!fragments.length ||
6456
6481
  (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
6457
6482
  "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
6458
- (queries.length || mutations.length || subscriptions.length), 31);
6483
+ (queries.length || mutations.length || subscriptions.length), 33);
6459
6484
  __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
6460
6485
  "".concat(document, " had ").concat(queries.length, " queries, ").concat(subscriptions.length, " ") +
6461
6486
  "subscriptions and ".concat(mutations.length, " mutations. ") +
6462
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 32);
6487
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 34);
6463
6488
  type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
6464
6489
  if (!queries.length && !mutations.length)
6465
6490
  type = exports.DocumentType.Subscription;
@@ -6470,7 +6495,7 @@ function parser(document) {
6470
6495
  : subscriptions;
6471
6496
  __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. ".concat(document, " had ") +
6472
6497
  "".concat(definitions.length, " definitions. ") +
6473
- "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 33);
6498
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 35);
6474
6499
  var definition = definitions[0];
6475
6500
  variables = definition.variableDefinitions || [];
6476
6501
  if (definition.name && definition.name.kind === 'Name') {
@@ -6488,7 +6513,7 @@ function verifyDocumentType(document, type) {
6488
6513
  var requiredOperationName = operationName(type);
6489
6514
  var usedOperationName = operationName(operation.type);
6490
6515
  __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a ".concat(requiredOperationName, " requires a graphql ") +
6491
- "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
6516
+ "".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 36);
6492
6517
  }
6493
6518
 
6494
6519
  var hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -6651,7 +6676,7 @@ var InternalState = (function () {
6651
6676
  InternalState.prototype.createWatchQueryOptions = function (_a) {
6652
6677
  var _b;
6653
6678
  if (_a === void 0) { _a = {}; }
6654
- var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; _a.defaultOptions; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
6679
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.defaultOptions; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "defaultOptions"]);
6655
6680
  var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
6656
6681
  if (this.renderPromises &&
6657
6682
  (watchQueryOptions.fetchPolicy === 'network-only' ||
@@ -6998,12 +7023,14 @@ function useSubscription(subscription, options) {
6998
7023
  });
6999
7024
  },
7000
7025
  error: function (error) {
7026
+ var _a, _b;
7001
7027
  setResult({
7002
7028
  loading: false,
7003
7029
  data: void 0,
7004
7030
  error: error,
7005
7031
  variables: options === null || options === void 0 ? void 0 : options.variables,
7006
7032
  });
7033
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
7007
7034
  },
7008
7035
  complete: function () {
7009
7036
  var _a, _b;