1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var globals = require('./globals');
|
6 | var graphql = require('graphql');
|
7 | var trie = require('@wry/trie');
|
8 | var tslib = require('tslib');
|
9 | var caches = require('@wry/caches');
|
10 | var optimism = require('optimism');
|
11 | var zenObservableTs = require('zen-observable-ts');
|
12 | require('symbol-observable');
|
13 |
|
14 | function shouldInclude(_a, variables) {
|
15 | var directives = _a.directives;
|
16 | if (!directives || !directives.length) {
|
17 | return true;
|
18 | }
|
19 | return getInclusionDirectives(directives).every(function (_a) {
|
20 | var directive = _a.directive, ifArgument = _a.ifArgument;
|
21 | var evaledValue = false;
|
22 | if (ifArgument.value.kind === "Variable") {
|
23 | evaledValue =
|
24 | variables && variables[ifArgument.value.name.value];
|
25 | globals.invariant(evaledValue !== void 0, 70, directive.name.value);
|
26 | }
|
27 | else {
|
28 | evaledValue = ifArgument.value.value;
|
29 | }
|
30 | return directive.name.value === "skip" ? !evaledValue : evaledValue;
|
31 | });
|
32 | }
|
33 | function getDirectiveNames(root) {
|
34 | var names = [];
|
35 | graphql.visit(root, {
|
36 | Directive: function (node) {
|
37 | names.push(node.name.value);
|
38 | },
|
39 | });
|
40 | return names;
|
41 | }
|
42 | var hasAnyDirectives = function (names, root) {
|
43 | return hasDirectives(names, root, false);
|
44 | };
|
45 | var hasAllDirectives = function (names, root) {
|
46 | return hasDirectives(names, root, true);
|
47 | };
|
48 | function hasDirectives(names, root, all) {
|
49 | var nameSet = new Set(names);
|
50 | var uniqueCount = nameSet.size;
|
51 | graphql.visit(root, {
|
52 | Directive: function (node) {
|
53 | if (nameSet.delete(node.name.value) && (!all || !nameSet.size)) {
|
54 | return graphql.BREAK;
|
55 | }
|
56 | },
|
57 | });
|
58 | return all ? !nameSet.size : nameSet.size < uniqueCount;
|
59 | }
|
60 | function hasClientExports(document) {
|
61 | return document && hasDirectives(["client", "export"], document, true);
|
62 | }
|
63 | function isInclusionDirective(_a) {
|
64 | var value = _a.name.value;
|
65 | return value === "skip" || value === "include";
|
66 | }
|
67 | function getInclusionDirectives(directives) {
|
68 | var result = [];
|
69 | if (directives && directives.length) {
|
70 | directives.forEach(function (directive) {
|
71 | if (!isInclusionDirective(directive))
|
72 | return;
|
73 | var directiveArguments = directive.arguments;
|
74 | var directiveName = directive.name.value;
|
75 | globals.invariant(directiveArguments && directiveArguments.length === 1, 71, directiveName);
|
76 | var ifArgument = directiveArguments[0];
|
77 | globals.invariant(ifArgument.name && ifArgument.name.value === "if", 72, directiveName);
|
78 | var ifValue = ifArgument.value;
|
79 | globals.invariant(ifValue &&
|
80 | (ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 73, directiveName);
|
81 | result.push({ directive: directive, ifArgument: ifArgument });
|
82 | });
|
83 | }
|
84 | return result;
|
85 | }
|
86 |
|
87 | var isReactNative = globals.maybe(function () { return navigator.product; }) == "ReactNative";
|
88 | var canUseWeakMap = typeof WeakMap === "function" &&
|
89 | !(isReactNative && !global.HermesInternal);
|
90 | var canUseWeakSet = typeof WeakSet === "function";
|
91 | var canUseSymbol = typeof Symbol === "function" && typeof Symbol.for === "function";
|
92 | var canUseAsyncIteratorSymbol = canUseSymbol && Symbol.asyncIterator;
|
93 | var canUseDOM = typeof globals.maybe(function () { return window.document.createElement; }) === "function";
|
94 | var usingJSDOM =
|
95 | globals.maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
|
96 | var canUseLayoutEffect = (canUseDOM || isReactNative) && !usingJSDOM;
|
97 |
|
98 | function isNonNullObject(obj) {
|
99 | return obj !== null && typeof obj === "object";
|
100 | }
|
101 | function isPlainObject(obj) {
|
102 | return (obj !== null &&
|
103 | typeof obj === "object" &&
|
104 | (Object.getPrototypeOf(obj) === Object.prototype ||
|
105 | Object.getPrototypeOf(obj) === null));
|
106 | }
|
107 |
|
108 | function getFragmentQueryDocument(document, fragmentName) {
|
109 | var actualFragmentName = fragmentName;
|
110 | var fragments = [];
|
111 | document.definitions.forEach(function (definition) {
|
112 | if (definition.kind === "OperationDefinition") {
|
113 | throw globals.newInvariantError(
|
114 | 74,
|
115 | definition.operation,
|
116 | definition.name ? " named '".concat(definition.name.value, "'") : ""
|
117 | );
|
118 | }
|
119 | if (definition.kind === "FragmentDefinition") {
|
120 | fragments.push(definition);
|
121 | }
|
122 | });
|
123 | if (typeof actualFragmentName === "undefined") {
|
124 | globals.invariant(fragments.length === 1, 75, fragments.length);
|
125 | actualFragmentName = fragments[0].name.value;
|
126 | }
|
127 | var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
|
128 | {
|
129 | kind: "OperationDefinition",
|
130 | operation: "query",
|
131 | selectionSet: {
|
132 | kind: "SelectionSet",
|
133 | selections: [
|
134 | {
|
135 | kind: "FragmentSpread",
|
136 | name: {
|
137 | kind: "Name",
|
138 | value: actualFragmentName,
|
139 | },
|
140 | },
|
141 | ],
|
142 | },
|
143 | }
|
144 | ], document.definitions, true) });
|
145 | return query;
|
146 | }
|
147 | function createFragmentMap(fragments) {
|
148 | if (fragments === void 0) { fragments = []; }
|
149 | var symTable = {};
|
150 | fragments.forEach(function (fragment) {
|
151 | symTable[fragment.name.value] = fragment;
|
152 | });
|
153 | return symTable;
|
154 | }
|
155 | function getFragmentFromSelection(selection, fragmentMap) {
|
156 | switch (selection.kind) {
|
157 | case "InlineFragment":
|
158 | return selection;
|
159 | case "FragmentSpread": {
|
160 | var fragmentName = selection.name.value;
|
161 | if (typeof fragmentMap === "function") {
|
162 | return fragmentMap(fragmentName);
|
163 | }
|
164 | var fragment = fragmentMap && fragmentMap[fragmentName];
|
165 | globals.invariant(fragment, 76, fragmentName);
|
166 | return fragment || null;
|
167 | }
|
168 | default:
|
169 | return null;
|
170 | }
|
171 | }
|
172 |
|
173 | var scheduledCleanup = new WeakSet();
|
174 | function schedule(cache) {
|
175 | if (cache.size <= (cache.max || -1)) {
|
176 | return;
|
177 | }
|
178 | if (!scheduledCleanup.has(cache)) {
|
179 | scheduledCleanup.add(cache);
|
180 | setTimeout(function () {
|
181 | cache.clean();
|
182 | scheduledCleanup.delete(cache);
|
183 | }, 100);
|
184 | }
|
185 | }
|
186 | var AutoCleanedWeakCache = function (max, dispose) {
|
187 | var cache = new caches.WeakCache(max, dispose);
|
188 | cache.set = function (key, value) {
|
189 | var ret = caches.WeakCache.prototype.set.call(this, key, value);
|
190 | schedule(this);
|
191 | return ret;
|
192 | };
|
193 | return cache;
|
194 | };
|
195 | var AutoCleanedStrongCache = function (max, dispose) {
|
196 | var cache = new caches.StrongCache(max, dispose);
|
197 | cache.set = function (key, value) {
|
198 | var ret = caches.StrongCache.prototype.set.call(this, key, value);
|
199 | schedule(this);
|
200 | return ret;
|
201 | };
|
202 | return cache;
|
203 | };
|
204 |
|
205 | var cacheSizeSymbol = Symbol.for("apollo.cacheSize");
|
206 | var cacheSizes = tslib.__assign({}, globals.global[cacheSizeSymbol]);
|
207 |
|
208 | var globalCaches = {};
|
209 | function registerGlobalCache(name, getSize) {
|
210 | globalCaches[name] = getSize;
|
211 | }
|
212 |
|
213 | var canonicalStringify = Object.assign(function canonicalStringify(value) {
|
214 | return JSON.stringify(value, stableObjectReplacer);
|
215 | }, {
|
216 | reset: function () {
|
217 | sortingMap = new AutoCleanedStrongCache(cacheSizes.canonicalStringify || 1000 );
|
218 | },
|
219 | });
|
220 | if (globalThis.__DEV__ !== false) {
|
221 | registerGlobalCache("canonicalStringify", function () { return sortingMap.size; });
|
222 | }
|
223 | var sortingMap;
|
224 | canonicalStringify.reset();
|
225 | function stableObjectReplacer(key, value) {
|
226 | if (value && typeof value === "object") {
|
227 | var proto = Object.getPrototypeOf(value);
|
228 | if (proto === Object.prototype || proto === null) {
|
229 | var keys = Object.keys(value);
|
230 | if (keys.every(everyKeyInOrder))
|
231 | return value;
|
232 | var unsortedKey = JSON.stringify(keys);
|
233 | var sortedKeys = sortingMap.get(unsortedKey);
|
234 | if (!sortedKeys) {
|
235 | keys.sort();
|
236 | var sortedKey = JSON.stringify(keys);
|
237 | sortedKeys = sortingMap.get(sortedKey) || keys;
|
238 | sortingMap.set(unsortedKey, sortedKeys);
|
239 | sortingMap.set(sortedKey, sortedKeys);
|
240 | }
|
241 | var sortedObject_1 = Object.create(proto);
|
242 | sortedKeys.forEach(function (key) {
|
243 | sortedObject_1[key] = value[key];
|
244 | });
|
245 | return sortedObject_1;
|
246 | }
|
247 | }
|
248 | return value;
|
249 | }
|
250 | function everyKeyInOrder(key, i, keys) {
|
251 | return i === 0 || keys[i - 1] <= key;
|
252 | }
|
253 |
|
254 | function makeReference(id) {
|
255 | return { __ref: String(id) };
|
256 | }
|
257 | function isReference(obj) {
|
258 | return Boolean(obj && typeof obj === "object" && typeof obj.__ref === "string");
|
259 | }
|
260 | function isDocumentNode(value) {
|
261 | return (isNonNullObject(value) &&
|
262 | value.kind === "Document" &&
|
263 | Array.isArray(value.definitions));
|
264 | }
|
265 | function isStringValue(value) {
|
266 | return value.kind === "StringValue";
|
267 | }
|
268 | function isBooleanValue(value) {
|
269 | return value.kind === "BooleanValue";
|
270 | }
|
271 | function isIntValue(value) {
|
272 | return value.kind === "IntValue";
|
273 | }
|
274 | function isFloatValue(value) {
|
275 | return value.kind === "FloatValue";
|
276 | }
|
277 | function isVariable(value) {
|
278 | return value.kind === "Variable";
|
279 | }
|
280 | function isObjectValue(value) {
|
281 | return value.kind === "ObjectValue";
|
282 | }
|
283 | function isListValue(value) {
|
284 | return value.kind === "ListValue";
|
285 | }
|
286 | function isEnumValue(value) {
|
287 | return value.kind === "EnumValue";
|
288 | }
|
289 | function isNullValue(value) {
|
290 | return value.kind === "NullValue";
|
291 | }
|
292 | function valueToObjectRepresentation(argObj, name, value, variables) {
|
293 | if (isIntValue(value) || isFloatValue(value)) {
|
294 | argObj[name.value] = Number(value.value);
|
295 | }
|
296 | else if (isBooleanValue(value) || isStringValue(value)) {
|
297 | argObj[name.value] = value.value;
|
298 | }
|
299 | else if (isObjectValue(value)) {
|
300 | var nestedArgObj_1 = {};
|
301 | value.fields.map(function (obj) {
|
302 | return valueToObjectRepresentation(nestedArgObj_1, obj.name, obj.value, variables);
|
303 | });
|
304 | argObj[name.value] = nestedArgObj_1;
|
305 | }
|
306 | else if (isVariable(value)) {
|
307 | var variableValue = (variables || {})[value.name.value];
|
308 | argObj[name.value] = variableValue;
|
309 | }
|
310 | else if (isListValue(value)) {
|
311 | argObj[name.value] = value.values.map(function (listValue) {
|
312 | var nestedArgArrayObj = {};
|
313 | valueToObjectRepresentation(nestedArgArrayObj, name, listValue, variables);
|
314 | return nestedArgArrayObj[name.value];
|
315 | });
|
316 | }
|
317 | else if (isEnumValue(value)) {
|
318 | argObj[name.value] = value.value;
|
319 | }
|
320 | else if (isNullValue(value)) {
|
321 | argObj[name.value] = null;
|
322 | }
|
323 | else {
|
324 | throw globals.newInvariantError(85, name.value, value.kind);
|
325 | }
|
326 | }
|
327 | function storeKeyNameFromField(field, variables) {
|
328 | var directivesObj = null;
|
329 | if (field.directives) {
|
330 | directivesObj = {};
|
331 | field.directives.forEach(function (directive) {
|
332 | directivesObj[directive.name.value] = {};
|
333 | if (directive.arguments) {
|
334 | directive.arguments.forEach(function (_a) {
|
335 | var name = _a.name, value = _a.value;
|
336 | return valueToObjectRepresentation(directivesObj[directive.name.value], name, value, variables);
|
337 | });
|
338 | }
|
339 | });
|
340 | }
|
341 | var argObj = null;
|
342 | if (field.arguments && field.arguments.length) {
|
343 | argObj = {};
|
344 | field.arguments.forEach(function (_a) {
|
345 | var name = _a.name, value = _a.value;
|
346 | return valueToObjectRepresentation(argObj, name, value, variables);
|
347 | });
|
348 | }
|
349 | return getStoreKeyName(field.name.value, argObj, directivesObj);
|
350 | }
|
351 | var KNOWN_DIRECTIVES = [
|
352 | "connection",
|
353 | "include",
|
354 | "skip",
|
355 | "client",
|
356 | "rest",
|
357 | "export",
|
358 | "nonreactive",
|
359 | ];
|
360 | var storeKeyNameStringify = canonicalStringify;
|
361 | var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
|
362 | if (args &&
|
363 | directives &&
|
364 | directives["connection"] &&
|
365 | directives["connection"]["key"]) {
|
366 | if (directives["connection"]["filter"] &&
|
367 | directives["connection"]["filter"].length > 0) {
|
368 | var filterKeys = directives["connection"]["filter"] ?
|
369 | directives["connection"]["filter"]
|
370 | : [];
|
371 | filterKeys.sort();
|
372 | var filteredArgs_1 = {};
|
373 | filterKeys.forEach(function (key) {
|
374 | filteredArgs_1[key] = args[key];
|
375 | });
|
376 | return "".concat(directives["connection"]["key"], "(").concat(storeKeyNameStringify(filteredArgs_1), ")");
|
377 | }
|
378 | else {
|
379 | return directives["connection"]["key"];
|
380 | }
|
381 | }
|
382 | var completeFieldName = fieldName;
|
383 | if (args) {
|
384 | var stringifiedArgs = storeKeyNameStringify(args);
|
385 | completeFieldName += "(".concat(stringifiedArgs, ")");
|
386 | }
|
387 | if (directives) {
|
388 | Object.keys(directives).forEach(function (key) {
|
389 | if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
|
390 | return;
|
391 | if (directives[key] && Object.keys(directives[key]).length) {
|
392 | completeFieldName += "@".concat(key, "(").concat(storeKeyNameStringify(directives[key]), ")");
|
393 | }
|
394 | else {
|
395 | completeFieldName += "@".concat(key);
|
396 | }
|
397 | });
|
398 | }
|
399 | return completeFieldName;
|
400 | }, {
|
401 | setStringify: function (s) {
|
402 | var previous = storeKeyNameStringify;
|
403 | storeKeyNameStringify = s;
|
404 | return previous;
|
405 | },
|
406 | });
|
407 | function argumentsObjectFromField(field, variables) {
|
408 | if (field.arguments && field.arguments.length) {
|
409 | var argObj_1 = {};
|
410 | field.arguments.forEach(function (_a) {
|
411 | var name = _a.name, value = _a.value;
|
412 | return valueToObjectRepresentation(argObj_1, name, value, variables);
|
413 | });
|
414 | return argObj_1;
|
415 | }
|
416 | return null;
|
417 | }
|
418 | function resultKeyNameFromField(field) {
|
419 | return field.alias ? field.alias.value : field.name.value;
|
420 | }
|
421 | function getTypenameFromResult(result, selectionSet, fragmentMap) {
|
422 | var fragments;
|
423 | for (var _i = 0, _a = selectionSet.selections; _i < _a.length; _i++) {
|
424 | var selection = _a[_i];
|
425 | if (isField(selection)) {
|
426 | if (selection.name.value === "__typename") {
|
427 | return result[resultKeyNameFromField(selection)];
|
428 | }
|
429 | }
|
430 | else if (fragments) {
|
431 | fragments.push(selection);
|
432 | }
|
433 | else {
|
434 | fragments = [selection];
|
435 | }
|
436 | }
|
437 | if (typeof result.__typename === "string") {
|
438 | return result.__typename;
|
439 | }
|
440 | if (fragments) {
|
441 | for (var _b = 0, fragments_1 = fragments; _b < fragments_1.length; _b++) {
|
442 | var selection = fragments_1[_b];
|
443 | var typename = getTypenameFromResult(result, getFragmentFromSelection(selection, fragmentMap).selectionSet, fragmentMap);
|
444 | if (typeof typename === "string") {
|
445 | return typename;
|
446 | }
|
447 | }
|
448 | }
|
449 | }
|
450 | function isField(selection) {
|
451 | return selection.kind === "Field";
|
452 | }
|
453 | function isInlineFragment(selection) {
|
454 | return selection.kind === "InlineFragment";
|
455 | }
|
456 |
|
457 | function checkDocument(doc) {
|
458 | globals.invariant(doc && doc.kind === "Document", 77);
|
459 | var operations = doc.definitions
|
460 | .filter(function (d) { return d.kind !== "FragmentDefinition"; })
|
461 | .map(function (definition) {
|
462 | if (definition.kind !== "OperationDefinition") {
|
463 | throw globals.newInvariantError(78, definition.kind);
|
464 | }
|
465 | return definition;
|
466 | });
|
467 | globals.invariant(operations.length <= 1, 79, operations.length);
|
468 | return doc;
|
469 | }
|
470 | function getOperationDefinition(doc) {
|
471 | checkDocument(doc);
|
472 | return doc.definitions.filter(function (definition) {
|
473 | return definition.kind === "OperationDefinition";
|
474 | })[0];
|
475 | }
|
476 | function getOperationName(doc) {
|
477 | return (doc.definitions
|
478 | .filter(function (definition) {
|
479 | return definition.kind === "OperationDefinition" && !!definition.name;
|
480 | })
|
481 | .map(function (x) { return x.name.value; })[0] || null);
|
482 | }
|
483 | function getFragmentDefinitions(doc) {
|
484 | return doc.definitions.filter(function (definition) {
|
485 | return definition.kind === "FragmentDefinition";
|
486 | });
|
487 | }
|
488 | function getQueryDefinition(doc) {
|
489 | var queryDef = getOperationDefinition(doc);
|
490 | globals.invariant(queryDef && queryDef.operation === "query", 80);
|
491 | return queryDef;
|
492 | }
|
493 | function getFragmentDefinition(doc) {
|
494 | globals.invariant(doc.kind === "Document", 81);
|
495 | globals.invariant(doc.definitions.length <= 1, 82);
|
496 | var fragmentDef = doc.definitions[0];
|
497 | globals.invariant(fragmentDef.kind === "FragmentDefinition", 83);
|
498 | return fragmentDef;
|
499 | }
|
500 | function getMainDefinition(queryDoc) {
|
501 | checkDocument(queryDoc);
|
502 | var fragmentDefinition;
|
503 | for (var _i = 0, _a = queryDoc.definitions; _i < _a.length; _i++) {
|
504 | var definition = _a[_i];
|
505 | if (definition.kind === "OperationDefinition") {
|
506 | var operation = definition.operation;
|
507 | if (operation === "query" ||
|
508 | operation === "mutation" ||
|
509 | operation === "subscription") {
|
510 | return definition;
|
511 | }
|
512 | }
|
513 | if (definition.kind === "FragmentDefinition" && !fragmentDefinition) {
|
514 | fragmentDefinition = definition;
|
515 | }
|
516 | }
|
517 | if (fragmentDefinition) {
|
518 | return fragmentDefinition;
|
519 | }
|
520 | throw globals.newInvariantError(84);
|
521 | }
|
522 | function getDefaultValues(definition) {
|
523 | var defaultValues = Object.create(null);
|
524 | var defs = definition && definition.variableDefinitions;
|
525 | if (defs && defs.length) {
|
526 | defs.forEach(function (def) {
|
527 | if (def.defaultValue) {
|
528 | valueToObjectRepresentation(defaultValues, def.variable.name, def.defaultValue);
|
529 | }
|
530 | });
|
531 | }
|
532 | return defaultValues;
|
533 | }
|
534 |
|
535 | function identity(document) {
|
536 | return document;
|
537 | }
|
538 | var DocumentTransform = (function () {
|
539 | function DocumentTransform(transform, options) {
|
540 | if (options === void 0) { options = Object.create(null); }
|
541 | this.resultCache = canUseWeakSet ? new WeakSet() : new Set();
|
542 | this.transform = transform;
|
543 | if (options.getCacheKey) {
|
544 | this.getCacheKey = options.getCacheKey;
|
545 | }
|
546 | this.cached = options.cache !== false;
|
547 | this.resetCache();
|
548 | }
|
549 | DocumentTransform.prototype.getCacheKey = function (document) {
|
550 | return [document];
|
551 | };
|
552 | DocumentTransform.identity = function () {
|
553 | return new DocumentTransform(identity, { cache: false });
|
554 | };
|
555 | DocumentTransform.split = function (predicate, left, right) {
|
556 | if (right === void 0) { right = DocumentTransform.identity(); }
|
557 | return Object.assign(new DocumentTransform(function (document) {
|
558 | var documentTransform = predicate(document) ? left : right;
|
559 | return documentTransform.transformDocument(document);
|
560 | },
|
561 | { cache: false }), { left: left, right: right });
|
562 | };
|
563 | DocumentTransform.prototype.resetCache = function () {
|
564 | var _this = this;
|
565 | if (this.cached) {
|
566 | var stableCacheKeys_1 = new trie.Trie(canUseWeakMap);
|
567 | this.performWork = optimism.wrap(DocumentTransform.prototype.performWork.bind(this), {
|
568 | makeCacheKey: function (document) {
|
569 | var cacheKeys = _this.getCacheKey(document);
|
570 | if (cacheKeys) {
|
571 | globals.invariant(Array.isArray(cacheKeys), 69);
|
572 | return stableCacheKeys_1.lookupArray(cacheKeys);
|
573 | }
|
574 | },
|
575 | max: cacheSizes["documentTransform.cache"],
|
576 | cache: (caches.WeakCache),
|
577 | });
|
578 | }
|
579 | };
|
580 | DocumentTransform.prototype.performWork = function (document) {
|
581 | checkDocument(document);
|
582 | return this.transform(document);
|
583 | };
|
584 | DocumentTransform.prototype.transformDocument = function (document) {
|
585 | if (this.resultCache.has(document)) {
|
586 | return document;
|
587 | }
|
588 | var transformedDocument = this.performWork(document);
|
589 | this.resultCache.add(transformedDocument);
|
590 | return transformedDocument;
|
591 | };
|
592 | DocumentTransform.prototype.concat = function (otherTransform) {
|
593 | var _this = this;
|
594 | return Object.assign(new DocumentTransform(function (document) {
|
595 | return otherTransform.transformDocument(_this.transformDocument(document));
|
596 | },
|
597 | { cache: false }), {
|
598 | left: this,
|
599 | right: otherTransform,
|
600 | });
|
601 | };
|
602 | return DocumentTransform;
|
603 | }());
|
604 |
|
605 | var printCache;
|
606 | var print = Object.assign(function (ast) {
|
607 | var result = printCache.get(ast);
|
608 | if (!result) {
|
609 | result = graphql.print(ast);
|
610 | printCache.set(ast, result);
|
611 | }
|
612 | return result;
|
613 | }, {
|
614 | reset: function () {
|
615 | printCache = new AutoCleanedWeakCache(cacheSizes.print || 2000 );
|
616 | },
|
617 | });
|
618 | print.reset();
|
619 | if (globalThis.__DEV__ !== false) {
|
620 | registerGlobalCache("print", function () { return (printCache ? printCache.size : 0); });
|
621 | }
|
622 |
|
623 | var isArray = Array.isArray;
|
624 | function isNonEmptyArray(value) {
|
625 | return Array.isArray(value) && value.length > 0;
|
626 | }
|
627 |
|
628 | var TYPENAME_FIELD = {
|
629 | kind: graphql.Kind.FIELD,
|
630 | name: {
|
631 | kind: graphql.Kind.NAME,
|
632 | value: "__typename",
|
633 | },
|
634 | };
|
635 | function isEmpty(op, fragmentMap) {
|
636 | return (!op ||
|
637 | op.selectionSet.selections.every(function (selection) {
|
638 | return selection.kind === graphql.Kind.FRAGMENT_SPREAD &&
|
639 | isEmpty(fragmentMap[selection.name.value], fragmentMap);
|
640 | }));
|
641 | }
|
642 | function nullIfDocIsEmpty(doc) {
|
643 | return (isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))) ?
|
644 | null
|
645 | : doc;
|
646 | }
|
647 | function getDirectiveMatcher(configs) {
|
648 | var names = new Map();
|
649 | var tests = new Map();
|
650 | configs.forEach(function (directive) {
|
651 | if (directive) {
|
652 | if (directive.name) {
|
653 | names.set(directive.name, directive);
|
654 | }
|
655 | else if (directive.test) {
|
656 | tests.set(directive.test, directive);
|
657 | }
|
658 | }
|
659 | });
|
660 | return function (directive) {
|
661 | var config = names.get(directive.name.value);
|
662 | if (!config && tests.size) {
|
663 | tests.forEach(function (testConfig, test) {
|
664 | if (test(directive)) {
|
665 | config = testConfig;
|
666 | }
|
667 | });
|
668 | }
|
669 | return config;
|
670 | };
|
671 | }
|
672 | function makeInUseGetterFunction(defaultKey) {
|
673 | var map = new Map();
|
674 | return function inUseGetterFunction(key) {
|
675 | if (key === void 0) { key = defaultKey; }
|
676 | var inUse = map.get(key);
|
677 | if (!inUse) {
|
678 | map.set(key, (inUse = {
|
679 | variables: new Set(),
|
680 | fragmentSpreads: new Set(),
|
681 | }));
|
682 | }
|
683 | return inUse;
|
684 | };
|
685 | }
|
686 | function removeDirectivesFromDocument(directives, doc) {
|
687 | checkDocument(doc);
|
688 | var getInUseByOperationName = makeInUseGetterFunction("");
|
689 | var getInUseByFragmentName = makeInUseGetterFunction("");
|
690 | var getInUse = function (ancestors) {
|
691 | for (var p = 0, ancestor = void 0; p < ancestors.length && (ancestor = ancestors[p]); ++p) {
|
692 | if (isArray(ancestor))
|
693 | continue;
|
694 | if (ancestor.kind === graphql.Kind.OPERATION_DEFINITION) {
|
695 | return getInUseByOperationName(ancestor.name && ancestor.name.value);
|
696 | }
|
697 | if (ancestor.kind === graphql.Kind.FRAGMENT_DEFINITION) {
|
698 | return getInUseByFragmentName(ancestor.name.value);
|
699 | }
|
700 | }
|
701 | globalThis.__DEV__ !== false && globals.invariant.error(86);
|
702 | return null;
|
703 | };
|
704 | var operationCount = 0;
|
705 | for (var i = doc.definitions.length - 1; i >= 0; --i) {
|
706 | if (doc.definitions[i].kind === graphql.Kind.OPERATION_DEFINITION) {
|
707 | ++operationCount;
|
708 | }
|
709 | }
|
710 | var directiveMatcher = getDirectiveMatcher(directives);
|
711 | var shouldRemoveField = function (nodeDirectives) {
|
712 | return isNonEmptyArray(nodeDirectives) &&
|
713 | nodeDirectives
|
714 | .map(directiveMatcher)
|
715 | .some(function (config) { return config && config.remove; });
|
716 | };
|
717 | var originalFragmentDefsByPath = new Map();
|
718 | var firstVisitMadeChanges = false;
|
719 | var fieldOrInlineFragmentVisitor = {
|
720 | enter: function (node) {
|
721 | if (shouldRemoveField(node.directives)) {
|
722 | firstVisitMadeChanges = true;
|
723 | return null;
|
724 | }
|
725 | },
|
726 | };
|
727 | var docWithoutDirectiveSubtrees = graphql.visit(doc, {
|
728 | Field: fieldOrInlineFragmentVisitor,
|
729 | InlineFragment: fieldOrInlineFragmentVisitor,
|
730 | VariableDefinition: {
|
731 | enter: function () {
|
732 | return false;
|
733 | },
|
734 | },
|
735 | Variable: {
|
736 | enter: function (node, _key, _parent, _path, ancestors) {
|
737 | var inUse = getInUse(ancestors);
|
738 | if (inUse) {
|
739 | inUse.variables.add(node.name.value);
|
740 | }
|
741 | },
|
742 | },
|
743 | FragmentSpread: {
|
744 | enter: function (node, _key, _parent, _path, ancestors) {
|
745 | if (shouldRemoveField(node.directives)) {
|
746 | firstVisitMadeChanges = true;
|
747 | return null;
|
748 | }
|
749 | var inUse = getInUse(ancestors);
|
750 | if (inUse) {
|
751 | inUse.fragmentSpreads.add(node.name.value);
|
752 | }
|
753 | },
|
754 | },
|
755 | FragmentDefinition: {
|
756 | enter: function (node, _key, _parent, path) {
|
757 | originalFragmentDefsByPath.set(JSON.stringify(path), node);
|
758 | },
|
759 | leave: function (node, _key, _parent, path) {
|
760 | var originalNode = originalFragmentDefsByPath.get(JSON.stringify(path));
|
761 | if (node === originalNode) {
|
762 | return node;
|
763 | }
|
764 | if (
|
765 | operationCount > 0 &&
|
766 | node.selectionSet.selections.every(function (selection) {
|
767 | return selection.kind === graphql.Kind.FIELD &&
|
768 | selection.name.value === "__typename";
|
769 | })) {
|
770 | getInUseByFragmentName(node.name.value).removed = true;
|
771 | firstVisitMadeChanges = true;
|
772 | return null;
|
773 | }
|
774 | },
|
775 | },
|
776 | Directive: {
|
777 | leave: function (node) {
|
778 | if (directiveMatcher(node)) {
|
779 | firstVisitMadeChanges = true;
|
780 | return null;
|
781 | }
|
782 | },
|
783 | },
|
784 | });
|
785 | if (!firstVisitMadeChanges) {
|
786 | return doc;
|
787 | }
|
788 | var populateTransitiveVars = function (inUse) {
|
789 | if (!inUse.transitiveVars) {
|
790 | inUse.transitiveVars = new Set(inUse.variables);
|
791 | if (!inUse.removed) {
|
792 | inUse.fragmentSpreads.forEach(function (childFragmentName) {
|
793 | populateTransitiveVars(getInUseByFragmentName(childFragmentName)).transitiveVars.forEach(function (varName) {
|
794 | inUse.transitiveVars.add(varName);
|
795 | });
|
796 | });
|
797 | }
|
798 | }
|
799 | return inUse;
|
800 | };
|
801 | var allFragmentNamesUsed = new Set();
|
802 | docWithoutDirectiveSubtrees.definitions.forEach(function (def) {
|
803 | if (def.kind === graphql.Kind.OPERATION_DEFINITION) {
|
804 | populateTransitiveVars(getInUseByOperationName(def.name && def.name.value)).fragmentSpreads.forEach(function (childFragmentName) {
|
805 | allFragmentNamesUsed.add(childFragmentName);
|
806 | });
|
807 | }
|
808 | else if (def.kind === graphql.Kind.FRAGMENT_DEFINITION &&
|
809 | operationCount === 0 &&
|
810 | !getInUseByFragmentName(def.name.value).removed) {
|
811 | allFragmentNamesUsed.add(def.name.value);
|
812 | }
|
813 | });
|
814 | allFragmentNamesUsed.forEach(function (fragmentName) {
|
815 | populateTransitiveVars(getInUseByFragmentName(fragmentName)).fragmentSpreads.forEach(function (childFragmentName) {
|
816 | allFragmentNamesUsed.add(childFragmentName);
|
817 | });
|
818 | });
|
819 | var fragmentWillBeRemoved = function (fragmentName) {
|
820 | return !!(
|
821 | (!allFragmentNamesUsed.has(fragmentName) ||
|
822 | getInUseByFragmentName(fragmentName).removed));
|
823 | };
|
824 | var enterVisitor = {
|
825 | enter: function (node) {
|
826 | if (fragmentWillBeRemoved(node.name.value)) {
|
827 | return null;
|
828 | }
|
829 | },
|
830 | };
|
831 | return nullIfDocIsEmpty(graphql.visit(docWithoutDirectiveSubtrees, {
|
832 | FragmentSpread: enterVisitor,
|
833 | FragmentDefinition: enterVisitor,
|
834 | OperationDefinition: {
|
835 | leave: function (node) {
|
836 | if (node.variableDefinitions) {
|
837 | var usedVariableNames_1 = populateTransitiveVars(
|
838 | getInUseByOperationName(node.name && node.name.value)).transitiveVars;
|
839 | if (usedVariableNames_1.size < node.variableDefinitions.length) {
|
840 | return tslib.__assign(tslib.__assign({}, node), { variableDefinitions: node.variableDefinitions.filter(function (varDef) {
|
841 | return usedVariableNames_1.has(varDef.variable.name.value);
|
842 | }) });
|
843 | }
|
844 | }
|
845 | },
|
846 | },
|
847 | }));
|
848 | }
|
849 | var addTypenameToDocument = Object.assign(function (doc) {
|
850 | return graphql.visit(doc, {
|
851 | SelectionSet: {
|
852 | enter: function (node, _key, parent) {
|
853 | if (parent &&
|
854 | parent.kind ===
|
855 | graphql.Kind.OPERATION_DEFINITION) {
|
856 | return;
|
857 | }
|
858 | var selections = node.selections;
|
859 | if (!selections) {
|
860 | return;
|
861 | }
|
862 | var skip = selections.some(function (selection) {
|
863 | return (isField(selection) &&
|
864 | (selection.name.value === "__typename" ||
|
865 | selection.name.value.lastIndexOf("__", 0) === 0));
|
866 | });
|
867 | if (skip) {
|
868 | return;
|
869 | }
|
870 | var field = parent;
|
871 | if (isField(field) &&
|
872 | field.directives &&
|
873 | field.directives.some(function (d) { return d.name.value === "export"; })) {
|
874 | return;
|
875 | }
|
876 | return tslib.__assign(tslib.__assign({}, node), { selections: tslib.__spreadArray(tslib.__spreadArray([], selections, true), [TYPENAME_FIELD], false) });
|
877 | },
|
878 | },
|
879 | });
|
880 | }, {
|
881 | added: function (field) {
|
882 | return field === TYPENAME_FIELD;
|
883 | },
|
884 | });
|
885 | var connectionRemoveConfig = {
|
886 | test: function (directive) {
|
887 | var willRemove = directive.name.value === "connection";
|
888 | if (willRemove) {
|
889 | if (!directive.arguments ||
|
890 | !directive.arguments.some(function (arg) { return arg.name.value === "key"; })) {
|
891 | globalThis.__DEV__ !== false && globals.invariant.warn(87);
|
892 | }
|
893 | }
|
894 | return willRemove;
|
895 | },
|
896 | };
|
897 | function removeConnectionDirectiveFromDocument(doc) {
|
898 | return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
|
899 | }
|
900 | function getArgumentMatcher(config) {
|
901 | return function argumentMatcher(argument) {
|
902 | return config.some(function (aConfig) {
|
903 | return argument.value &&
|
904 | argument.value.kind === graphql.Kind.VARIABLE &&
|
905 | argument.value.name &&
|
906 | (aConfig.name === argument.value.name.value ||
|
907 | (aConfig.test && aConfig.test(argument)));
|
908 | });
|
909 | };
|
910 | }
|
911 | function removeArgumentsFromDocument(config, doc) {
|
912 | var argMatcher = getArgumentMatcher(config);
|
913 | return nullIfDocIsEmpty(graphql.visit(doc, {
|
914 | OperationDefinition: {
|
915 | enter: function (node) {
|
916 | return tslib.__assign(tslib.__assign({}, node), {
|
917 | variableDefinitions: node.variableDefinitions ?
|
918 | node.variableDefinitions.filter(function (varDef) {
|
919 | return !config.some(function (arg) { return arg.name === varDef.variable.name.value; });
|
920 | })
|
921 | : [] });
|
922 | },
|
923 | },
|
924 | Field: {
|
925 | enter: function (node) {
|
926 | var shouldRemoveField = config.some(function (argConfig) { return argConfig.remove; });
|
927 | if (shouldRemoveField) {
|
928 | var argMatchCount_1 = 0;
|
929 | if (node.arguments) {
|
930 | node.arguments.forEach(function (arg) {
|
931 | if (argMatcher(arg)) {
|
932 | argMatchCount_1 += 1;
|
933 | }
|
934 | });
|
935 | }
|
936 | if (argMatchCount_1 === 1) {
|
937 | return null;
|
938 | }
|
939 | }
|
940 | },
|
941 | },
|
942 | Argument: {
|
943 | enter: function (node) {
|
944 | if (argMatcher(node)) {
|
945 | return null;
|
946 | }
|
947 | },
|
948 | },
|
949 | }));
|
950 | }
|
951 | function removeFragmentSpreadFromDocument(config, doc) {
|
952 | function enter(node) {
|
953 | if (config.some(function (def) { return def.name === node.name.value; })) {
|
954 | return null;
|
955 | }
|
956 | }
|
957 | return nullIfDocIsEmpty(graphql.visit(doc, {
|
958 | FragmentSpread: { enter: enter },
|
959 | FragmentDefinition: { enter: enter },
|
960 | }));
|
961 | }
|
962 | function buildQueryFromSelectionSet(document) {
|
963 | var definition = getMainDefinition(document);
|
964 | var definitionOperation = definition.operation;
|
965 | if (definitionOperation === "query") {
|
966 | return document;
|
967 | }
|
968 | var modifiedDoc = graphql.visit(document, {
|
969 | OperationDefinition: {
|
970 | enter: function (node) {
|
971 | return tslib.__assign(tslib.__assign({}, node), { operation: "query" });
|
972 | },
|
973 | },
|
974 | });
|
975 | return modifiedDoc;
|
976 | }
|
977 | function removeClientSetsFromDocument(document) {
|
978 | checkDocument(document);
|
979 | var modifiedDoc = removeDirectivesFromDocument([
|
980 | {
|
981 | test: function (directive) { return directive.name.value === "client"; },
|
982 | remove: true,
|
983 | },
|
984 | ], document);
|
985 | return modifiedDoc;
|
986 | }
|
987 |
|
988 | function isOperation(document, operation) {
|
989 | var _a;
|
990 | return ((_a = getOperationDefinition(document)) === null || _a === void 0 ? void 0 : _a.operation) === operation;
|
991 | }
|
992 | function isMutationOperation(document) {
|
993 | return isOperation(document, "mutation");
|
994 | }
|
995 | function isQueryOperation(document) {
|
996 | return isOperation(document, "query");
|
997 | }
|
998 | function isSubscriptionOperation(document) {
|
999 | return isOperation(document, "subscription");
|
1000 | }
|
1001 |
|
1002 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
1003 | function mergeDeep() {
|
1004 | var sources = [];
|
1005 | for (var _i = 0; _i < arguments.length; _i++) {
|
1006 | sources[_i] = arguments[_i];
|
1007 | }
|
1008 | return mergeDeepArray(sources);
|
1009 | }
|
1010 | function mergeDeepArray(sources) {
|
1011 | var target = sources[0] || {};
|
1012 | var count = sources.length;
|
1013 | if (count > 1) {
|
1014 | var merger = new DeepMerger();
|
1015 | for (var i = 1; i < count; ++i) {
|
1016 | target = merger.merge(target, sources[i]);
|
1017 | }
|
1018 | }
|
1019 | return target;
|
1020 | }
|
1021 | var defaultReconciler = function (target, source, property) {
|
1022 | return this.merge(target[property], source[property]);
|
1023 | };
|
1024 | var DeepMerger = (function () {
|
1025 | function DeepMerger(reconciler) {
|
1026 | if (reconciler === void 0) { reconciler = defaultReconciler; }
|
1027 | this.reconciler = reconciler;
|
1028 | this.isObject = isNonNullObject;
|
1029 | this.pastCopies = new Set();
|
1030 | }
|
1031 | DeepMerger.prototype.merge = function (target, source) {
|
1032 | var _this = this;
|
1033 | var context = [];
|
1034 | for (var _i = 2; _i < arguments.length; _i++) {
|
1035 | context[_i - 2] = arguments[_i];
|
1036 | }
|
1037 | if (isNonNullObject(source) && isNonNullObject(target)) {
|
1038 | Object.keys(source).forEach(function (sourceKey) {
|
1039 | if (hasOwnProperty.call(target, sourceKey)) {
|
1040 | var targetValue = target[sourceKey];
|
1041 | if (source[sourceKey] !== targetValue) {
|
1042 | var result = _this.reconciler.apply(_this, tslib.__spreadArray([target,
|
1043 | source,
|
1044 | sourceKey], context, false));
|
1045 | if (result !== targetValue) {
|
1046 | target = _this.shallowCopyForMerge(target);
|
1047 | target[sourceKey] = result;
|
1048 | }
|
1049 | }
|
1050 | }
|
1051 | else {
|
1052 | target = _this.shallowCopyForMerge(target);
|
1053 | target[sourceKey] = source[sourceKey];
|
1054 | }
|
1055 | });
|
1056 | return target;
|
1057 | }
|
1058 | return source;
|
1059 | };
|
1060 | DeepMerger.prototype.shallowCopyForMerge = function (value) {
|
1061 | if (isNonNullObject(value)) {
|
1062 | if (!this.pastCopies.has(value)) {
|
1063 | if (Array.isArray(value)) {
|
1064 | value = value.slice(0);
|
1065 | }
|
1066 | else {
|
1067 | value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
|
1068 | }
|
1069 | this.pastCopies.add(value);
|
1070 | }
|
1071 | }
|
1072 | return value;
|
1073 | };
|
1074 | return DeepMerger;
|
1075 | }());
|
1076 |
|
1077 | function concatPagination(keyArgs) {
|
1078 | if (keyArgs === void 0) { keyArgs = false; }
|
1079 | return {
|
1080 | keyArgs: keyArgs,
|
1081 | merge: function (existing, incoming) {
|
1082 | return existing ? tslib.__spreadArray(tslib.__spreadArray([], existing, true), incoming, true) : incoming;
|
1083 | },
|
1084 | };
|
1085 | }
|
1086 | function offsetLimitPagination(keyArgs) {
|
1087 | if (keyArgs === void 0) { keyArgs = false; }
|
1088 | return {
|
1089 | keyArgs: keyArgs,
|
1090 | merge: function (existing, incoming, _a) {
|
1091 | var args = _a.args;
|
1092 | var merged = existing ? existing.slice(0) : [];
|
1093 | if (incoming) {
|
1094 | if (args) {
|
1095 | var _b = args.offset, offset = _b === void 0 ? 0 : _b;
|
1096 | for (var i = 0; i < incoming.length; ++i) {
|
1097 | merged[offset + i] = incoming[i];
|
1098 | }
|
1099 | }
|
1100 | else {
|
1101 | merged.push.apply(merged, incoming);
|
1102 | }
|
1103 | }
|
1104 | return merged;
|
1105 | },
|
1106 | };
|
1107 | }
|
1108 | function relayStylePagination(keyArgs) {
|
1109 | if (keyArgs === void 0) { keyArgs = false; }
|
1110 | return {
|
1111 | keyArgs: keyArgs,
|
1112 | read: function (existing, _a) {
|
1113 | var canRead = _a.canRead, readField = _a.readField;
|
1114 | if (!existing)
|
1115 | return existing;
|
1116 | var edges = [];
|
1117 | var firstEdgeCursor = "";
|
1118 | var lastEdgeCursor = "";
|
1119 | existing.edges.forEach(function (edge) {
|
1120 | if (canRead(readField("node", edge))) {
|
1121 | edges.push(edge);
|
1122 | if (edge.cursor) {
|
1123 | firstEdgeCursor = firstEdgeCursor || edge.cursor || "";
|
1124 | lastEdgeCursor = edge.cursor || lastEdgeCursor;
|
1125 | }
|
1126 | }
|
1127 | });
|
1128 | if (edges.length > 1 && firstEdgeCursor === lastEdgeCursor) {
|
1129 | firstEdgeCursor = "";
|
1130 | }
|
1131 | var _b = existing.pageInfo || {}, startCursor = _b.startCursor, endCursor = _b.endCursor;
|
1132 | return tslib.__assign(tslib.__assign({}, getExtras(existing)), { edges: edges, pageInfo: tslib.__assign(tslib.__assign({}, existing.pageInfo), {
|
1133 | startCursor: startCursor || firstEdgeCursor, endCursor: endCursor || lastEdgeCursor }) });
|
1134 | },
|
1135 | merge: function (existing, incoming, _a) {
|
1136 | var args = _a.args, isReference = _a.isReference, readField = _a.readField;
|
1137 | if (!existing) {
|
1138 | existing = makeEmptyData();
|
1139 | }
|
1140 | if (!incoming) {
|
1141 | return existing;
|
1142 | }
|
1143 | var incomingEdges = incoming.edges ?
|
1144 | incoming.edges.map(function (edge) {
|
1145 | if (isReference((edge = tslib.__assign({}, edge)))) {
|
1146 | edge.cursor = readField("cursor", edge);
|
1147 | }
|
1148 | return edge;
|
1149 | })
|
1150 | : [];
|
1151 | if (incoming.pageInfo) {
|
1152 | var pageInfo_1 = incoming.pageInfo;
|
1153 | var startCursor = pageInfo_1.startCursor, endCursor = pageInfo_1.endCursor;
|
1154 | var firstEdge = incomingEdges[0];
|
1155 | var lastEdge = incomingEdges[incomingEdges.length - 1];
|
1156 | if (firstEdge && startCursor) {
|
1157 | firstEdge.cursor = startCursor;
|
1158 | }
|
1159 | if (lastEdge && endCursor) {
|
1160 | lastEdge.cursor = endCursor;
|
1161 | }
|
1162 | var firstCursor = firstEdge && firstEdge.cursor;
|
1163 | if (firstCursor && !startCursor) {
|
1164 | incoming = mergeDeep(incoming, {
|
1165 | pageInfo: {
|
1166 | startCursor: firstCursor,
|
1167 | },
|
1168 | });
|
1169 | }
|
1170 | var lastCursor = lastEdge && lastEdge.cursor;
|
1171 | if (lastCursor && !endCursor) {
|
1172 | incoming = mergeDeep(incoming, {
|
1173 | pageInfo: {
|
1174 | endCursor: lastCursor,
|
1175 | },
|
1176 | });
|
1177 | }
|
1178 | }
|
1179 | var prefix = existing.edges;
|
1180 | var suffix = [];
|
1181 | if (args && args.after) {
|
1182 | var index = prefix.findIndex(function (edge) { return edge.cursor === args.after; });
|
1183 | if (index >= 0) {
|
1184 | prefix = prefix.slice(0, index + 1);
|
1185 | }
|
1186 | }
|
1187 | else if (args && args.before) {
|
1188 | var index = prefix.findIndex(function (edge) { return edge.cursor === args.before; });
|
1189 | suffix = index < 0 ? prefix : prefix.slice(index);
|
1190 | prefix = [];
|
1191 | }
|
1192 | else if (incoming.edges) {
|
1193 | prefix = [];
|
1194 | }
|
1195 | var edges = tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], prefix, true), incomingEdges, true), suffix, true);
|
1196 | var pageInfo = tslib.__assign(tslib.__assign({}, incoming.pageInfo), existing.pageInfo);
|
1197 | if (incoming.pageInfo) {
|
1198 | var _b = incoming.pageInfo, hasPreviousPage = _b.hasPreviousPage, hasNextPage = _b.hasNextPage, startCursor = _b.startCursor, endCursor = _b.endCursor, extras = tslib.__rest(_b, ["hasPreviousPage", "hasNextPage", "startCursor", "endCursor"]);
|
1199 | Object.assign(pageInfo, extras);
|
1200 | if (!prefix.length) {
|
1201 | if (void 0 !== hasPreviousPage)
|
1202 | pageInfo.hasPreviousPage = hasPreviousPage;
|
1203 | if (void 0 !== startCursor)
|
1204 | pageInfo.startCursor = startCursor;
|
1205 | }
|
1206 | if (!suffix.length) {
|
1207 | if (void 0 !== hasNextPage)
|
1208 | pageInfo.hasNextPage = hasNextPage;
|
1209 | if (void 0 !== endCursor)
|
1210 | pageInfo.endCursor = endCursor;
|
1211 | }
|
1212 | }
|
1213 | return tslib.__assign(tslib.__assign(tslib.__assign({}, getExtras(existing)), getExtras(incoming)), { edges: edges, pageInfo: pageInfo });
|
1214 | },
|
1215 | };
|
1216 | }
|
1217 | var getExtras = function (obj) { return tslib.__rest(obj, notExtras); };
|
1218 | var notExtras = ["edges", "pageInfo"];
|
1219 | function makeEmptyData() {
|
1220 | return {
|
1221 | edges: [],
|
1222 | pageInfo: {
|
1223 | hasPreviousPage: false,
|
1224 | hasNextPage: true,
|
1225 | startCursor: "",
|
1226 | endCursor: "",
|
1227 | },
|
1228 | };
|
1229 | }
|
1230 |
|
1231 | function createFulfilledPromise(value) {
|
1232 | var promise = Promise.resolve(value);
|
1233 | promise.status = "fulfilled";
|
1234 | promise.value = value;
|
1235 | return promise;
|
1236 | }
|
1237 | function createRejectedPromise(reason) {
|
1238 | var promise = Promise.reject(reason);
|
1239 | promise.catch(function () { });
|
1240 | promise.status = "rejected";
|
1241 | promise.reason = reason;
|
1242 | return promise;
|
1243 | }
|
1244 | function isStatefulPromise(promise) {
|
1245 | return "status" in promise;
|
1246 | }
|
1247 | function wrapPromiseWithState(promise) {
|
1248 | if (isStatefulPromise(promise)) {
|
1249 | return promise;
|
1250 | }
|
1251 | var pendingPromise = promise;
|
1252 | pendingPromise.status = "pending";
|
1253 | pendingPromise.then(function (value) {
|
1254 | if (pendingPromise.status === "pending") {
|
1255 | var fulfilledPromise = pendingPromise;
|
1256 | fulfilledPromise.status = "fulfilled";
|
1257 | fulfilledPromise.value = value;
|
1258 | }
|
1259 | }, function (reason) {
|
1260 | if (pendingPromise.status === "pending") {
|
1261 | var rejectedPromise = pendingPromise;
|
1262 | rejectedPromise.status = "rejected";
|
1263 | rejectedPromise.reason = reason;
|
1264 | }
|
1265 | });
|
1266 | return promise;
|
1267 | }
|
1268 |
|
1269 | var toString = Object.prototype.toString;
|
1270 | function cloneDeep(value) {
|
1271 | return cloneDeepHelper(value);
|
1272 | }
|
1273 | function cloneDeepHelper(val, seen) {
|
1274 | switch (toString.call(val)) {
|
1275 | case "[object Array]": {
|
1276 | seen = seen || new Map();
|
1277 | if (seen.has(val))
|
1278 | return seen.get(val);
|
1279 | var copy_1 = val.slice(0);
|
1280 | seen.set(val, copy_1);
|
1281 | copy_1.forEach(function (child, i) {
|
1282 | copy_1[i] = cloneDeepHelper(child, seen);
|
1283 | });
|
1284 | return copy_1;
|
1285 | }
|
1286 | case "[object Object]": {
|
1287 | seen = seen || new Map();
|
1288 | if (seen.has(val))
|
1289 | return seen.get(val);
|
1290 | var copy_2 = Object.create(Object.getPrototypeOf(val));
|
1291 | seen.set(val, copy_2);
|
1292 | Object.keys(val).forEach(function (key) {
|
1293 | copy_2[key] = cloneDeepHelper(val[key], seen);
|
1294 | });
|
1295 | return copy_2;
|
1296 | }
|
1297 | default:
|
1298 | return val;
|
1299 | }
|
1300 | }
|
1301 |
|
1302 | function deepFreeze(value) {
|
1303 | var workSet = new Set([value]);
|
1304 | workSet.forEach(function (obj) {
|
1305 | if (isNonNullObject(obj) && shallowFreeze(obj) === obj) {
|
1306 | Object.getOwnPropertyNames(obj).forEach(function (name) {
|
1307 | if (isNonNullObject(obj[name]))
|
1308 | workSet.add(obj[name]);
|
1309 | });
|
1310 | }
|
1311 | });
|
1312 | return value;
|
1313 | }
|
1314 | function shallowFreeze(obj) {
|
1315 | if (globalThis.__DEV__ !== false && !Object.isFrozen(obj)) {
|
1316 | try {
|
1317 | Object.freeze(obj);
|
1318 | }
|
1319 | catch (e) {
|
1320 | if (e instanceof TypeError)
|
1321 | return null;
|
1322 | throw e;
|
1323 | }
|
1324 | }
|
1325 | return obj;
|
1326 | }
|
1327 | function maybeDeepFreeze(obj) {
|
1328 | if (globalThis.__DEV__ !== false) {
|
1329 | deepFreeze(obj);
|
1330 | }
|
1331 | return obj;
|
1332 | }
|
1333 |
|
1334 | function iterateObserversSafely(observers, method, argument) {
|
1335 | var observersWithMethod = [];
|
1336 | observers.forEach(function (obs) { return obs[method] && observersWithMethod.push(obs); });
|
1337 | observersWithMethod.forEach(function (obs) { return obs[method](argument); });
|
1338 | }
|
1339 |
|
1340 | function asyncMap(observable, mapFn, catchFn) {
|
1341 | return new zenObservableTs.Observable(function (observer) {
|
1342 | var promiseQueue = {
|
1343 | then: function (callback) {
|
1344 | return new Promise(function (resolve) { return resolve(callback()); });
|
1345 | },
|
1346 | };
|
1347 | function makeCallback(examiner, key) {
|
1348 | return function (arg) {
|
1349 | if (examiner) {
|
1350 | var both = function () {
|
1351 | return observer.closed ?
|
1352 | 0
|
1353 | : examiner(arg);
|
1354 | };
|
1355 | promiseQueue = promiseQueue.then(both, both).then(function (result) { return observer.next(result); }, function (error) { return observer.error(error); });
|
1356 | }
|
1357 | else {
|
1358 | observer[key](arg);
|
1359 | }
|
1360 | };
|
1361 | }
|
1362 | var handler = {
|
1363 | next: makeCallback(mapFn, "next"),
|
1364 | error: makeCallback(catchFn, "error"),
|
1365 | complete: function () {
|
1366 | promiseQueue.then(function () { return observer.complete(); });
|
1367 | },
|
1368 | };
|
1369 | var sub = observable.subscribe(handler);
|
1370 | return function () { return sub.unsubscribe(); };
|
1371 | });
|
1372 | }
|
1373 |
|
1374 | function fixObservableSubclass(subclass) {
|
1375 | function set(key) {
|
1376 | Object.defineProperty(subclass, key, { value: zenObservableTs.Observable });
|
1377 | }
|
1378 | if (canUseSymbol && Symbol.species) {
|
1379 | set(Symbol.species);
|
1380 | }
|
1381 | set("@@species");
|
1382 | return subclass;
|
1383 | }
|
1384 |
|
1385 | function isPromiseLike(value) {
|
1386 | return value && typeof value.then === "function";
|
1387 | }
|
1388 | var Concast = (function (_super) {
|
1389 | tslib.__extends(Concast, _super);
|
1390 | function Concast(sources) {
|
1391 | var _this = _super.call(this, function (observer) {
|
1392 | _this.addObserver(observer);
|
1393 | return function () { return _this.removeObserver(observer); };
|
1394 | }) || this;
|
1395 | _this.observers = new Set();
|
1396 | _this.promise = new Promise(function (resolve, reject) {
|
1397 | _this.resolve = resolve;
|
1398 | _this.reject = reject;
|
1399 | });
|
1400 | _this.handlers = {
|
1401 | next: function (result) {
|
1402 | if (_this.sub !== null) {
|
1403 | _this.latest = ["next", result];
|
1404 | _this.notify("next", result);
|
1405 | iterateObserversSafely(_this.observers, "next", result);
|
1406 | }
|
1407 | },
|
1408 | error: function (error) {
|
1409 | var sub = _this.sub;
|
1410 | if (sub !== null) {
|
1411 | if (sub)
|
1412 | setTimeout(function () { return sub.unsubscribe(); });
|
1413 | _this.sub = null;
|
1414 | _this.latest = ["error", error];
|
1415 | _this.reject(error);
|
1416 | _this.notify("error", error);
|
1417 | iterateObserversSafely(_this.observers, "error", error);
|
1418 | }
|
1419 | },
|
1420 | complete: function () {
|
1421 | var _a = _this, sub = _a.sub, _b = _a.sources, sources = _b === void 0 ? [] : _b;
|
1422 | if (sub !== null) {
|
1423 | var value = sources.shift();
|
1424 | if (!value) {
|
1425 | if (sub)
|
1426 | setTimeout(function () { return sub.unsubscribe(); });
|
1427 | _this.sub = null;
|
1428 | if (_this.latest && _this.latest[0] === "next") {
|
1429 | _this.resolve(_this.latest[1]);
|
1430 | }
|
1431 | else {
|
1432 | _this.resolve();
|
1433 | }
|
1434 | _this.notify("complete");
|
1435 | iterateObserversSafely(_this.observers, "complete");
|
1436 | }
|
1437 | else if (isPromiseLike(value)) {
|
1438 | value.then(function (obs) { return (_this.sub = obs.subscribe(_this.handlers)); }, _this.handlers.error);
|
1439 | }
|
1440 | else {
|
1441 | _this.sub = value.subscribe(_this.handlers);
|
1442 | }
|
1443 | }
|
1444 | },
|
1445 | };
|
1446 | _this.nextResultListeners = new Set();
|
1447 | _this.cancel = function (reason) {
|
1448 | _this.reject(reason);
|
1449 | _this.sources = [];
|
1450 | _this.handlers.error(reason);
|
1451 | };
|
1452 | _this.promise.catch(function (_) { });
|
1453 | if (typeof sources === "function") {
|
1454 | sources = [new zenObservableTs.Observable(sources)];
|
1455 | }
|
1456 | if (isPromiseLike(sources)) {
|
1457 | sources.then(function (iterable) { return _this.start(iterable); }, _this.handlers.error);
|
1458 | }
|
1459 | else {
|
1460 | _this.start(sources);
|
1461 | }
|
1462 | return _this;
|
1463 | }
|
1464 | Concast.prototype.start = function (sources) {
|
1465 | if (this.sub !== void 0)
|
1466 | return;
|
1467 | this.sources = Array.from(sources);
|
1468 | this.handlers.complete();
|
1469 | };
|
1470 | Concast.prototype.deliverLastMessage = function (observer) {
|
1471 | if (this.latest) {
|
1472 | var nextOrError = this.latest[0];
|
1473 | var method = observer[nextOrError];
|
1474 | if (method) {
|
1475 | method.call(observer, this.latest[1]);
|
1476 | }
|
1477 | if (this.sub === null && nextOrError === "next" && observer.complete) {
|
1478 | observer.complete();
|
1479 | }
|
1480 | }
|
1481 | };
|
1482 | Concast.prototype.addObserver = function (observer) {
|
1483 | if (!this.observers.has(observer)) {
|
1484 | this.deliverLastMessage(observer);
|
1485 | this.observers.add(observer);
|
1486 | }
|
1487 | };
|
1488 | Concast.prototype.removeObserver = function (observer) {
|
1489 | if (this.observers.delete(observer) && this.observers.size < 1) {
|
1490 | this.handlers.complete();
|
1491 | }
|
1492 | };
|
1493 | Concast.prototype.notify = function (method, arg) {
|
1494 | var nextResultListeners = this.nextResultListeners;
|
1495 | if (nextResultListeners.size) {
|
1496 | this.nextResultListeners = new Set();
|
1497 | nextResultListeners.forEach(function (listener) { return listener(method, arg); });
|
1498 | }
|
1499 | };
|
1500 | Concast.prototype.beforeNext = function (callback) {
|
1501 | var called = false;
|
1502 | this.nextResultListeners.add(function (method, arg) {
|
1503 | if (!called) {
|
1504 | called = true;
|
1505 | callback(method, arg);
|
1506 | }
|
1507 | });
|
1508 | };
|
1509 | return Concast;
|
1510 | }(zenObservableTs.Observable));
|
1511 | fixObservableSubclass(Concast);
|
1512 |
|
1513 | function isExecutionPatchIncrementalResult(value) {
|
1514 | return "incremental" in value;
|
1515 | }
|
1516 | function isExecutionPatchInitialResult(value) {
|
1517 | return "hasNext" in value && "data" in value;
|
1518 | }
|
1519 | function isExecutionPatchResult(value) {
|
1520 | return (isExecutionPatchIncrementalResult(value) ||
|
1521 | isExecutionPatchInitialResult(value));
|
1522 | }
|
1523 | function isApolloPayloadResult(value) {
|
1524 | return isNonNullObject(value) && "payload" in value;
|
1525 | }
|
1526 | function mergeIncrementalData(prevResult, result) {
|
1527 | var mergedData = prevResult;
|
1528 | var merger = new DeepMerger();
|
1529 | if (isExecutionPatchIncrementalResult(result) &&
|
1530 | isNonEmptyArray(result.incremental)) {
|
1531 | result.incremental.forEach(function (_a) {
|
1532 | var data = _a.data, path = _a.path;
|
1533 | for (var i = path.length - 1; i >= 0; --i) {
|
1534 | var key = path[i];
|
1535 | var isNumericKey = !isNaN(+key);
|
1536 | var parent_1 = isNumericKey ? [] : {};
|
1537 | parent_1[key] = data;
|
1538 | data = parent_1;
|
1539 | }
|
1540 | mergedData = merger.merge(mergedData, data);
|
1541 | });
|
1542 | }
|
1543 | return mergedData;
|
1544 | }
|
1545 |
|
1546 | function graphQLResultHasError(result) {
|
1547 | var errors = getGraphQLErrorsFromResult(result);
|
1548 | return isNonEmptyArray(errors);
|
1549 | }
|
1550 | function getGraphQLErrorsFromResult(result) {
|
1551 | var graphQLErrors = isNonEmptyArray(result.errors) ? result.errors.slice(0) : [];
|
1552 | if (isExecutionPatchIncrementalResult(result) &&
|
1553 | isNonEmptyArray(result.incremental)) {
|
1554 | result.incremental.forEach(function (incrementalResult) {
|
1555 | if (incrementalResult.errors) {
|
1556 | graphQLErrors.push.apply(graphQLErrors, incrementalResult.errors);
|
1557 | }
|
1558 | });
|
1559 | }
|
1560 | return graphQLErrors;
|
1561 | }
|
1562 |
|
1563 | function compact() {
|
1564 | var objects = [];
|
1565 | for (var _i = 0; _i < arguments.length; _i++) {
|
1566 | objects[_i] = arguments[_i];
|
1567 | }
|
1568 | var result = Object.create(null);
|
1569 | objects.forEach(function (obj) {
|
1570 | if (!obj)
|
1571 | return;
|
1572 | Object.keys(obj).forEach(function (key) {
|
1573 | var value = obj[key];
|
1574 | if (value !== void 0) {
|
1575 | result[key] = value;
|
1576 | }
|
1577 | });
|
1578 | });
|
1579 | return result;
|
1580 | }
|
1581 |
|
1582 | var prefixCounts = new Map();
|
1583 | function makeUniqueId(prefix) {
|
1584 | var count = prefixCounts.get(prefix) || 1;
|
1585 | prefixCounts.set(prefix, count + 1);
|
1586 | return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
|
1587 | }
|
1588 |
|
1589 | function stringifyForDisplay(value, space) {
|
1590 | if (space === void 0) { space = 0; }
|
1591 | var undefId = makeUniqueId("stringifyForDisplay");
|
1592 | return JSON.stringify(value, function (key, value) {
|
1593 | return value === void 0 ? undefId : value;
|
1594 | }, space)
|
1595 | .split(JSON.stringify(undefId))
|
1596 | .join("<undefined>");
|
1597 | }
|
1598 |
|
1599 | function mergeOptions(defaults, options) {
|
1600 | return compact(defaults, options, options.variables && {
|
1601 | variables: compact(tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables)),
|
1602 | });
|
1603 | }
|
1604 |
|
1605 | function omitDeep(value, key) {
|
1606 | return __omitDeep(value, key);
|
1607 | }
|
1608 | function __omitDeep(value, key, known) {
|
1609 | if (known === void 0) { known = new Map(); }
|
1610 | if (known.has(value)) {
|
1611 | return known.get(value);
|
1612 | }
|
1613 | var modified = false;
|
1614 | if (Array.isArray(value)) {
|
1615 | var array_1 = [];
|
1616 | known.set(value, array_1);
|
1617 | value.forEach(function (value, index) {
|
1618 | var result = __omitDeep(value, key, known);
|
1619 | modified || (modified = result !== value);
|
1620 | array_1[index] = result;
|
1621 | });
|
1622 | if (modified) {
|
1623 | return array_1;
|
1624 | }
|
1625 | }
|
1626 | else if (isPlainObject(value)) {
|
1627 | var obj_1 = Object.create(Object.getPrototypeOf(value));
|
1628 | known.set(value, obj_1);
|
1629 | Object.keys(value).forEach(function (k) {
|
1630 | if (k === key) {
|
1631 | modified = true;
|
1632 | return;
|
1633 | }
|
1634 | var result = __omitDeep(value[k], key, known);
|
1635 | modified || (modified = result !== value[k]);
|
1636 | obj_1[k] = result;
|
1637 | });
|
1638 | if (modified) {
|
1639 | return obj_1;
|
1640 | }
|
1641 | }
|
1642 | return value;
|
1643 | }
|
1644 |
|
1645 | function stripTypename(value) {
|
1646 | return omitDeep(value, "__typename");
|
1647 | }
|
1648 |
|
1649 | exports.DEV = globals.DEV;
|
1650 | exports.maybe = globals.maybe;
|
1651 | exports.Observable = zenObservableTs.Observable;
|
1652 | exports.AutoCleanedStrongCache = AutoCleanedStrongCache;
|
1653 | exports.AutoCleanedWeakCache = AutoCleanedWeakCache;
|
1654 | exports.Concast = Concast;
|
1655 | exports.DeepMerger = DeepMerger;
|
1656 | exports.DocumentTransform = DocumentTransform;
|
1657 | exports.addTypenameToDocument = addTypenameToDocument;
|
1658 | exports.argumentsObjectFromField = argumentsObjectFromField;
|
1659 | exports.asyncMap = asyncMap;
|
1660 | exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
|
1661 | exports.cacheSizes = cacheSizes;
|
1662 | exports.canUseAsyncIteratorSymbol = canUseAsyncIteratorSymbol;
|
1663 | exports.canUseDOM = canUseDOM;
|
1664 | exports.canUseLayoutEffect = canUseLayoutEffect;
|
1665 | exports.canUseSymbol = canUseSymbol;
|
1666 | exports.canUseWeakMap = canUseWeakMap;
|
1667 | exports.canUseWeakSet = canUseWeakSet;
|
1668 | exports.canonicalStringify = canonicalStringify;
|
1669 | exports.checkDocument = checkDocument;
|
1670 | exports.cloneDeep = cloneDeep;
|
1671 | exports.compact = compact;
|
1672 | exports.concatPagination = concatPagination;
|
1673 | exports.createFragmentMap = createFragmentMap;
|
1674 | exports.createFulfilledPromise = createFulfilledPromise;
|
1675 | exports.createRejectedPromise = createRejectedPromise;
|
1676 | exports.fixObservableSubclass = fixObservableSubclass;
|
1677 | exports.getDefaultValues = getDefaultValues;
|
1678 | exports.getDirectiveNames = getDirectiveNames;
|
1679 | exports.getFragmentDefinition = getFragmentDefinition;
|
1680 | exports.getFragmentDefinitions = getFragmentDefinitions;
|
1681 | exports.getFragmentFromSelection = getFragmentFromSelection;
|
1682 | exports.getFragmentQueryDocument = getFragmentQueryDocument;
|
1683 | exports.getGraphQLErrorsFromResult = getGraphQLErrorsFromResult;
|
1684 | exports.getInclusionDirectives = getInclusionDirectives;
|
1685 | exports.getMainDefinition = getMainDefinition;
|
1686 | exports.getOperationDefinition = getOperationDefinition;
|
1687 | exports.getOperationName = getOperationName;
|
1688 | exports.getQueryDefinition = getQueryDefinition;
|
1689 | exports.getStoreKeyName = getStoreKeyName;
|
1690 | exports.getTypenameFromResult = getTypenameFromResult;
|
1691 | exports.graphQLResultHasError = graphQLResultHasError;
|
1692 | exports.hasAllDirectives = hasAllDirectives;
|
1693 | exports.hasAnyDirectives = hasAnyDirectives;
|
1694 | exports.hasClientExports = hasClientExports;
|
1695 | exports.hasDirectives = hasDirectives;
|
1696 | exports.isApolloPayloadResult = isApolloPayloadResult;
|
1697 | exports.isArray = isArray;
|
1698 | exports.isDocumentNode = isDocumentNode;
|
1699 | exports.isExecutionPatchIncrementalResult = isExecutionPatchIncrementalResult;
|
1700 | exports.isExecutionPatchInitialResult = isExecutionPatchInitialResult;
|
1701 | exports.isExecutionPatchResult = isExecutionPatchResult;
|
1702 | exports.isField = isField;
|
1703 | exports.isInlineFragment = isInlineFragment;
|
1704 | exports.isMutationOperation = isMutationOperation;
|
1705 | exports.isNonEmptyArray = isNonEmptyArray;
|
1706 | exports.isNonNullObject = isNonNullObject;
|
1707 | exports.isPlainObject = isPlainObject;
|
1708 | exports.isQueryOperation = isQueryOperation;
|
1709 | exports.isReference = isReference;
|
1710 | exports.isStatefulPromise = isStatefulPromise;
|
1711 | exports.isSubscriptionOperation = isSubscriptionOperation;
|
1712 | exports.iterateObserversSafely = iterateObserversSafely;
|
1713 | exports.makeReference = makeReference;
|
1714 | exports.makeUniqueId = makeUniqueId;
|
1715 | exports.maybeDeepFreeze = maybeDeepFreeze;
|
1716 | exports.mergeDeep = mergeDeep;
|
1717 | exports.mergeDeepArray = mergeDeepArray;
|
1718 | exports.mergeIncrementalData = mergeIncrementalData;
|
1719 | exports.mergeOptions = mergeOptions;
|
1720 | exports.offsetLimitPagination = offsetLimitPagination;
|
1721 | exports.omitDeep = omitDeep;
|
1722 | exports.print = print;
|
1723 | exports.relayStylePagination = relayStylePagination;
|
1724 | exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
|
1725 | exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
|
1726 | exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
|
1727 | exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
|
1728 | exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
|
1729 | exports.resultKeyNameFromField = resultKeyNameFromField;
|
1730 | exports.shouldInclude = shouldInclude;
|
1731 | exports.storeKeyNameFromField = storeKeyNameFromField;
|
1732 | exports.stringifyForDisplay = stringifyForDisplay;
|
1733 | exports.stripTypename = stripTypename;
|
1734 | exports.valueToObjectRepresentation = valueToObjectRepresentation;
|
1735 | exports.wrapPromiseWithState = wrapPromiseWithState;
|
1736 |
|