@apollo/client 3.7.0-beta.6 → 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 (202) hide show
  1. package/README.md +2 -0
  2. package/apollo-client.cjs +522 -188
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs +175 -48
  6. package/cache/cache.cjs.map +1 -1
  7. package/cache/cache.cjs.native.js +175 -48
  8. package/cache/core/cache.d.ts +1 -1
  9. package/cache/core/cache.d.ts.map +1 -1
  10. package/cache/core/cache.js +3 -3
  11. package/cache/core/cache.js.map +1 -1
  12. package/cache/core/types/common.d.ts +1 -1
  13. package/cache/core/types/common.d.ts.map +1 -1
  14. package/cache/core/types/common.js +16 -11
  15. package/cache/core/types/common.js.map +1 -1
  16. package/cache/index.d.ts +2 -1
  17. package/cache/index.d.ts.map +1 -1
  18. package/cache/index.js +1 -0
  19. package/cache/index.js.map +1 -1
  20. package/cache/inmemory/fragmentRegistry.d.ts +8 -0
  21. package/cache/inmemory/fragmentRegistry.d.ts.map +1 -0
  22. package/cache/inmemory/fragmentRegistry.js +113 -0
  23. package/cache/inmemory/fragmentRegistry.js.map +1 -0
  24. package/cache/inmemory/helpers.d.ts +9 -3
  25. package/cache/inmemory/helpers.d.ts.map +1 -1
  26. package/cache/inmemory/helpers.js +23 -6
  27. package/cache/inmemory/helpers.js.map +1 -1
  28. package/cache/inmemory/inMemoryCache.d.ts +1 -0
  29. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  30. package/cache/inmemory/inMemoryCache.js +9 -1
  31. package/cache/inmemory/inMemoryCache.js.map +1 -1
  32. package/cache/inmemory/readFromStore.d.ts +2 -1
  33. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  34. package/cache/inmemory/readFromStore.js +10 -14
  35. package/cache/inmemory/readFromStore.js.map +1 -1
  36. package/cache/inmemory/types.d.ts +2 -0
  37. package/cache/inmemory/types.d.ts.map +1 -1
  38. package/cache/inmemory/types.js.map +1 -1
  39. package/cache/inmemory/writeToStore.d.ts +5 -3
  40. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  41. package/cache/inmemory/writeToStore.js +12 -19
  42. package/cache/inmemory/writeToStore.js.map +1 -1
  43. package/core/ApolloClient.js +2 -2
  44. package/core/LocalState.js +1 -1
  45. package/core/ObservableQuery.d.ts.map +1 -1
  46. package/core/ObservableQuery.js +2 -2
  47. package/core/ObservableQuery.js.map +1 -1
  48. package/core/QueryInfo.d.ts +1 -1
  49. package/core/QueryInfo.d.ts.map +1 -1
  50. package/core/QueryInfo.js +26 -4
  51. package/core/QueryInfo.js.map +1 -1
  52. package/core/QueryManager.d.ts.map +1 -1
  53. package/core/QueryManager.js +36 -23
  54. package/core/QueryManager.js.map +1 -1
  55. package/core/core.cjs +70 -33
  56. package/core/core.cjs.map +1 -1
  57. package/core/core.cjs.native.js +70 -33
  58. package/core/types.d.ts.map +1 -1
  59. package/core/types.js.map +1 -1
  60. package/invariantErrorCodes.js +59 -49
  61. package/link/batch-http/batch-http.cjs +2 -2
  62. package/link/batch-http/batch-http.cjs.map +1 -1
  63. package/link/batch-http/batch-http.cjs.native.js +2 -2
  64. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  65. package/link/batch-http/batchHttpLink.js +2 -2
  66. package/link/batch-http/batchHttpLink.js.map +1 -1
  67. package/link/core/ApolloLink.js +1 -1
  68. package/link/core/core.cjs +1 -1
  69. package/link/core/core.cjs.map +1 -1
  70. package/link/core/core.cjs.native.js +1 -1
  71. package/link/core/types.d.ts +30 -5
  72. package/link/core/types.d.ts.map +1 -1
  73. package/link/core/types.js +0 -1
  74. package/link/core/types.js.map +1 -1
  75. package/link/http/checkFetcher.js +1 -1
  76. package/link/http/createHttpLink.d.ts.map +1 -1
  77. package/link/http/createHttpLink.js +16 -19
  78. package/link/http/createHttpLink.js.map +1 -1
  79. package/link/http/http.cjs +335 -55
  80. package/link/http/http.cjs.map +1 -1
  81. package/link/http/http.cjs.native.js +335 -55
  82. package/link/http/iterators/async.d.ts +2 -0
  83. package/link/http/iterators/async.d.ts.map +1 -0
  84. package/link/http/iterators/async.js +14 -0
  85. package/link/http/iterators/async.js.map +1 -0
  86. package/link/http/iterators/nodeStream.d.ts +4 -0
  87. package/link/http/iterators/nodeStream.d.ts.map +1 -0
  88. package/link/http/iterators/nodeStream.js +71 -0
  89. package/link/http/iterators/nodeStream.js.map +1 -0
  90. package/link/http/iterators/promise.d.ts +2 -0
  91. package/link/http/iterators/promise.d.ts.map +1 -0
  92. package/link/http/iterators/promise.js +28 -0
  93. package/link/http/iterators/promise.js.map +1 -0
  94. package/link/http/iterators/reader.d.ts +2 -0
  95. package/link/http/iterators/reader.d.ts.map +1 -0
  96. package/link/http/iterators/reader.js +15 -0
  97. package/link/http/iterators/reader.js.map +1 -0
  98. package/link/http/parseAndCheckHttpResponse.d.ts +7 -1
  99. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  100. package/link/http/parseAndCheckHttpResponse.js +131 -27
  101. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  102. package/link/http/responseIterator.d.ts +3 -0
  103. package/link/http/responseIterator.d.ts.map +1 -0
  104. package/link/http/responseIterator.js +23 -0
  105. package/link/http/responseIterator.js.map +1 -0
  106. package/link/http/selectHttpOptionsAndBody.d.ts +2 -0
  107. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  108. package/link/http/selectHttpOptionsAndBody.js +17 -7
  109. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  110. package/link/http/serializeFetchParameter.js +1 -1
  111. package/link/persisted-queries/index.js +2 -2
  112. package/link/persisted-queries/persisted-queries.cjs +2 -2
  113. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  114. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  115. package/link/utils/utils.cjs +1 -1
  116. package/link/utils/utils.cjs.map +1 -1
  117. package/link/utils/utils.cjs.native.js +1 -1
  118. package/link/utils/validateOperation.js +1 -1
  119. package/package.json +40 -29
  120. package/react/context/ApolloConsumer.js +1 -1
  121. package/react/context/ApolloProvider.js +1 -1
  122. package/react/context/context.cjs +2 -2
  123. package/react/context/context.cjs.map +1 -1
  124. package/react/context/context.cjs.native.js +2 -2
  125. package/react/hoc/hoc-utils.js +1 -1
  126. package/react/hoc/hoc.cjs +2 -2
  127. package/react/hoc/hoc.cjs.map +1 -1
  128. package/react/hoc/hoc.cjs.native.js +2 -2
  129. package/react/hoc/withApollo.js +1 -1
  130. package/react/hooks/hooks.cjs +19 -12
  131. package/react/hooks/hooks.cjs.map +1 -1
  132. package/react/hooks/hooks.cjs.native.js +19 -12
  133. package/react/hooks/useApolloClient.js +1 -1
  134. package/react/hooks/useFragment.d.ts +2 -4
  135. package/react/hooks/useFragment.d.ts.map +1 -1
  136. package/react/hooks/useFragment.js +6 -3
  137. package/react/hooks/useFragment.js.map +1 -1
  138. package/react/hooks/useMutation.d.ts.map +1 -1
  139. package/react/hooks/useMutation.js +8 -6
  140. package/react/hooks/useMutation.js.map +1 -1
  141. package/react/hooks/useQuery.d.ts.map +1 -1
  142. package/react/hooks/useQuery.js +1 -1
  143. package/react/hooks/useQuery.js.map +1 -1
  144. package/react/hooks/useSubscription.d.ts.map +1 -1
  145. package/react/hooks/useSubscription.js +2 -0
  146. package/react/hooks/useSubscription.js.map +1 -1
  147. package/react/parser/index.js +5 -5
  148. package/react/parser/parser.cjs +5 -5
  149. package/react/parser/parser.cjs.map +1 -1
  150. package/react/parser/parser.cjs.native.js +5 -5
  151. package/react/types/types.d.ts +3 -3
  152. package/react/types/types.d.ts.map +1 -1
  153. package/react/types/types.js.map +1 -1
  154. package/testing/core/core.cjs +2 -2
  155. package/testing/core/core.cjs.map +1 -1
  156. package/testing/core/core.cjs.native.js +2 -2
  157. package/testing/core/itAsync.d.ts +3 -3
  158. package/testing/core/itAsync.d.ts.map +1 -1
  159. package/testing/core/mocking/mockLink.js +2 -2
  160. package/testing/core/mocking/mockLink.js.map +1 -1
  161. package/testing/core/subscribeAndCount.d.ts +2 -3
  162. package/testing/core/subscribeAndCount.d.ts.map +1 -1
  163. package/testing/core/subscribeAndCount.js.map +1 -1
  164. package/utilities/common/canUse.d.ts +1 -0
  165. package/utilities/common/canUse.d.ts.map +1 -1
  166. package/utilities/common/canUse.js +1 -0
  167. package/utilities/common/canUse.js.map +1 -1
  168. package/utilities/common/incrementalResult.d.ts +3 -0
  169. package/utilities/common/incrementalResult.d.ts.map +1 -0
  170. package/utilities/common/incrementalResult.js +4 -0
  171. package/utilities/common/incrementalResult.js.map +1 -0
  172. package/utilities/common/responseIterator.d.ts +10 -0
  173. package/utilities/common/responseIterator.d.ts.map +1 -0
  174. package/utilities/common/responseIterator.js +21 -0
  175. package/utilities/common/responseIterator.js.map +1 -0
  176. package/utilities/globals/globals.cjs +1 -1
  177. package/utilities/globals/globals.cjs.map +1 -1
  178. package/utilities/globals/globals.cjs.native.js +1 -1
  179. package/utilities/globals/index.js +1 -1
  180. package/utilities/graphql/directives.d.ts +3 -1
  181. package/utilities/graphql/directives.d.ts.map +1 -1
  182. package/utilities/graphql/directives.js +20 -10
  183. package/utilities/graphql/directives.js.map +1 -1
  184. package/utilities/graphql/fragments.d.ts +2 -1
  185. package/utilities/graphql/fragments.d.ts.map +1 -1
  186. package/utilities/graphql/fragments.js +9 -5
  187. package/utilities/graphql/fragments.js.map +1 -1
  188. package/utilities/graphql/getFromAST.js +8 -8
  189. package/utilities/graphql/storeUtils.d.ts +1 -1
  190. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  191. package/utilities/graphql/storeUtils.js +1 -1
  192. package/utilities/graphql/transform.d.ts.map +1 -1
  193. package/utilities/graphql/transform.js +3 -5
  194. package/utilities/graphql/transform.js.map +1 -1
  195. package/utilities/index.d.ts +2 -2
  196. package/utilities/index.d.ts.map +1 -1
  197. package/utilities/index.js +1 -1
  198. package/utilities/index.js.map +1 -1
  199. package/utilities/utilities.cjs +44 -28
  200. package/utilities/utilities.cjs.map +1 -1
  201. package/utilities/utilities.cjs.native.js +44 -28
  202. package/version.js +1 -1
@@ -3,42 +3,315 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var globals = require('../../utilities/globals');
6
- var utils = require('../utils');
7
6
  var tslib = require('tslib');
7
+ var utilities = require('../../utilities');
8
+ var utils = require('../utils');
8
9
  var graphql = require('graphql');
9
10
  var core = require('../core');
10
- var utilities = require('../../utilities');
11
11
 
12
- var hasOwnProperty = Object.prototype.hasOwnProperty;
13
- function parseAndCheckHttpResponse(operations) {
14
- return function (response) { return response
15
- .text()
16
- .then(function (bodyText) {
17
- try {
18
- return JSON.parse(bodyText);
12
+ typeof WeakMap === 'function' &&
13
+ globals.maybe(function () { return navigator.product; }) !== 'ReactNative';
14
+ var canUseSymbol = typeof Symbol === 'function' &&
15
+ typeof Symbol.for === 'function';
16
+ var canUseAsyncIteratorSymbol = canUseSymbol && Symbol.asyncIterator;
17
+ typeof globals.maybe(function () { return window.document.createElement; }) === "function";
18
+ globals.maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
19
+
20
+ function isNodeResponse(value) {
21
+ return !!value.body;
22
+ }
23
+ function isReadableStream(value) {
24
+ return !!value.getReader;
25
+ }
26
+ function isAsyncIterableIterator(value) {
27
+ return !!(canUseAsyncIteratorSymbol &&
28
+ value[Symbol.asyncIterator]);
29
+ }
30
+ function isStreamableBlob(value) {
31
+ return !!value.stream;
32
+ }
33
+ function isBlob(value) {
34
+ return !!value.arrayBuffer;
35
+ }
36
+ function isNodeReadableStream(value) {
37
+ return !!value.pipe;
38
+ }
39
+
40
+ function asyncIterator(source) {
41
+ var _a;
42
+ var iterator = source[Symbol.asyncIterator]();
43
+ return _a = {
44
+ next: function () {
45
+ return iterator.next();
46
+ }
47
+ },
48
+ _a[Symbol.asyncIterator] = function () {
49
+ return this;
50
+ },
51
+ _a;
52
+ }
53
+
54
+ function nodeStreamIterator(stream) {
55
+ var cleanup = null;
56
+ var error = null;
57
+ var done = false;
58
+ var data = [];
59
+ var waiting = [];
60
+ function onData(chunk) {
61
+ if (error)
62
+ return;
63
+ if (waiting.length) {
64
+ var shiftedArr = waiting.shift();
65
+ if (Array.isArray(shiftedArr) && shiftedArr[0]) {
66
+ return shiftedArr[0]({ value: chunk, done: false });
67
+ }
19
68
  }
20
- catch (err) {
21
- var parseError = err;
22
- parseError.name = 'ServerParseError';
23
- parseError.response = response;
24
- parseError.statusCode = response.status;
25
- parseError.bodyText = bodyText;
26
- throw parseError;
69
+ data.push(chunk);
70
+ }
71
+ function onError(err) {
72
+ error = err;
73
+ var all = waiting.slice();
74
+ all.forEach(function (pair) {
75
+ pair[1](err);
76
+ });
77
+ !cleanup || cleanup();
78
+ }
79
+ function onEnd() {
80
+ done = true;
81
+ var all = waiting.slice();
82
+ all.forEach(function (pair) {
83
+ pair[0]({ value: undefined, done: true });
84
+ });
85
+ !cleanup || cleanup();
86
+ }
87
+ cleanup = function () {
88
+ cleanup = null;
89
+ stream.removeListener("data", onData);
90
+ stream.removeListener("error", onError);
91
+ stream.removeListener("end", onEnd);
92
+ stream.removeListener("finish", onEnd);
93
+ stream.removeListener("close", onEnd);
94
+ };
95
+ stream.on("data", onData);
96
+ stream.on("error", onError);
97
+ stream.on("end", onEnd);
98
+ stream.on("finish", onEnd);
99
+ stream.on("close", onEnd);
100
+ function getNext() {
101
+ return new Promise(function (resolve, reject) {
102
+ if (error)
103
+ return reject(error);
104
+ if (data.length)
105
+ return resolve({ value: data.shift(), done: false });
106
+ if (done)
107
+ return resolve({ value: undefined, done: true });
108
+ waiting.push([resolve, reject]);
109
+ });
110
+ }
111
+ var iterator = {
112
+ next: function () {
113
+ return getNext();
114
+ },
115
+ };
116
+ if (utilities.canUseAsyncIteratorSymbol) {
117
+ iterator[Symbol.asyncIterator] = function () {
118
+ return this;
119
+ };
120
+ }
121
+ return iterator;
122
+ }
123
+
124
+ function promiseIterator(promise) {
125
+ var resolved = false;
126
+ var iterator = {
127
+ next: function () {
128
+ if (resolved)
129
+ return Promise.resolve({
130
+ value: undefined,
131
+ done: true,
132
+ });
133
+ resolved = true;
134
+ return new Promise(function (resolve, reject) {
135
+ promise
136
+ .then(function (value) {
137
+ resolve({ value: value, done: false });
138
+ })
139
+ .catch(reject);
140
+ });
141
+ },
142
+ };
143
+ if (utilities.canUseAsyncIteratorSymbol) {
144
+ iterator[Symbol.asyncIterator] = function () {
145
+ return this;
146
+ };
147
+ }
148
+ return iterator;
149
+ }
150
+
151
+ function readerIterator(reader) {
152
+ var iterator = {
153
+ next: function () {
154
+ return reader.read();
155
+ },
156
+ };
157
+ if (utilities.canUseAsyncIteratorSymbol) {
158
+ iterator[Symbol.asyncIterator] = function () {
159
+ return this;
160
+ };
161
+ }
162
+ return iterator;
163
+ }
164
+
165
+ function responseIterator(response) {
166
+ var body = response;
167
+ if (isNodeResponse(response))
168
+ body = response.body;
169
+ if (isAsyncIterableIterator(body))
170
+ return asyncIterator(body);
171
+ if (isReadableStream(body))
172
+ return readerIterator(body.getReader());
173
+ if (isStreamableBlob(body)) {
174
+ return readerIterator(body.stream().getReader());
175
+ }
176
+ if (isBlob(body))
177
+ return promiseIterator(body.arrayBuffer());
178
+ if (isNodeReadableStream(body))
179
+ return nodeStreamIterator(body);
180
+ throw new Error("Unknown body type for responseIterator. Please pass a streamable response.");
181
+ }
182
+
183
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
184
+ function readMultipartBody(response, observer) {
185
+ var _a, _b, _c;
186
+ return tslib.__awaiter(this, void 0, void 0, function () {
187
+ var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _d, value, done, chunk, bi, message, i, headers, contentType_1, body, result;
188
+ var _e;
189
+ return tslib.__generator(this, function (_f) {
190
+ switch (_f.label) {
191
+ case 0:
192
+ if (TextDecoder === undefined) {
193
+ throw new Error("TextDecoder must be defined in the environment: please import a polyfill.");
194
+ }
195
+ decoder = new TextDecoder("utf-8");
196
+ contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get('content-type');
197
+ delimiter = "boundary=";
198
+ boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter))
199
+ ? contentType === null || contentType === void 0 ? void 0 : contentType.substring((contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(delimiter)) + delimiter.length).replace(/['"]/g, "").replace(/\;(.*)/gm, "").trim()
200
+ : "-";
201
+ boundary = "--".concat(boundaryVal);
202
+ buffer = "";
203
+ iterator = responseIterator(response);
204
+ running = true;
205
+ _f.label = 1;
206
+ case 1:
207
+ if (!running) return [3, 3];
208
+ return [4, iterator.next()];
209
+ case 2:
210
+ _d = _f.sent(), value = _d.value, done = _d.done;
211
+ chunk = typeof value === "string" ? value : decoder.decode(value);
212
+ running = !done;
213
+ buffer += chunk;
214
+ bi = buffer.indexOf(boundary);
215
+ while (bi > -1) {
216
+ message = void 0;
217
+ _e = [
218
+ buffer.slice(0, bi),
219
+ buffer.slice(bi + boundary.length),
220
+ ], message = _e[0], buffer = _e[1];
221
+ if (message.trim()) {
222
+ i = message.indexOf("\r\n\r\n");
223
+ headers = parseHeaders(message.slice(0, i));
224
+ contentType_1 = headers["content-type"];
225
+ if (contentType_1 &&
226
+ contentType_1.toLowerCase().indexOf("application/json") === -1) {
227
+ throw new Error("Unsupported patch content type: application/json is required.");
228
+ }
229
+ body = message.slice(i);
230
+ try {
231
+ result = parseJsonBody(response, body.replace("\r\n", ""));
232
+ if (Object.keys(result).length > 1 ||
233
+ "data" in result ||
234
+ "incremental" in result ||
235
+ "errors" in result) {
236
+ (_b = observer.next) === null || _b === void 0 ? void 0 : _b.call(observer, result);
237
+ }
238
+ }
239
+ catch (err) {
240
+ handleError(err, observer);
241
+ }
242
+ }
243
+ bi = buffer.indexOf(boundary);
244
+ }
245
+ return [3, 1];
246
+ case 3:
247
+ (_c = observer.complete) === null || _c === void 0 ? void 0 : _c.call(observer);
248
+ return [2];
249
+ }
250
+ });
251
+ });
252
+ }
253
+ function parseHeaders(headerText) {
254
+ var headersInit = {};
255
+ headerText.split("\n").forEach(function (line) {
256
+ var i = line.indexOf(":");
257
+ if (i > -1) {
258
+ var name_1 = line.slice(0, i).trim().toLowerCase();
259
+ var value = line.slice(i + 1).trim();
260
+ headersInit[name_1] = value;
27
261
  }
28
- })
262
+ });
263
+ return headersInit;
264
+ }
265
+ function parseJsonBody(response, bodyText) {
266
+ try {
267
+ return JSON.parse(bodyText);
268
+ }
269
+ catch (err) {
270
+ var parseError = err;
271
+ parseError.name = "ServerParseError";
272
+ parseError.response = response;
273
+ parseError.statusCode = response.status;
274
+ parseError.bodyText = bodyText;
275
+ throw parseError;
276
+ }
277
+ }
278
+ function handleError(err, observer) {
279
+ var _a, _b;
280
+ if (err.name === "AbortError")
281
+ return;
282
+ if (err.result && err.result.errors && err.result.data) {
283
+ (_a = observer.next) === null || _a === void 0 ? void 0 : _a.call(observer, err.result);
284
+ }
285
+ (_b = observer.error) === null || _b === void 0 ? void 0 : _b.call(observer, err);
286
+ }
287
+ function readJsonBody(response, operation, observer) {
288
+ parseAndCheckHttpResponse(operation)(response)
29
289
  .then(function (result) {
30
- if (response.status >= 300) {
31
- utils.throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
32
- }
33
- if (!Array.isArray(result) &&
34
- !hasOwnProperty.call(result, 'data') &&
35
- !hasOwnProperty.call(result, 'errors')) {
36
- utils.throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
37
- ? operations.map(function (op) { return op.operationName; })
38
- : operations.operationName, "'."));
39
- }
40
- return result;
41
- }); };
290
+ var _a, _b;
291
+ (_a = observer.next) === null || _a === void 0 ? void 0 : _a.call(observer, result);
292
+ (_b = observer.complete) === null || _b === void 0 ? void 0 : _b.call(observer);
293
+ })
294
+ .catch(function (err) { return handleError(err, observer); });
295
+ }
296
+ function parseAndCheckHttpResponse(operations) {
297
+ return function (response) {
298
+ return response
299
+ .text()
300
+ .then(function (bodyText) { return parseJsonBody(response, bodyText); })
301
+ .then(function (result) {
302
+ if (response.status >= 300) {
303
+ utils.throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
304
+ }
305
+ if (!Array.isArray(result) &&
306
+ !hasOwnProperty.call(result, "data") &&
307
+ !hasOwnProperty.call(result, "errors")) {
308
+ utils.throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
309
+ ? operations.map(function (op) { return op.operationName; })
310
+ : operations.operationName, "'."));
311
+ }
312
+ return result;
313
+ });
314
+ };
42
315
  }
43
316
 
44
317
  var serializeFetchParameter = function (p, label) {
@@ -47,7 +320,7 @@ var serializeFetchParameter = function (p, label) {
47
320
  serialized = JSON.stringify(p);
48
321
  }
49
322
  catch (e) {
50
- var parseError = __DEV__ ? new globals.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new globals.InvariantError(21);
323
+ var parseError = __DEV__ ? new globals.InvariantError("Network request failed. ".concat(label, " is not serializable: ").concat(e.message)) : new globals.InvariantError(23);
51
324
  parseError.parseError = e;
52
325
  throw parseError;
53
326
  }
@@ -57,6 +330,7 @@ var serializeFetchParameter = function (p, label) {
57
330
  var defaultHttpOptions = {
58
331
  includeQuery: true,
59
332
  includeExtensions: false,
333
+ preserveHeaderCase: false,
60
334
  };
61
335
  var defaultHeaders = {
62
336
  accept: '*/*',
@@ -88,12 +362,13 @@ function selectHttpOptionsAndBodyInternal(operation, printer) {
88
362
  var options = {};
89
363
  var http = {};
90
364
  configs.forEach(function (config) {
91
- options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), headersToLowerCase(config.headers)) });
365
+ options = tslib.__assign(tslib.__assign(tslib.__assign({}, options), config.options), { headers: tslib.__assign(tslib.__assign({}, options.headers), config.headers) });
92
366
  if (config.credentials) {
93
367
  options.credentials = config.credentials;
94
368
  }
95
369
  http = tslib.__assign(tslib.__assign({}, http), config.http);
96
370
  });
371
+ options.headers = removeDuplicateHeaders(options.headers, http.preserveHeaderCase);
97
372
  var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
98
373
  var body = { operationName: operationName, variables: variables };
99
374
  if (http.includeExtensions)
@@ -105,20 +380,28 @@ function selectHttpOptionsAndBodyInternal(operation, printer) {
105
380
  body: body,
106
381
  };
107
382
  }
108
- function headersToLowerCase(headers) {
109
- if (headers) {
110
- var normalized_1 = Object.create(null);
383
+ function removeDuplicateHeaders(headers, preserveHeaderCase) {
384
+ if (!preserveHeaderCase) {
385
+ var normalizedHeaders_1 = Object.create(null);
111
386
  Object.keys(Object(headers)).forEach(function (name) {
112
- normalized_1[name.toLowerCase()] = headers[name];
387
+ normalizedHeaders_1[name.toLowerCase()] = headers[name];
113
388
  });
114
- return normalized_1;
389
+ return normalizedHeaders_1;
115
390
  }
116
- return headers;
391
+ var headerData = Object.create(null);
392
+ Object.keys(Object(headers)).forEach(function (name) {
393
+ headerData[name.toLowerCase()] = { originalName: name, value: headers[name] };
394
+ });
395
+ var normalizedHeaders = Object.create(null);
396
+ Object.keys(headerData).forEach(function (name) {
397
+ normalizedHeaders[headerData[name].originalName] = headerData[name].value;
398
+ });
399
+ return normalizedHeaders;
117
400
  }
118
401
 
119
402
  var checkFetcher = function (fetcher) {
120
403
  if (!fetcher && typeof fetch === 'undefined') {
121
- throw __DEV__ ? new globals.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 globals.InvariantError(20);
404
+ throw __DEV__ ? new globals.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 globals.InvariantError(22);
122
405
  }
123
406
  };
124
407
 
@@ -189,12 +472,12 @@ function rewriteURIForGET(chosenURI, body) {
189
472
  var backupFetch = utilities.maybe(function () { return fetch; });
190
473
  var createHttpLink = function (linkOptions) {
191
474
  if (linkOptions === void 0) { linkOptions = {}; }
192
- 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"]);
475
+ 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"]);
193
476
  if (__DEV__) {
194
477
  checkFetcher(preferredFetch || backupFetch);
195
478
  }
196
479
  var linkConfig = {
197
- http: { includeExtensions: includeExtensions },
480
+ http: { includeExtensions: includeExtensions, preserveHeaderCase: preserveHeaderCase },
198
481
  options: requestOptions.fetchOptions,
199
482
  credentials: requestOptions.credentials,
200
483
  headers: requestOptions.headers,
@@ -250,6 +533,9 @@ var createHttpLink = function (linkOptions) {
250
533
  !operation.query.definitions.some(definitionIsMutation)) {
251
534
  options.method = 'GET';
252
535
  }
536
+ if (utilities.hasDirectives(['defer'], operation.query)) {
537
+ options.headers.accept = "multipart/mixed; deferSpec=20220824, application/json";
538
+ }
253
539
  if (options.method === 'GET') {
254
540
  var _d = rewriteURIForGET(chosenURI, body), newURI = _d.newURI, parseError = _d.parseError;
255
541
  if (parseError) {
@@ -269,23 +555,17 @@ var createHttpLink = function (linkOptions) {
269
555
  var currentFetch = preferredFetch || utilities.maybe(function () { return fetch; }) || backupFetch;
270
556
  currentFetch(chosenURI, options)
271
557
  .then(function (response) {
558
+ var _a;
272
559
  operation.setContext({ response: response });
273
- return response;
274
- })
275
- .then(parseAndCheckHttpResponse(operation))
276
- .then(function (result) {
277
- observer.next(result);
278
- observer.complete();
279
- return result;
280
- })
281
- .catch(function (err) {
282
- if (err.name === 'AbortError')
283
- return;
284
- if (err.result && err.result.errors && err.result.data) {
285
- observer.next(err.result);
560
+ var ctype = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get('content-type');
561
+ if (ctype !== null && /^multipart\/mixed/i.test(ctype)) {
562
+ return readMultipartBody(response, observer);
286
563
  }
287
- observer.error(err);
288
- });
564
+ else {
565
+ return readJsonBody(response, operation, observer);
566
+ }
567
+ })
568
+ .catch(function (err) { return handleError(err, observer); });
289
569
  return function () {
290
570
  if (controller)
291
571
  controller.abort();