@apollo/client 3.9.0-alpha.1 → 3.9.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs +221 -180
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +52 -40
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +52 -40
- package/cache/core/types/common.d.ts +2 -2
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/index.d.ts +1 -2
- package/cache/index.d.ts.map +1 -1
- package/cache/index.js +1 -2
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js +35 -0
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +1 -2
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/object-canon.d.ts +0 -5
- package/cache/inmemory/object-canon.d.ts.map +1 -1
- package/cache/inmemory/object-canon.js +0 -22
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +4 -6
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +4 -4
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +5 -6
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +2 -0
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +12 -4
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +10 -11
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +0 -2
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +0 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +4 -2
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +15 -14
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +39 -33
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +39 -33
- package/dev/dev.cjs +125 -101
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +125 -101
- package/dev/loadErrorMessageHandler.js +2 -2
- package/dev/loadErrorMessageHandler.js.map +1 -1
- package/invariantErrorCodes.js +96 -81
- package/link/core/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/http.cjs +3 -3
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +3 -3
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs +2 -2
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
- package/link/utils/toPromise.js +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/package.json +27 -26
- package/react/cache/QueryReference.d.ts.map +1 -1
- package/react/cache/QueryReference.js +7 -2
- package/react/cache/QueryReference.js.map +1 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +3 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +3 -3
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +2 -2
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -2
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +15 -10
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +15 -10
- package/react/hooks/index.d.ts +1 -0
- package/react/hooks/index.d.ts.map +1 -1
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useQuery.js +1 -1
- package/react/hooks/useReadQuery.d.ts +7 -4
- package/react/hooks/useReadQuery.d.ts.map +1 -1
- package/react/hooks/useReadQuery.js +1 -1
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +2 -2
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/parser/index.js +5 -5
- package/react/parser/parser.cjs +5 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +5 -5
- package/testing/core/core.cjs +2 -2
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +2 -2
- package/testing/core/mocking/mockLink.js +2 -2
- package/testing/internal/ObservableStream.d.ts +26 -0
- package/testing/internal/ObservableStream.d.ts.map +1 -0
- package/testing/internal/ObservableStream.js +101 -0
- package/testing/internal/ObservableStream.js.map +1 -0
- package/testing/internal/index.d.ts +1 -0
- package/testing/internal/index.d.ts.map +1 -1
- package/testing/internal/index.js +1 -0
- package/testing/internal/index.js.map +1 -1
- package/testing/react/MockedProvider.d.ts +1 -0
- package/testing/react/MockedProvider.d.ts.map +1 -1
- package/testing/react/MockedProvider.js +2 -1
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +2 -1
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +2 -1
- package/utilities/common/canonicalStringify.d.ts +4 -0
- package/utilities/common/canonicalStringify.d.ts.map +1 -0
- package/utilities/common/canonicalStringify.js +37 -0
- package/utilities/common/canonicalStringify.js.map +1 -0
- package/utilities/globals/globals.cjs +29 -19
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +29 -19
- package/utilities/globals/invariantWrappers.d.ts.map +1 -1
- package/utilities/globals/invariantWrappers.js +28 -18
- package/utilities/globals/invariantWrappers.js.map +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.js +4 -4
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.d.ts +7 -2
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +8 -20
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.js +2 -2
- package/utilities/index.d.ts +2 -1
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/observables/asyncMap.d.ts.map +1 -1
- package/utilities/observables/asyncMap.js +17 -34
- package/utilities/observables/asyncMap.js.map +1 -1
- package/utilities/subscriptions/relay/index.d.ts +6 -0
- package/utilities/subscriptions/relay/index.d.ts.map +1 -0
- package/utilities/subscriptions/relay/index.js +43 -0
- package/utilities/subscriptions/relay/index.js.map +1 -0
- package/utilities/subscriptions/relay/package.json +8 -0
- package/utilities/subscriptions/relay/relay.cjs +368 -0
- package/utilities/subscriptions/relay/relay.cjs.map +1 -0
- package/utilities/subscriptions/relay/relay.cjs.native.js +368 -0
- package/utilities/subscriptions/shared.d.ts +9 -0
- package/utilities/subscriptions/shared.d.ts.map +1 -0
- package/utilities/subscriptions/shared.js +7 -0
- package/utilities/subscriptions/shared.js.map +1 -0
- package/utilities/subscriptions/urql/index.d.ts +7 -0
- package/utilities/subscriptions/urql/index.d.ts.map +1 -0
- package/utilities/subscriptions/urql/index.js +40 -0
- package/utilities/subscriptions/urql/index.js.map +1 -0
- package/utilities/subscriptions/urql/package.json +8 -0
- package/utilities/subscriptions/urql/urql.cjs +364 -0
- package/utilities/subscriptions/urql/urql.cjs.map +1 -0
- package/utilities/subscriptions/urql/urql.cjs.native.js +364 -0
- package/utilities/utilities.cjs +80 -72
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +80 -72
- package/version.js +1 -1
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utilities = require('../..');
|
|
6
|
+
var tslib = require('tslib');
|
|
7
|
+
var utils = require('../../../link/utils');
|
|
8
|
+
var errors = require('../../../errors');
|
|
9
|
+
var core = require('../../../core');
|
|
10
|
+
|
|
11
|
+
function asyncIterator(source) {
|
|
12
|
+
var _a;
|
|
13
|
+
var iterator = source[Symbol.asyncIterator]();
|
|
14
|
+
return _a = {
|
|
15
|
+
next: function () {
|
|
16
|
+
return iterator.next();
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
_a[Symbol.asyncIterator] = function () {
|
|
20
|
+
return this;
|
|
21
|
+
},
|
|
22
|
+
_a;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function nodeStreamIterator(stream) {
|
|
26
|
+
var cleanup = null;
|
|
27
|
+
var error = null;
|
|
28
|
+
var done = false;
|
|
29
|
+
var data = [];
|
|
30
|
+
var waiting = [];
|
|
31
|
+
function onData(chunk) {
|
|
32
|
+
if (error)
|
|
33
|
+
return;
|
|
34
|
+
if (waiting.length) {
|
|
35
|
+
var shiftedArr = waiting.shift();
|
|
36
|
+
if (Array.isArray(shiftedArr) && shiftedArr[0]) {
|
|
37
|
+
return shiftedArr[0]({ value: chunk, done: false });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
data.push(chunk);
|
|
41
|
+
}
|
|
42
|
+
function onError(err) {
|
|
43
|
+
error = err;
|
|
44
|
+
var all = waiting.slice();
|
|
45
|
+
all.forEach(function (pair) {
|
|
46
|
+
pair[1](err);
|
|
47
|
+
});
|
|
48
|
+
!cleanup || cleanup();
|
|
49
|
+
}
|
|
50
|
+
function onEnd() {
|
|
51
|
+
done = true;
|
|
52
|
+
var all = waiting.slice();
|
|
53
|
+
all.forEach(function (pair) {
|
|
54
|
+
pair[0]({ value: undefined, done: true });
|
|
55
|
+
});
|
|
56
|
+
!cleanup || cleanup();
|
|
57
|
+
}
|
|
58
|
+
cleanup = function () {
|
|
59
|
+
cleanup = null;
|
|
60
|
+
stream.removeListener("data", onData);
|
|
61
|
+
stream.removeListener("error", onError);
|
|
62
|
+
stream.removeListener("end", onEnd);
|
|
63
|
+
stream.removeListener("finish", onEnd);
|
|
64
|
+
stream.removeListener("close", onEnd);
|
|
65
|
+
};
|
|
66
|
+
stream.on("data", onData);
|
|
67
|
+
stream.on("error", onError);
|
|
68
|
+
stream.on("end", onEnd);
|
|
69
|
+
stream.on("finish", onEnd);
|
|
70
|
+
stream.on("close", onEnd);
|
|
71
|
+
function getNext() {
|
|
72
|
+
return new Promise(function (resolve, reject) {
|
|
73
|
+
if (error)
|
|
74
|
+
return reject(error);
|
|
75
|
+
if (data.length)
|
|
76
|
+
return resolve({ value: data.shift(), done: false });
|
|
77
|
+
if (done)
|
|
78
|
+
return resolve({ value: undefined, done: true });
|
|
79
|
+
waiting.push([resolve, reject]);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
var iterator = {
|
|
83
|
+
next: function () {
|
|
84
|
+
return getNext();
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
if (utilities.canUseAsyncIteratorSymbol) {
|
|
88
|
+
iterator[Symbol.asyncIterator] = function () {
|
|
89
|
+
return this;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return iterator;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function promiseIterator(promise) {
|
|
96
|
+
var resolved = false;
|
|
97
|
+
var iterator = {
|
|
98
|
+
next: function () {
|
|
99
|
+
if (resolved)
|
|
100
|
+
return Promise.resolve({
|
|
101
|
+
value: undefined,
|
|
102
|
+
done: true,
|
|
103
|
+
});
|
|
104
|
+
resolved = true;
|
|
105
|
+
return new Promise(function (resolve, reject) {
|
|
106
|
+
promise
|
|
107
|
+
.then(function (value) {
|
|
108
|
+
resolve({ value: value, done: false });
|
|
109
|
+
})
|
|
110
|
+
.catch(reject);
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
if (utilities.canUseAsyncIteratorSymbol) {
|
|
115
|
+
iterator[Symbol.asyncIterator] = function () {
|
|
116
|
+
return this;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return iterator;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function readerIterator(reader) {
|
|
123
|
+
var iterator = {
|
|
124
|
+
next: function () {
|
|
125
|
+
return reader.read();
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
if (utilities.canUseAsyncIteratorSymbol) {
|
|
129
|
+
iterator[Symbol.asyncIterator] = function () {
|
|
130
|
+
return this;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return iterator;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function isNodeResponse(value) {
|
|
137
|
+
return !!value.body;
|
|
138
|
+
}
|
|
139
|
+
function isReadableStream(value) {
|
|
140
|
+
return !!value.getReader;
|
|
141
|
+
}
|
|
142
|
+
function isAsyncIterableIterator(value) {
|
|
143
|
+
return !!(utilities.canUseAsyncIteratorSymbol &&
|
|
144
|
+
value[Symbol.asyncIterator]);
|
|
145
|
+
}
|
|
146
|
+
function isStreamableBlob(value) {
|
|
147
|
+
return !!value.stream;
|
|
148
|
+
}
|
|
149
|
+
function isBlob(value) {
|
|
150
|
+
return !!value.arrayBuffer;
|
|
151
|
+
}
|
|
152
|
+
function isNodeReadableStream(value) {
|
|
153
|
+
return !!value.pipe;
|
|
154
|
+
}
|
|
155
|
+
function responseIterator(response) {
|
|
156
|
+
var body = response;
|
|
157
|
+
if (isNodeResponse(response))
|
|
158
|
+
body = response.body;
|
|
159
|
+
if (isAsyncIterableIterator(body))
|
|
160
|
+
return asyncIterator(body);
|
|
161
|
+
if (isReadableStream(body))
|
|
162
|
+
return readerIterator(body.getReader());
|
|
163
|
+
if (isStreamableBlob(body)) {
|
|
164
|
+
return readerIterator(body.stream().getReader());
|
|
165
|
+
}
|
|
166
|
+
if (isBlob(body))
|
|
167
|
+
return promiseIterator(body.arrayBuffer());
|
|
168
|
+
if (isNodeReadableStream(body))
|
|
169
|
+
return nodeStreamIterator(body);
|
|
170
|
+
throw new Error("Unknown body type for responseIterator. Please pass a streamable response.");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function isNonNullObject(obj) {
|
|
174
|
+
return obj !== null && typeof obj === "object";
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function isApolloPayloadResult(value) {
|
|
178
|
+
return isNonNullObject(value) && "payload" in value;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function readMultipartBody(response, nextValue) {
|
|
182
|
+
var _a;
|
|
183
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
184
|
+
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _b, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
|
|
185
|
+
var _c, _d;
|
|
186
|
+
return tslib.__generator(this, function (_e) {
|
|
187
|
+
switch (_e.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
if (TextDecoder === undefined) {
|
|
190
|
+
throw new Error("TextDecoder must be defined in the environment: please import a polyfill.");
|
|
191
|
+
}
|
|
192
|
+
decoder = new TextDecoder("utf-8");
|
|
193
|
+
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
|
|
194
|
+
delimiter = "boundary=";
|
|
195
|
+
boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter))
|
|
196
|
+
? 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()
|
|
197
|
+
: "-";
|
|
198
|
+
boundary = "\r\n--".concat(boundaryVal);
|
|
199
|
+
buffer = "";
|
|
200
|
+
iterator = responseIterator(response);
|
|
201
|
+
running = true;
|
|
202
|
+
_e.label = 1;
|
|
203
|
+
case 1:
|
|
204
|
+
if (!running) return [3, 3];
|
|
205
|
+
return [4, iterator.next()];
|
|
206
|
+
case 2:
|
|
207
|
+
_b = _e.sent(), value = _b.value, done = _b.done;
|
|
208
|
+
chunk = typeof value === "string" ? value : decoder.decode(value);
|
|
209
|
+
searchFrom = buffer.length - boundary.length + 1;
|
|
210
|
+
running = !done;
|
|
211
|
+
buffer += chunk;
|
|
212
|
+
bi = buffer.indexOf(boundary, searchFrom);
|
|
213
|
+
while (bi > -1) {
|
|
214
|
+
message = void 0;
|
|
215
|
+
_c = [
|
|
216
|
+
buffer.slice(0, bi),
|
|
217
|
+
buffer.slice(bi + boundary.length),
|
|
218
|
+
], message = _c[0], buffer = _c[1];
|
|
219
|
+
i = message.indexOf("\r\n\r\n");
|
|
220
|
+
headers = parseHeaders(message.slice(0, i));
|
|
221
|
+
contentType_1 = headers["content-type"];
|
|
222
|
+
if (contentType_1 &&
|
|
223
|
+
contentType_1.toLowerCase().indexOf("application/json") === -1) {
|
|
224
|
+
throw new Error("Unsupported patch content type: application/json is required.");
|
|
225
|
+
}
|
|
226
|
+
body = message.slice(i);
|
|
227
|
+
if (body) {
|
|
228
|
+
result = parseJsonBody(response, body);
|
|
229
|
+
if (Object.keys(result).length > 1 ||
|
|
230
|
+
"data" in result ||
|
|
231
|
+
"incremental" in result ||
|
|
232
|
+
"errors" in result ||
|
|
233
|
+
"payload" in result) {
|
|
234
|
+
if (isApolloPayloadResult(result)) {
|
|
235
|
+
next = {};
|
|
236
|
+
if ("payload" in result) {
|
|
237
|
+
next = tslib.__assign({}, result.payload);
|
|
238
|
+
}
|
|
239
|
+
if ("errors" in result) {
|
|
240
|
+
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_d = {}, _d[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _d)) });
|
|
241
|
+
}
|
|
242
|
+
nextValue(next);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
nextValue(result);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
else if (Object.keys(result).length === 1 &&
|
|
249
|
+
"hasNext" in result &&
|
|
250
|
+
!result.hasNext) {
|
|
251
|
+
return [2];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
bi = buffer.indexOf(boundary);
|
|
255
|
+
}
|
|
256
|
+
return [3, 1];
|
|
257
|
+
case 3: return [2];
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function parseHeaders(headerText) {
|
|
263
|
+
var headersInit = {};
|
|
264
|
+
headerText.split("\n").forEach(function (line) {
|
|
265
|
+
var i = line.indexOf(":");
|
|
266
|
+
if (i > -1) {
|
|
267
|
+
var name_1 = line.slice(0, i).trim().toLowerCase();
|
|
268
|
+
var value = line.slice(i + 1).trim();
|
|
269
|
+
headersInit[name_1] = value;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
return headersInit;
|
|
273
|
+
}
|
|
274
|
+
function parseJsonBody(response, bodyText) {
|
|
275
|
+
if (response.status >= 300) {
|
|
276
|
+
var getResult = function () {
|
|
277
|
+
try {
|
|
278
|
+
return JSON.parse(bodyText);
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
return bodyText;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
utils.throwServerError(response, getResult(), "Response not successful: Received status code ".concat(response.status));
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
return JSON.parse(bodyText);
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
var parseError = err;
|
|
291
|
+
parseError.name = "ServerParseError";
|
|
292
|
+
parseError.response = response;
|
|
293
|
+
parseError.statusCode = response.status;
|
|
294
|
+
parseError.bodyText = bodyText;
|
|
295
|
+
throw parseError;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function handleError(err, observer) {
|
|
299
|
+
if (err.result && err.result.errors && err.result.data) {
|
|
300
|
+
observer.next(err.result);
|
|
301
|
+
}
|
|
302
|
+
observer.error(err);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
var defaultHttpOptions = {
|
|
306
|
+
includeQuery: true,
|
|
307
|
+
includeExtensions: false,
|
|
308
|
+
preserveHeaderCase: false,
|
|
309
|
+
};
|
|
310
|
+
var defaultHeaders = {
|
|
311
|
+
accept: "*/*",
|
|
312
|
+
"content-type": "application/json",
|
|
313
|
+
};
|
|
314
|
+
var defaultOptions = {
|
|
315
|
+
method: "POST",
|
|
316
|
+
};
|
|
317
|
+
var fallbackHttpConfig = {
|
|
318
|
+
http: defaultHttpOptions,
|
|
319
|
+
headers: defaultHeaders,
|
|
320
|
+
options: defaultOptions,
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
function generateOptionsForMultipartSubscription(headers) {
|
|
324
|
+
var options = tslib.__assign(tslib.__assign({}, fallbackHttpConfig.options), { headers: tslib.__assign(tslib.__assign(tslib.__assign({}, (headers || {})), fallbackHttpConfig.headers), { accept: "multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/json" }) });
|
|
325
|
+
return options;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
var backupFetch = utilities.maybe(function () { return fetch; });
|
|
329
|
+
function createFetchMultipartSubscription(uri, _a) {
|
|
330
|
+
var _b = _a === void 0 ? {} : _a, preferredFetch = _b.fetch, headers = _b.headers;
|
|
331
|
+
return function multipartSubscriptionForwarder(_a) {
|
|
332
|
+
var query = _a.query, variables = _a.variables;
|
|
333
|
+
var body = { variables: variables, query: query };
|
|
334
|
+
var options = generateOptionsForMultipartSubscription(headers || {});
|
|
335
|
+
return new utilities.Observable(function (observer) {
|
|
336
|
+
try {
|
|
337
|
+
options.body = core.serializeFetchParameter(body, "Payload");
|
|
338
|
+
}
|
|
339
|
+
catch (parseError) {
|
|
340
|
+
observer.error(parseError);
|
|
341
|
+
}
|
|
342
|
+
var currentFetch = preferredFetch || utilities.maybe(function () { return fetch; }) || backupFetch;
|
|
343
|
+
var observerNext = observer.next.bind(observer);
|
|
344
|
+
currentFetch(uri, options)
|
|
345
|
+
.then(function (response) {
|
|
346
|
+
var _a;
|
|
347
|
+
var ctype = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
|
|
348
|
+
if (ctype !== null && /^multipart\/mixed/i.test(ctype)) {
|
|
349
|
+
return readMultipartBody(response, observerNext);
|
|
350
|
+
}
|
|
351
|
+
observer.error(new Error("Expected multipart response"));
|
|
352
|
+
})
|
|
353
|
+
.then(function () {
|
|
354
|
+
observer.complete();
|
|
355
|
+
})
|
|
356
|
+
.catch(function (err) {
|
|
357
|
+
handleError(err, observer);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
exports.createFetchMultipartSubscription = createFetchMultipartSubscription;
|
|
364
|
+
//# sourceMappingURL=urql.cjs.map
|
package/utilities/utilities.cjs
CHANGED
|
@@ -20,7 +20,7 @@ function shouldInclude(_a, variables) {
|
|
|
20
20
|
if (ifArgument.value.kind === "Variable") {
|
|
21
21
|
evaledValue =
|
|
22
22
|
variables && variables[ifArgument.value.name.value];
|
|
23
|
-
globals.invariant(evaledValue !== void 0,
|
|
23
|
+
globals.invariant(evaledValue !== void 0, 67, directive.name.value);
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
26
|
evaledValue = ifArgument.value.value;
|
|
@@ -70,12 +70,12 @@ function getInclusionDirectives(directives) {
|
|
|
70
70
|
return;
|
|
71
71
|
var directiveArguments = directive.arguments;
|
|
72
72
|
var directiveName = directive.name.value;
|
|
73
|
-
globals.invariant(directiveArguments && directiveArguments.length === 1,
|
|
73
|
+
globals.invariant(directiveArguments && directiveArguments.length === 1, 68, directiveName);
|
|
74
74
|
var ifArgument = directiveArguments[0];
|
|
75
|
-
globals.invariant(ifArgument.name && ifArgument.name.value === "if",
|
|
75
|
+
globals.invariant(ifArgument.name && ifArgument.name.value === "if", 69, directiveName);
|
|
76
76
|
var ifValue = ifArgument.value;
|
|
77
77
|
globals.invariant(ifValue &&
|
|
78
|
-
(ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"),
|
|
78
|
+
(ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 70, directiveName);
|
|
79
79
|
result.push({ directive: directive, ifArgument: ifArgument });
|
|
80
80
|
});
|
|
81
81
|
}
|
|
@@ -107,7 +107,7 @@ function getFragmentQueryDocument(document, fragmentName) {
|
|
|
107
107
|
document.definitions.forEach(function (definition) {
|
|
108
108
|
if (definition.kind === "OperationDefinition") {
|
|
109
109
|
throw globals.newInvariantError(
|
|
110
|
-
|
|
110
|
+
71,
|
|
111
111
|
definition.operation,
|
|
112
112
|
definition.name ? " named '".concat(definition.name.value, "'") : ""
|
|
113
113
|
);
|
|
@@ -117,7 +117,7 @@ function getFragmentQueryDocument(document, fragmentName) {
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
if (typeof actualFragmentName === "undefined") {
|
|
120
|
-
globals.invariant(fragments.length === 1,
|
|
120
|
+
globals.invariant(fragments.length === 1, 72, fragments.length);
|
|
121
121
|
actualFragmentName = fragments[0].name.value;
|
|
122
122
|
}
|
|
123
123
|
var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
|
|
@@ -158,7 +158,7 @@ function getFragmentFromSelection(selection, fragmentMap) {
|
|
|
158
158
|
return fragmentMap(fragmentName);
|
|
159
159
|
}
|
|
160
160
|
var fragment = fragmentMap && fragmentMap[fragmentName];
|
|
161
|
-
globals.invariant(fragment,
|
|
161
|
+
globals.invariant(fragment, 73, fragmentName);
|
|
162
162
|
return fragment || null;
|
|
163
163
|
}
|
|
164
164
|
default:
|
|
@@ -166,6 +166,43 @@ function getFragmentFromSelection(selection, fragmentMap) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
var canonicalStringify = Object.assign(function canonicalStringify(value) {
|
|
170
|
+
return JSON.stringify(value, stableObjectReplacer);
|
|
171
|
+
}, {
|
|
172
|
+
reset: function () {
|
|
173
|
+
sortingMap.clear();
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
var sortingMap = new Map();
|
|
177
|
+
function stableObjectReplacer(key, value) {
|
|
178
|
+
if (value && typeof value === "object") {
|
|
179
|
+
var proto = Object.getPrototypeOf(value);
|
|
180
|
+
if (proto === Object.prototype || proto === null) {
|
|
181
|
+
var keys = Object.keys(value);
|
|
182
|
+
if (keys.every(everyKeyInOrder))
|
|
183
|
+
return value;
|
|
184
|
+
var unsortedKey = JSON.stringify(keys);
|
|
185
|
+
var sortedKeys = sortingMap.get(unsortedKey);
|
|
186
|
+
if (!sortedKeys) {
|
|
187
|
+
keys.sort();
|
|
188
|
+
var sortedKey = JSON.stringify(keys);
|
|
189
|
+
sortedKeys = sortingMap.get(sortedKey) || keys;
|
|
190
|
+
sortingMap.set(unsortedKey, sortedKeys);
|
|
191
|
+
sortingMap.set(sortedKey, sortedKeys);
|
|
192
|
+
}
|
|
193
|
+
var sortedObject_1 = Object.create(proto);
|
|
194
|
+
sortedKeys.forEach(function (key) {
|
|
195
|
+
sortedObject_1[key] = value[key];
|
|
196
|
+
});
|
|
197
|
+
return sortedObject_1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return value;
|
|
201
|
+
}
|
|
202
|
+
function everyKeyInOrder(key, i, keys) {
|
|
203
|
+
return i === 0 || keys[i - 1] <= key;
|
|
204
|
+
}
|
|
205
|
+
|
|
169
206
|
function makeReference(id) {
|
|
170
207
|
return { __ref: String(id) };
|
|
171
208
|
}
|
|
@@ -236,7 +273,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
|
|
|
236
273
|
argObj[name.value] = null;
|
|
237
274
|
}
|
|
238
275
|
else {
|
|
239
|
-
throw globals.newInvariantError(
|
|
276
|
+
throw globals.newInvariantError(82, name.value, value.kind);
|
|
240
277
|
}
|
|
241
278
|
}
|
|
242
279
|
function storeKeyNameFromField(field, variables) {
|
|
@@ -272,6 +309,7 @@ var KNOWN_DIRECTIVES = [
|
|
|
272
309
|
"export",
|
|
273
310
|
"nonreactive",
|
|
274
311
|
];
|
|
312
|
+
var storeKeyNameStringify = canonicalStringify;
|
|
275
313
|
var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
|
|
276
314
|
if (args &&
|
|
277
315
|
directives &&
|
|
@@ -287,7 +325,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
|
|
|
287
325
|
filterKeys.forEach(function (key) {
|
|
288
326
|
filteredArgs_1[key] = args[key];
|
|
289
327
|
});
|
|
290
|
-
return "".concat(directives["connection"]["key"], "(").concat(
|
|
328
|
+
return "".concat(directives["connection"]["key"], "(").concat(storeKeyNameStringify(filteredArgs_1), ")");
|
|
291
329
|
}
|
|
292
330
|
else {
|
|
293
331
|
return directives["connection"]["key"];
|
|
@@ -295,7 +333,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
|
|
|
295
333
|
}
|
|
296
334
|
var completeFieldName = fieldName;
|
|
297
335
|
if (args) {
|
|
298
|
-
var stringifiedArgs =
|
|
336
|
+
var stringifiedArgs = storeKeyNameStringify(args);
|
|
299
337
|
completeFieldName += "(".concat(stringifiedArgs, ")");
|
|
300
338
|
}
|
|
301
339
|
if (directives) {
|
|
@@ -303,7 +341,7 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
|
|
|
303
341
|
if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
|
|
304
342
|
return;
|
|
305
343
|
if (directives[key] && Object.keys(directives[key]).length) {
|
|
306
|
-
completeFieldName += "@".concat(key, "(").concat(
|
|
344
|
+
completeFieldName += "@".concat(key, "(").concat(storeKeyNameStringify(directives[key]), ")");
|
|
307
345
|
}
|
|
308
346
|
else {
|
|
309
347
|
completeFieldName += "@".concat(key);
|
|
@@ -313,25 +351,11 @@ var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
|
|
|
313
351
|
return completeFieldName;
|
|
314
352
|
}, {
|
|
315
353
|
setStringify: function (s) {
|
|
316
|
-
var previous =
|
|
317
|
-
|
|
354
|
+
var previous = storeKeyNameStringify;
|
|
355
|
+
storeKeyNameStringify = s;
|
|
318
356
|
return previous;
|
|
319
357
|
},
|
|
320
358
|
});
|
|
321
|
-
var stringify = function defaultStringify(value) {
|
|
322
|
-
return JSON.stringify(value, stringifyReplacer);
|
|
323
|
-
};
|
|
324
|
-
function stringifyReplacer(_key, value) {
|
|
325
|
-
if (isNonNullObject(value) && !Array.isArray(value)) {
|
|
326
|
-
value = Object.keys(value)
|
|
327
|
-
.sort()
|
|
328
|
-
.reduce(function (copy, key) {
|
|
329
|
-
copy[key] = value[key];
|
|
330
|
-
return copy;
|
|
331
|
-
}, {});
|
|
332
|
-
}
|
|
333
|
-
return value;
|
|
334
|
-
}
|
|
335
359
|
function argumentsObjectFromField(field, variables) {
|
|
336
360
|
if (field.arguments && field.arguments.length) {
|
|
337
361
|
var argObj_1 = {};
|
|
@@ -383,16 +407,16 @@ function isInlineFragment(selection) {
|
|
|
383
407
|
}
|
|
384
408
|
|
|
385
409
|
function checkDocument(doc) {
|
|
386
|
-
globals.invariant(doc && doc.kind === "Document",
|
|
410
|
+
globals.invariant(doc && doc.kind === "Document", 74);
|
|
387
411
|
var operations = doc.definitions
|
|
388
412
|
.filter(function (d) { return d.kind !== "FragmentDefinition"; })
|
|
389
413
|
.map(function (definition) {
|
|
390
414
|
if (definition.kind !== "OperationDefinition") {
|
|
391
|
-
throw globals.newInvariantError(
|
|
415
|
+
throw globals.newInvariantError(75, definition.kind);
|
|
392
416
|
}
|
|
393
417
|
return definition;
|
|
394
418
|
});
|
|
395
|
-
globals.invariant(operations.length <= 1,
|
|
419
|
+
globals.invariant(operations.length <= 1, 76, operations.length);
|
|
396
420
|
return doc;
|
|
397
421
|
}
|
|
398
422
|
function getOperationDefinition(doc) {
|
|
@@ -415,14 +439,14 @@ function getFragmentDefinitions(doc) {
|
|
|
415
439
|
}
|
|
416
440
|
function getQueryDefinition(doc) {
|
|
417
441
|
var queryDef = getOperationDefinition(doc);
|
|
418
|
-
globals.invariant(queryDef && queryDef.operation === "query",
|
|
442
|
+
globals.invariant(queryDef && queryDef.operation === "query", 77);
|
|
419
443
|
return queryDef;
|
|
420
444
|
}
|
|
421
445
|
function getFragmentDefinition(doc) {
|
|
422
|
-
globals.invariant(doc.kind === "Document",
|
|
423
|
-
globals.invariant(doc.definitions.length <= 1,
|
|
446
|
+
globals.invariant(doc.kind === "Document", 78);
|
|
447
|
+
globals.invariant(doc.definitions.length <= 1, 79);
|
|
424
448
|
var fragmentDef = doc.definitions[0];
|
|
425
|
-
globals.invariant(fragmentDef.kind === "FragmentDefinition",
|
|
449
|
+
globals.invariant(fragmentDef.kind === "FragmentDefinition", 80);
|
|
426
450
|
return fragmentDef;
|
|
427
451
|
}
|
|
428
452
|
function getMainDefinition(queryDoc) {
|
|
@@ -445,7 +469,7 @@ function getMainDefinition(queryDoc) {
|
|
|
445
469
|
if (fragmentDefinition) {
|
|
446
470
|
return fragmentDefinition;
|
|
447
471
|
}
|
|
448
|
-
throw globals.newInvariantError(
|
|
472
|
+
throw globals.newInvariantError(81);
|
|
449
473
|
}
|
|
450
474
|
function getDefaultValues(definition) {
|
|
451
475
|
var defaultValues = Object.create(null);
|
|
@@ -517,7 +541,7 @@ var DocumentTransform = (function () {
|
|
|
517
541
|
return;
|
|
518
542
|
var cacheKeys = this.getCacheKey(document);
|
|
519
543
|
if (cacheKeys) {
|
|
520
|
-
globals.invariant(Array.isArray(cacheKeys),
|
|
544
|
+
globals.invariant(Array.isArray(cacheKeys), 66);
|
|
521
545
|
return this.stableCacheKeys.lookupArray(cacheKeys);
|
|
522
546
|
}
|
|
523
547
|
};
|
|
@@ -613,7 +637,7 @@ function removeDirectivesFromDocument(directives, doc) {
|
|
|
613
637
|
return getInUseByFragmentName(ancestor.name.value);
|
|
614
638
|
}
|
|
615
639
|
}
|
|
616
|
-
globalThis.__DEV__ !== false && globals.invariant.error(
|
|
640
|
+
globalThis.__DEV__ !== false && globals.invariant.error(83);
|
|
617
641
|
return null;
|
|
618
642
|
};
|
|
619
643
|
var operationCount = 0;
|
|
@@ -800,7 +824,7 @@ var connectionRemoveConfig = {
|
|
|
800
824
|
if (willRemove) {
|
|
801
825
|
if (!directive.arguments ||
|
|
802
826
|
!directive.arguments.some(function (arg) { return arg.name.value === "key"; })) {
|
|
803
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
827
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(84);
|
|
804
828
|
}
|
|
805
829
|
}
|
|
806
830
|
return willRemove;
|
|
@@ -1249,48 +1273,31 @@ function iterateObserversSafely(observers, method, argument) {
|
|
|
1249
1273
|
|
|
1250
1274
|
function asyncMap(observable, mapFn, catchFn) {
|
|
1251
1275
|
return new zenObservableTs.Observable(function (observer) {
|
|
1252
|
-
var next = observer.next, error = observer.error, complete = observer.complete;
|
|
1253
|
-
var activeCallbackCount = 0;
|
|
1254
|
-
var completed = false;
|
|
1255
1276
|
var promiseQueue = {
|
|
1256
1277
|
then: function (callback) {
|
|
1257
1278
|
return new Promise(function (resolve) { return resolve(callback()); });
|
|
1258
1279
|
},
|
|
1259
1280
|
};
|
|
1260
|
-
function makeCallback(examiner,
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
--activeCallbackCount;
|
|
1275
|
-
throw error;
|
|
1276
|
-
})
|
|
1277
|
-
.catch(function (caught) {
|
|
1278
|
-
error && error.call(observer, caught);
|
|
1279
|
-
});
|
|
1280
|
-
};
|
|
1281
|
-
}
|
|
1282
|
-
else {
|
|
1283
|
-
return function (arg) { return delegate && delegate.call(observer, arg); };
|
|
1284
|
-
}
|
|
1281
|
+
function makeCallback(examiner, key) {
|
|
1282
|
+
return function (arg) {
|
|
1283
|
+
if (examiner) {
|
|
1284
|
+
var both = function () {
|
|
1285
|
+
return observer.closed
|
|
1286
|
+
? 0
|
|
1287
|
+
: examiner(arg);
|
|
1288
|
+
};
|
|
1289
|
+
promiseQueue = promiseQueue.then(both, both).then(function (result) { return observer.next(result); }, function (error) { return observer.error(error); });
|
|
1290
|
+
}
|
|
1291
|
+
else {
|
|
1292
|
+
observer[key](arg);
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1285
1295
|
}
|
|
1286
1296
|
var handler = {
|
|
1287
|
-
next: makeCallback(mapFn, next),
|
|
1288
|
-
error: makeCallback(catchFn, error),
|
|
1297
|
+
next: makeCallback(mapFn, "next"),
|
|
1298
|
+
error: makeCallback(catchFn, "error"),
|
|
1289
1299
|
complete: function () {
|
|
1290
|
-
|
|
1291
|
-
if (!activeCallbackCount) {
|
|
1292
|
-
complete && complete.call(observer);
|
|
1293
|
-
}
|
|
1300
|
+
promiseQueue.then(function () { return observer.complete(); });
|
|
1294
1301
|
},
|
|
1295
1302
|
};
|
|
1296
1303
|
var sub = observable.subscribe(handler);
|
|
@@ -1591,6 +1598,7 @@ exports.canUseLayoutEffect = canUseLayoutEffect;
|
|
|
1591
1598
|
exports.canUseSymbol = canUseSymbol;
|
|
1592
1599
|
exports.canUseWeakMap = canUseWeakMap;
|
|
1593
1600
|
exports.canUseWeakSet = canUseWeakSet;
|
|
1601
|
+
exports.canonicalStringify = canonicalStringify;
|
|
1594
1602
|
exports.checkDocument = checkDocument;
|
|
1595
1603
|
exports.cloneDeep = cloneDeep;
|
|
1596
1604
|
exports.compact = compact;
|