@apollo/client 3.6.2 → 3.6.5

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 (84) hide show
  1. package/apollo-client.cjs +164 -105
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +9 -10
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +2288 -0
  7. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  8. package/cache/inmemory/readFromStore.js +10 -11
  9. package/cache/inmemory/readFromStore.js.map +1 -1
  10. package/core/ApolloClient.d.ts.map +1 -1
  11. package/core/ApolloClient.js.map +1 -1
  12. package/core/ObservableQuery.d.ts.map +1 -1
  13. package/core/ObservableQuery.js +5 -3
  14. package/core/ObservableQuery.js.map +1 -1
  15. package/core/core.cjs +5 -3
  16. package/core/core.cjs.map +1 -1
  17. package/core/core.cjs.native.js +2141 -0
  18. package/errors/errors.cjs.native.js +48 -0
  19. package/invariantErrorCodes.js +1 -1
  20. package/link/batch/batch.cjs.native.js +161 -0
  21. package/link/batch-http/batch-http.cjs.native.js +127 -0
  22. package/link/context/context.cjs.native.js +38 -0
  23. package/link/core/core.cjs.native.js +121 -0
  24. package/link/error/error.cjs.native.js +90 -0
  25. package/link/http/http.cjs.native.js +320 -0
  26. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  27. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  28. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  29. package/link/retry/retry.cjs.native.js +170 -0
  30. package/link/schema/schema.cjs.native.js +56 -0
  31. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  32. package/link/utils/utils.cjs.native.js +115 -0
  33. package/link/ws/ws.cjs.native.js +28 -0
  34. package/main.cjs.native.js +16 -0
  35. package/package.json +16 -17
  36. package/react/components/components.cjs.native.js +79 -0
  37. package/react/context/context.cjs.native.js +67 -0
  38. package/react/hoc/hoc.cjs.native.js +325 -0
  39. package/react/hooks/hooks.cjs +168 -99
  40. package/react/hooks/hooks.cjs.map +1 -1
  41. package/react/hooks/hooks.cjs.native.js +612 -0
  42. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  43. package/react/hooks/useLazyQuery.js +12 -23
  44. package/react/hooks/useLazyQuery.js.map +1 -1
  45. package/react/hooks/useMutation.js +7 -7
  46. package/react/hooks/useMutation.js.map +1 -1
  47. package/react/hooks/useQuery.d.ts +6 -2
  48. package/react/hooks/useQuery.d.ts.map +1 -1
  49. package/react/hooks/useQuery.js +52 -40
  50. package/react/hooks/useQuery.js.map +1 -1
  51. package/react/hooks/useSubscription.d.ts.map +1 -1
  52. package/react/hooks/useSubscription.js +17 -7
  53. package/react/hooks/useSubscription.js.map +1 -1
  54. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  55. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  56. package/react/hooks/useSyncExternalStore.js +48 -0
  57. package/react/hooks/useSyncExternalStore.js.map +1 -0
  58. package/react/parser/parser.cjs.native.js +103 -0
  59. package/react/react.cjs.native.js +22 -0
  60. package/react/ssr/ssr.cjs.native.js +150 -0
  61. package/testing/core/core.cjs.native.js +288 -0
  62. package/testing/testing.cjs.native.js +58 -0
  63. package/utilities/common/canUse.d.ts +2 -0
  64. package/utilities/common/canUse.d.ts.map +1 -1
  65. package/utilities/common/canUse.js +6 -2
  66. package/utilities/common/canUse.js.map +1 -1
  67. package/utilities/common/mergeDeep.d.ts.map +1 -1
  68. package/utilities/common/mergeDeep.js +8 -11
  69. package/utilities/common/mergeDeep.js.map +1 -1
  70. package/utilities/common/mergeOptions.d.ts +1 -1
  71. package/utilities/common/mergeOptions.d.ts.map +1 -1
  72. package/utilities/common/mergeOptions.js +1 -1
  73. package/utilities/common/mergeOptions.js.map +1 -1
  74. package/utilities/globals/globals.cjs.native.js +56 -0
  75. package/utilities/observables/Concast.d.ts.map +1 -1
  76. package/utilities/observables/Concast.js +5 -2
  77. package/utilities/observables/Concast.js.map +1 -1
  78. package/utilities/policies/pagination.d.ts.map +1 -1
  79. package/utilities/policies/pagination.js +9 -7
  80. package/utilities/policies/pagination.js.map +1 -1
  81. package/utilities/utilities.cjs +30 -23
  82. package/utilities/utilities.cjs.map +1 -1
  83. package/utilities/utilities.cjs.native.js +1281 -0
  84. package/version.js +1 -1
@@ -0,0 +1,325 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var globals = require('../../utilities/globals');
6
+ var parser = require('../parser');
7
+ var tslib = require('tslib');
8
+ var React = require('react');
9
+ var hoistNonReactStatics = require('hoist-non-react-statics');
10
+ var components = require('../components');
11
+ var context = require('../context');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ for (var k in e) {
20
+ n[k] = e[k];
21
+ }
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
+ var hoistNonReactStatics__default = /*#__PURE__*/_interopDefaultLegacy(hoistNonReactStatics);
29
+
30
+ var defaultMapPropsToOptions = function () { return ({}); };
31
+ var defaultMapPropsToSkip = function () { return false; };
32
+ function getDisplayName$1(WrappedComponent) {
33
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
34
+ }
35
+ function calculateVariablesFromProps(operation, props) {
36
+ var variables = {};
37
+ for (var _i = 0, _a = operation.variables; _i < _a.length; _i++) {
38
+ var _b = _a[_i], variable = _b.variable, type = _b.type;
39
+ if (!variable.name || !variable.name.value)
40
+ continue;
41
+ var variableName = variable.name.value;
42
+ var variableProp = props[variableName];
43
+ if (typeof variableProp !== 'undefined') {
44
+ variables[variableName] = variableProp;
45
+ continue;
46
+ }
47
+ if (type.kind !== 'NonNullType') {
48
+ variables[variableName] = undefined;
49
+ }
50
+ }
51
+ return variables;
52
+ }
53
+ var GraphQLBase = (function (_super) {
54
+ tslib.__extends(GraphQLBase, _super);
55
+ function GraphQLBase(props) {
56
+ var _this = _super.call(this, props) || this;
57
+ _this.withRef = false;
58
+ _this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
59
+ return _this;
60
+ }
61
+ GraphQLBase.prototype.getWrappedInstance = function () {
62
+ __DEV__ ? globals.invariant(this.withRef, "To access the wrapped instance, you need to specify " +
63
+ "{ withRef: true } in the options") : globals.invariant(this.withRef, 27);
64
+ return this.wrappedInstance;
65
+ };
66
+ GraphQLBase.prototype.setWrappedInstance = function (ref) {
67
+ this.wrappedInstance = ref;
68
+ };
69
+ return GraphQLBase;
70
+ }(React__namespace.Component));
71
+
72
+ function withQuery(document, operationOptions) {
73
+ if (operationOptions === void 0) { operationOptions = {}; }
74
+ var operation = parser.parser(document);
75
+ var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? 'Apollo' : _c;
76
+ var mapPropsToOptions = options;
77
+ if (typeof mapPropsToOptions !== 'function') {
78
+ mapPropsToOptions = function () { return options; };
79
+ }
80
+ var mapPropsToSkip = skip;
81
+ if (typeof mapPropsToSkip !== 'function') {
82
+ mapPropsToSkip = function () { return skip; };
83
+ }
84
+ var lastResultProps;
85
+ return function (WrappedComponent) {
86
+ var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
87
+ var GraphQL = (function (_super) {
88
+ tslib.__extends(GraphQL, _super);
89
+ function GraphQL() {
90
+ return _super !== null && _super.apply(this, arguments) || this;
91
+ }
92
+ GraphQL.prototype.render = function () {
93
+ var _this = this;
94
+ var props = this.props;
95
+ var shouldSkip = mapPropsToSkip(props);
96
+ var opts = shouldSkip
97
+ ? Object.create(null)
98
+ : tslib.__assign({}, mapPropsToOptions(props));
99
+ if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
100
+ opts.variables = calculateVariablesFromProps(operation, props);
101
+ }
102
+ return (React__namespace.createElement(components.Query, tslib.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, query: document }), function (_a) {
103
+ var _b, _c;
104
+ _a.client; var data = _a.data, r = tslib.__rest(_a, ["client", "data"]);
105
+ if (operationOptions.withRef) {
106
+ _this.withRef = true;
107
+ props = Object.assign({}, props, {
108
+ ref: _this.setWrappedInstance
109
+ });
110
+ }
111
+ if (shouldSkip) {
112
+ return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, {})));
113
+ }
114
+ var result = Object.assign(r, data || {});
115
+ var name = operationOptions.name || 'data';
116
+ var childProps = (_b = {}, _b[name] = result, _b);
117
+ if (operationOptions.props) {
118
+ var newResult = (_c = {},
119
+ _c[name] = result,
120
+ _c.ownProps = props,
121
+ _c);
122
+ lastResultProps = operationOptions.props(newResult, lastResultProps);
123
+ childProps = lastResultProps;
124
+ }
125
+ return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps)));
126
+ }));
127
+ };
128
+ GraphQL.displayName = graphQLDisplayName;
129
+ GraphQL.WrappedComponent = WrappedComponent;
130
+ return GraphQL;
131
+ }(GraphQLBase));
132
+ return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
133
+ };
134
+ }
135
+
136
+ function withMutation(document, operationOptions) {
137
+ if (operationOptions === void 0) { operationOptions = {}; }
138
+ var operation = parser.parser(document);
139
+ var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.alias, alias = _b === void 0 ? 'Apollo' : _b;
140
+ var mapPropsToOptions = options;
141
+ if (typeof mapPropsToOptions !== 'function')
142
+ mapPropsToOptions = function () { return options; };
143
+ return function (WrappedComponent) {
144
+ var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
145
+ var GraphQL = (function (_super) {
146
+ tslib.__extends(GraphQL, _super);
147
+ function GraphQL() {
148
+ return _super !== null && _super.apply(this, arguments) || this;
149
+ }
150
+ GraphQL.prototype.render = function () {
151
+ var props = this.props;
152
+ var opts = mapPropsToOptions(props);
153
+ if (operationOptions.withRef) {
154
+ this.withRef = true;
155
+ props = Object.assign({}, props, {
156
+ ref: this.setWrappedInstance
157
+ });
158
+ }
159
+ if (!opts.variables && operation.variables.length > 0) {
160
+ opts.variables = calculateVariablesFromProps(operation, props);
161
+ }
162
+ return (React__namespace.createElement(components.Mutation, tslib.__assign({ ignoreResults: true }, opts, { mutation: document }), function (mutate, _a) {
163
+ var _b, _c;
164
+ var data = _a.data, r = tslib.__rest(_a, ["data"]);
165
+ var result = Object.assign(r, data || {});
166
+ var name = operationOptions.name || 'mutate';
167
+ var resultName = operationOptions.name
168
+ ? "".concat(name, "Result")
169
+ : 'result';
170
+ var childProps = (_b = {},
171
+ _b[name] = mutate,
172
+ _b[resultName] = result,
173
+ _b);
174
+ if (operationOptions.props) {
175
+ var newResult = (_c = {},
176
+ _c[name] = mutate,
177
+ _c[resultName] = result,
178
+ _c.ownProps = props,
179
+ _c);
180
+ childProps = operationOptions.props(newResult);
181
+ }
182
+ return React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps));
183
+ }));
184
+ };
185
+ GraphQL.displayName = graphQLDisplayName;
186
+ GraphQL.WrappedComponent = WrappedComponent;
187
+ return GraphQL;
188
+ }(GraphQLBase));
189
+ return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
190
+ };
191
+ }
192
+
193
+ function withSubscription(document, operationOptions) {
194
+ if (operationOptions === void 0) { operationOptions = {}; }
195
+ var operation = parser.parser(document);
196
+ var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? 'Apollo' : _c, shouldResubscribe = operationOptions.shouldResubscribe;
197
+ var mapPropsToOptions = options;
198
+ if (typeof mapPropsToOptions !== 'function')
199
+ mapPropsToOptions = function () { return options; };
200
+ var mapPropsToSkip = skip;
201
+ if (typeof mapPropsToSkip !== 'function')
202
+ mapPropsToSkip = function () { return skip; };
203
+ var lastResultProps;
204
+ return function (WrappedComponent) {
205
+ var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
206
+ var GraphQL = (function (_super) {
207
+ tslib.__extends(GraphQL, _super);
208
+ function GraphQL(props) {
209
+ var _this = _super.call(this, props) || this;
210
+ _this.state = { resubscribe: false };
211
+ return _this;
212
+ }
213
+ GraphQL.prototype.updateResubscribe = function (resubscribe) {
214
+ this.setState({ resubscribe: resubscribe });
215
+ };
216
+ GraphQL.prototype.componentDidUpdate = function (prevProps) {
217
+ var resubscribe = !!(shouldResubscribe &&
218
+ shouldResubscribe(prevProps, this.props));
219
+ if (this.state.resubscribe !== resubscribe) {
220
+ this.updateResubscribe(resubscribe);
221
+ }
222
+ };
223
+ GraphQL.prototype.render = function () {
224
+ var _this = this;
225
+ var props = this.props;
226
+ var shouldSkip = mapPropsToSkip(props);
227
+ var opts = shouldSkip
228
+ ? Object.create(null)
229
+ : mapPropsToOptions(props);
230
+ if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
231
+ opts.variables = calculateVariablesFromProps(operation, props);
232
+ }
233
+ return (React__namespace.createElement(components.Subscription, tslib.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, subscription: document, shouldResubscribe: this.state.resubscribe }), function (_a) {
234
+ var _b, _c;
235
+ var data = _a.data, r = tslib.__rest(_a, ["data"]);
236
+ if (operationOptions.withRef) {
237
+ _this.withRef = true;
238
+ props = Object.assign({}, props, {
239
+ ref: _this.setWrappedInstance
240
+ });
241
+ }
242
+ if (shouldSkip) {
243
+ return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, {})));
244
+ }
245
+ var result = Object.assign(r, data || {});
246
+ var name = operationOptions.name || 'data';
247
+ var childProps = (_b = {}, _b[name] = result, _b);
248
+ if (operationOptions.props) {
249
+ var newResult = (_c = {},
250
+ _c[name] = result,
251
+ _c.ownProps = props,
252
+ _c);
253
+ lastResultProps = operationOptions.props(newResult, lastResultProps);
254
+ childProps = lastResultProps;
255
+ }
256
+ return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps)));
257
+ }));
258
+ };
259
+ GraphQL.displayName = graphQLDisplayName;
260
+ GraphQL.WrappedComponent = WrappedComponent;
261
+ return GraphQL;
262
+ }(GraphQLBase));
263
+ return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
264
+ };
265
+ }
266
+
267
+ function graphql(document, operationOptions) {
268
+ if (operationOptions === void 0) { operationOptions = {}; }
269
+ switch (parser.parser(document).type) {
270
+ case parser.DocumentType.Mutation:
271
+ return withMutation(document, operationOptions);
272
+ case parser.DocumentType.Subscription:
273
+ return withSubscription(document, operationOptions);
274
+ case parser.DocumentType.Query:
275
+ default:
276
+ return withQuery(document, operationOptions);
277
+ }
278
+ }
279
+
280
+ function getDisplayName(WrappedComponent) {
281
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
282
+ }
283
+ function withApollo(WrappedComponent, operationOptions) {
284
+ if (operationOptions === void 0) { operationOptions = {}; }
285
+ var withDisplayName = "withApollo(".concat(getDisplayName(WrappedComponent), ")");
286
+ var WithApollo = (function (_super) {
287
+ tslib.__extends(WithApollo, _super);
288
+ function WithApollo(props) {
289
+ var _this = _super.call(this, props) || this;
290
+ _this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
291
+ return _this;
292
+ }
293
+ WithApollo.prototype.getWrappedInstance = function () {
294
+ __DEV__ ? globals.invariant(operationOptions.withRef, "To access the wrapped instance, you need to specify " +
295
+ "{ withRef: true } in the options") : globals.invariant(operationOptions.withRef, 28);
296
+ return this.wrappedInstance;
297
+ };
298
+ WithApollo.prototype.setWrappedInstance = function (ref) {
299
+ this.wrappedInstance = ref;
300
+ };
301
+ WithApollo.prototype.render = function () {
302
+ var _this = this;
303
+ return (React__namespace.createElement(context.ApolloConsumer, null, function (client) {
304
+ var props = Object.assign({}, _this.props, {
305
+ client: client,
306
+ ref: operationOptions.withRef
307
+ ? _this.setWrappedInstance
308
+ : undefined
309
+ });
310
+ return React__namespace.createElement(WrappedComponent, tslib.__assign({}, props));
311
+ }));
312
+ };
313
+ WithApollo.displayName = withDisplayName;
314
+ WithApollo.WrappedComponent = WrappedComponent;
315
+ return WithApollo;
316
+ }(React__namespace.Component));
317
+ return hoistNonReactStatics__default(WithApollo, WrappedComponent, {});
318
+ }
319
+
320
+ exports.graphql = graphql;
321
+ exports.withApollo = withApollo;
322
+ exports.withMutation = withMutation;
323
+ exports.withQuery = withQuery;
324
+ exports.withSubscription = withSubscription;
325
+ //# sourceMappingURL=hoc.cjs.map