@apollo/client 3.7.0-beta.7 → 3.7.0-beta.8

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
@@ -18,7 +18,7 @@ function shouldInclude(_a, variables) {
18
18
  var evaledValue = false;
19
19
  if (ifArgument.value.kind === 'Variable') {
20
20
  evaledValue = variables && variables[ifArgument.value.name.value];
21
- __DEV__ ? globals.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : globals.invariant(evaledValue !== void 0, 37);
21
+ __DEV__ ? globals.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : globals.invariant(evaledValue !== void 0, 39);
22
22
  }
23
23
  else {
24
24
  evaledValue = ifArgument.value.value;
@@ -35,22 +35,23 @@ function getDirectiveNames(root) {
35
35
  });
36
36
  return names;
37
37
  }
38
- function hasDirectives(names, root) {
38
+ var hasAnyDirectives = function (names, root) { return hasDirectives(names, root, false); };
39
+ var hasAllDirectives = function (names, root) { return hasDirectives(names, root, true); };
40
+ function hasDirectives(names, root, all) {
39
41
  var nameSet = new Set(names);
40
- var nameCount = nameSet.size;
42
+ var uniqueCount = nameSet.size;
41
43
  graphql.visit(root, {
42
44
  Directive: function (node) {
43
- if (nameSet.delete(node.name.value)) {
45
+ if (nameSet.delete(node.name.value) &&
46
+ (!all || !nameSet.size)) {
44
47
  return graphql.BREAK;
45
48
  }
46
49
  },
47
50
  });
48
- return nameSet.size < nameCount;
51
+ return all ? !nameSet.size : nameSet.size < uniqueCount;
49
52
  }
50
53
  function hasClientExports(document) {
51
- return (document &&
52
- hasDirectives(['client'], document) &&
53
- hasDirectives(['export'], document));
54
+ return document && hasDirectives(['client', 'export'], document, true);
54
55
  }
55
56
  function isInclusionDirective(_a) {
56
57
  var value = _a.name.value;
@@ -64,13 +65,13 @@ function getInclusionDirectives(directives) {
64
65
  return;
65
66
  var directiveArguments = directive.arguments;
66
67
  var directiveName = directive.name.value;
67
- __DEV__ ? globals.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : globals.invariant(directiveArguments && directiveArguments.length === 1, 38);
68
+ __DEV__ ? globals.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : globals.invariant(directiveArguments && directiveArguments.length === 1, 40);
68
69
  var ifArgument = directiveArguments[0];
69
- __DEV__ ? globals.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : globals.invariant(ifArgument.name && ifArgument.name.value === 'if', 39);
70
+ __DEV__ ? globals.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : globals.invariant(ifArgument.name && ifArgument.name.value === 'if', 41);
70
71
  var ifValue = ifArgument.value;
71
72
  __DEV__ ? globals.invariant(ifValue &&
72
73
  (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : globals.invariant(ifValue &&
73
- (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 40);
74
+ (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 42);
74
75
  result.push({ directive: directive, ifArgument: ifArgument });
75
76
  });
76
77
  }
@@ -83,14 +84,14 @@ function getFragmentQueryDocument(document, fragmentName) {
83
84
  document.definitions.forEach(function (definition) {
84
85
  if (definition.kind === 'OperationDefinition') {
85
86
  throw __DEV__ ? new globals.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
86
- 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new globals.InvariantError(41);
87
+ 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new globals.InvariantError(43);
87
88
  }
88
89
  if (definition.kind === 'FragmentDefinition') {
89
90
  fragments.push(definition);
90
91
  }
91
92
  });
92
93
  if (typeof actualFragmentName === 'undefined') {
93
- __DEV__ ? globals.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : globals.invariant(fragments.length === 1, 42);
94
+ __DEV__ ? globals.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : globals.invariant(fragments.length === 1, 44);
94
95
  actualFragmentName = fragments[0].name.value;
95
96
  }
96
97
  var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
@@ -126,9 +127,13 @@ function getFragmentFromSelection(selection, fragmentMap) {
126
127
  case 'InlineFragment':
127
128
  return selection;
128
129
  case 'FragmentSpread': {
129
- var fragment = fragmentMap && fragmentMap[selection.name.value];
130
- __DEV__ ? globals.invariant(fragment, "No fragment named ".concat(selection.name.value, ".")) : globals.invariant(fragment, 43);
131
- return fragment;
130
+ var fragmentName = selection.name.value;
131
+ if (typeof fragmentMap === "function") {
132
+ return fragmentMap(fragmentName);
133
+ }
134
+ var fragment = fragmentMap && fragmentMap[fragmentName];
135
+ __DEV__ ? globals.invariant(fragment, "No fragment named ".concat(fragmentName)) : globals.invariant(fragment, 45);
136
+ return fragment || null;
132
137
  }
133
138
  default:
134
139
  return null;
@@ -211,7 +216,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
211
216
  else {
212
217
  throw __DEV__ ? new globals.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
213
218
  'is not supported. Use variables instead of inline arguments to ' +
214
- 'overcome this limitation.') : new globals.InvariantError(52);
219
+ 'overcome this limitation.') : new globals.InvariantError(54);
215
220
  }
216
221
  }
217
222
  function storeKeyNameFromField(field, variables) {
@@ -345,16 +350,16 @@ function isInlineFragment(selection) {
345
350
  }
346
351
 
347
352
  function checkDocument(doc) {
348
- __DEV__ ? globals.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") : globals.invariant(doc && doc.kind === 'Document', 44);
353
+ __DEV__ ? globals.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") : globals.invariant(doc && doc.kind === 'Document', 46);
349
354
  var operations = doc.definitions
350
355
  .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
351
356
  .map(function (definition) {
352
357
  if (definition.kind !== 'OperationDefinition') {
353
- throw __DEV__ ? new globals.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new globals.InvariantError(45);
358
+ throw __DEV__ ? new globals.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new globals.InvariantError(47);
354
359
  }
355
360
  return definition;
356
361
  });
357
- __DEV__ ? globals.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : globals.invariant(operations.length <= 1, 46);
362
+ __DEV__ ? globals.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : globals.invariant(operations.length <= 1, 48);
358
363
  return doc;
359
364
  }
360
365
  function getOperationDefinition(doc) {
@@ -373,14 +378,14 @@ function getFragmentDefinitions(doc) {
373
378
  }
374
379
  function getQueryDefinition(doc) {
375
380
  var queryDef = getOperationDefinition(doc);
376
- __DEV__ ? globals.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : globals.invariant(queryDef && queryDef.operation === 'query', 47);
381
+ __DEV__ ? globals.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : globals.invariant(queryDef && queryDef.operation === 'query', 49);
377
382
  return queryDef;
378
383
  }
379
384
  function getFragmentDefinition(doc) {
380
- __DEV__ ? globals.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") : globals.invariant(doc.kind === 'Document', 48);
381
- __DEV__ ? globals.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : globals.invariant(doc.definitions.length <= 1, 49);
385
+ __DEV__ ? globals.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") : globals.invariant(doc.kind === 'Document', 50);
386
+ __DEV__ ? globals.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : globals.invariant(doc.definitions.length <= 1, 51);
382
387
  var fragmentDef = doc.definitions[0];
383
- __DEV__ ? globals.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : globals.invariant(fragmentDef.kind === 'FragmentDefinition', 50);
388
+ __DEV__ ? globals.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : globals.invariant(fragmentDef.kind === 'FragmentDefinition', 52);
384
389
  return fragmentDef;
385
390
  }
386
391
  function getMainDefinition(queryDoc) {
@@ -403,7 +408,7 @@ function getMainDefinition(queryDoc) {
403
408
  if (fragmentDefinition) {
404
409
  return fragmentDefinition;
405
410
  }
406
- throw __DEV__ ? new globals.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new globals.InvariantError(51);
411
+ throw __DEV__ ? new globals.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new globals.InvariantError(53);
407
412
  }
408
413
  function getDefaultValues(definition) {
409
414
  var defaultValues = Object.create(null);
@@ -436,11 +441,9 @@ var TYPENAME_FIELD = {
436
441
  value: '__typename',
437
442
  },
438
443
  };
439
- function isEmpty(op, fragments) {
440
- return op.selectionSet.selections.every(function (selection) {
441
- return selection.kind === 'FragmentSpread' &&
442
- isEmpty(fragments[selection.name.value], fragments);
443
- });
444
+ function isEmpty(op, fragmentMap) {
445
+ return !op || op.selectionSet.selections.every(function (selection) { return selection.kind === 'FragmentSpread' &&
446
+ isEmpty(fragmentMap[selection.name.value], fragmentMap); });
444
447
  }
445
448
  function nullIfDocIsEmpty(doc) {
446
449
  return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))
@@ -1260,6 +1263,8 @@ exports.getQueryDefinition = getQueryDefinition;
1260
1263
  exports.getStoreKeyName = getStoreKeyName;
1261
1264
  exports.getTypenameFromResult = getTypenameFromResult;
1262
1265
  exports.graphQLResultHasError = graphQLResultHasError;
1266
+ exports.hasAllDirectives = hasAllDirectives;
1267
+ exports.hasAnyDirectives = hasAnyDirectives;
1263
1268
  exports.hasClientExports = hasClientExports;
1264
1269
  exports.hasDirectives = hasDirectives;
1265
1270
  exports.isDocumentNode = isDocumentNode;
package/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export var version = '3.7.0-beta.7';
1
+ export var version = '3.7.0-beta.8';
2
2
  //# sourceMappingURL=version.js.map