1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var globals = require('./globals');
|
6 | var graphql = require('graphql');
|
7 | var tslib = require('tslib');
|
8 | var zenObservableTs = require('zen-observable-ts');
|
9 | require('symbol-observable');
|
10 |
|
11 | function shouldInclude(_a, variables) {
|
12 | var directives = _a.directives;
|
13 | if (!directives || !directives.length) {
|
14 | return true;
|
15 | }
|
16 | return getInclusionDirectives(directives).every(function (_a) {
|
17 | var directive = _a.directive, ifArgument = _a.ifArgument;
|
18 | var evaledValue = false;
|
19 | if (ifArgument.value.kind === 'Variable') {
|
20 | evaledValue = variables && variables[ifArgument.value.name.value];
|
21 | __DEV__ ? globals.invariant(evaledValue !== void 0, "Invalid variable referenced in @".concat(directive.name.value, " directive.")) : globals.invariant(evaledValue !== void 0, 40);
|
22 | }
|
23 | else {
|
24 | evaledValue = ifArgument.value.value;
|
25 | }
|
26 | return directive.name.value === 'skip' ? !evaledValue : evaledValue;
|
27 | });
|
28 | }
|
29 | function getDirectiveNames(root) {
|
30 | var names = [];
|
31 | graphql.visit(root, {
|
32 | Directive: function (node) {
|
33 | names.push(node.name.value);
|
34 | },
|
35 | });
|
36 | return names;
|
37 | }
|
38 | var hasAnyDirectives = function (names, root) { return hasDirectives(names, root, false); };
|
39 | var hasAllDirectives = function (names, root) { return hasDirectives(names, root, true); };
|
40 | function hasDirectives(names, root, all) {
|
41 | var nameSet = new Set(names);
|
42 | var uniqueCount = nameSet.size;
|
43 | graphql.visit(root, {
|
44 | Directive: function (node) {
|
45 | if (nameSet.delete(node.name.value) &&
|
46 | (!all || !nameSet.size)) {
|
47 | return graphql.BREAK;
|
48 | }
|
49 | },
|
50 | });
|
51 | return all ? !nameSet.size : nameSet.size < uniqueCount;
|
52 | }
|
53 | function hasClientExports(document) {
|
54 | return document && hasDirectives(['client', 'export'], document, true);
|
55 | }
|
56 | function isInclusionDirective(_a) {
|
57 | var value = _a.name.value;
|
58 | return value === 'skip' || value === 'include';
|
59 | }
|
60 | function getInclusionDirectives(directives) {
|
61 | var result = [];
|
62 | if (directives && directives.length) {
|
63 | directives.forEach(function (directive) {
|
64 | if (!isInclusionDirective(directive))
|
65 | return;
|
66 | var directiveArguments = directive.arguments;
|
67 | var directiveName = directive.name.value;
|
68 | __DEV__ ? globals.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @".concat(directiveName, " directive.")) : globals.invariant(directiveArguments && directiveArguments.length === 1, 41);
|
69 | var ifArgument = directiveArguments[0];
|
70 | __DEV__ ? globals.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @".concat(directiveName, " directive.")) : globals.invariant(ifArgument.name && ifArgument.name.value === 'if', 42);
|
71 | var ifValue = ifArgument.value;
|
72 | __DEV__ ? globals.invariant(ifValue &&
|
73 | (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @".concat(directiveName, " directive must be a variable or a boolean value.")) : globals.invariant(ifValue &&
|
74 | (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 43);
|
75 | result.push({ directive: directive, ifArgument: ifArgument });
|
76 | });
|
77 | }
|
78 | return result;
|
79 | }
|
80 |
|
81 | function getFragmentQueryDocument(document, fragmentName) {
|
82 | var actualFragmentName = fragmentName;
|
83 | var fragments = [];
|
84 | document.definitions.forEach(function (definition) {
|
85 | if (definition.kind === 'OperationDefinition') {
|
86 | throw __DEV__ ? new globals.InvariantError("Found a ".concat(definition.operation, " operation").concat(definition.name ? " named '".concat(definition.name.value, "'") : '', ". ") +
|
87 | 'No operations are allowed when using a fragment as a query. Only fragments are allowed.') : new globals.InvariantError(44);
|
88 | }
|
89 | if (definition.kind === 'FragmentDefinition') {
|
90 | fragments.push(definition);
|
91 | }
|
92 | });
|
93 | if (typeof actualFragmentName === 'undefined') {
|
94 | __DEV__ ? globals.invariant(fragments.length === 1, "Found ".concat(fragments.length, " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.")) : globals.invariant(fragments.length === 1, 45);
|
95 | actualFragmentName = fragments[0].name.value;
|
96 | }
|
97 | var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
|
98 | {
|
99 | kind: 'OperationDefinition',
|
100 | operation: 'query',
|
101 | selectionSet: {
|
102 | kind: 'SelectionSet',
|
103 | selections: [
|
104 | {
|
105 | kind: 'FragmentSpread',
|
106 | name: {
|
107 | kind: 'Name',
|
108 | value: actualFragmentName,
|
109 | },
|
110 | },
|
111 | ],
|
112 | },
|
113 | }
|
114 | ], document.definitions, true) });
|
115 | return query;
|
116 | }
|
117 | function createFragmentMap(fragments) {
|
118 | if (fragments === void 0) { fragments = []; }
|
119 | var symTable = {};
|
120 | fragments.forEach(function (fragment) {
|
121 | symTable[fragment.name.value] = fragment;
|
122 | });
|
123 | return symTable;
|
124 | }
|
125 | function getFragmentFromSelection(selection, fragmentMap) {
|
126 | switch (selection.kind) {
|
127 | case 'InlineFragment':
|
128 | return selection;
|
129 | case 'FragmentSpread': {
|
130 | var fragmentName = selection.name.value;
|
131 | if (typeof fragmentMap === "function") {
|
132 | return fragmentMap(fragmentName);
|
133 | }
|
134 | var fragment = fragmentMap && fragmentMap[fragmentName];
|
135 | __DEV__ ? globals.invariant(fragment, "No fragment named ".concat(fragmentName)) : globals.invariant(fragment, 46);
|
136 | return fragment || null;
|
137 | }
|
138 | default:
|
139 | return null;
|
140 | }
|
141 | }
|
142 |
|
143 | function isNonNullObject(obj) {
|
144 | return obj !== null && typeof obj === 'object';
|
145 | }
|
146 |
|
147 | function makeReference(id) {
|
148 | return { __ref: String(id) };
|
149 | }
|
150 | function isReference(obj) {
|
151 | return Boolean(obj && typeof obj === 'object' && typeof obj.__ref === 'string');
|
152 | }
|
153 | function isDocumentNode(value) {
|
154 | return (isNonNullObject(value) &&
|
155 | value.kind === "Document" &&
|
156 | Array.isArray(value.definitions));
|
157 | }
|
158 | function isStringValue(value) {
|
159 | return value.kind === 'StringValue';
|
160 | }
|
161 | function isBooleanValue(value) {
|
162 | return value.kind === 'BooleanValue';
|
163 | }
|
164 | function isIntValue(value) {
|
165 | return value.kind === 'IntValue';
|
166 | }
|
167 | function isFloatValue(value) {
|
168 | return value.kind === 'FloatValue';
|
169 | }
|
170 | function isVariable(value) {
|
171 | return value.kind === 'Variable';
|
172 | }
|
173 | function isObjectValue(value) {
|
174 | return value.kind === 'ObjectValue';
|
175 | }
|
176 | function isListValue(value) {
|
177 | return value.kind === 'ListValue';
|
178 | }
|
179 | function isEnumValue(value) {
|
180 | return value.kind === 'EnumValue';
|
181 | }
|
182 | function isNullValue(value) {
|
183 | return value.kind === 'NullValue';
|
184 | }
|
185 | function valueToObjectRepresentation(argObj, name, value, variables) {
|
186 | if (isIntValue(value) || isFloatValue(value)) {
|
187 | argObj[name.value] = Number(value.value);
|
188 | }
|
189 | else if (isBooleanValue(value) || isStringValue(value)) {
|
190 | argObj[name.value] = value.value;
|
191 | }
|
192 | else if (isObjectValue(value)) {
|
193 | var nestedArgObj_1 = {};
|
194 | value.fields.map(function (obj) {
|
195 | return valueToObjectRepresentation(nestedArgObj_1, obj.name, obj.value, variables);
|
196 | });
|
197 | argObj[name.value] = nestedArgObj_1;
|
198 | }
|
199 | else if (isVariable(value)) {
|
200 | var variableValue = (variables || {})[value.name.value];
|
201 | argObj[name.value] = variableValue;
|
202 | }
|
203 | else if (isListValue(value)) {
|
204 | argObj[name.value] = value.values.map(function (listValue) {
|
205 | var nestedArgArrayObj = {};
|
206 | valueToObjectRepresentation(nestedArgArrayObj, name, listValue, variables);
|
207 | return nestedArgArrayObj[name.value];
|
208 | });
|
209 | }
|
210 | else if (isEnumValue(value)) {
|
211 | argObj[name.value] = value.value;
|
212 | }
|
213 | else if (isNullValue(value)) {
|
214 | argObj[name.value] = null;
|
215 | }
|
216 | else {
|
217 | throw __DEV__ ? new globals.InvariantError("The inline argument \"".concat(name.value, "\" of kind \"").concat(value.kind, "\"") +
|
218 | 'is not supported. Use variables instead of inline arguments to ' +
|
219 | 'overcome this limitation.') : new globals.InvariantError(55);
|
220 | }
|
221 | }
|
222 | function storeKeyNameFromField(field, variables) {
|
223 | var directivesObj = null;
|
224 | if (field.directives) {
|
225 | directivesObj = {};
|
226 | field.directives.forEach(function (directive) {
|
227 | directivesObj[directive.name.value] = {};
|
228 | if (directive.arguments) {
|
229 | directive.arguments.forEach(function (_a) {
|
230 | var name = _a.name, value = _a.value;
|
231 | return valueToObjectRepresentation(directivesObj[directive.name.value], name, value, variables);
|
232 | });
|
233 | }
|
234 | });
|
235 | }
|
236 | var argObj = null;
|
237 | if (field.arguments && field.arguments.length) {
|
238 | argObj = {};
|
239 | field.arguments.forEach(function (_a) {
|
240 | var name = _a.name, value = _a.value;
|
241 | return valueToObjectRepresentation(argObj, name, value, variables);
|
242 | });
|
243 | }
|
244 | return getStoreKeyName(field.name.value, argObj, directivesObj);
|
245 | }
|
246 | var KNOWN_DIRECTIVES = [
|
247 | 'connection',
|
248 | 'include',
|
249 | 'skip',
|
250 | 'client',
|
251 | 'rest',
|
252 | 'export',
|
253 | ];
|
254 | var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
|
255 | if (args &&
|
256 | directives &&
|
257 | directives['connection'] &&
|
258 | directives['connection']['key']) {
|
259 | if (directives['connection']['filter'] &&
|
260 | directives['connection']['filter'].length > 0) {
|
261 | var filterKeys = directives['connection']['filter']
|
262 | ? directives['connection']['filter']
|
263 | : [];
|
264 | filterKeys.sort();
|
265 | var filteredArgs_1 = {};
|
266 | filterKeys.forEach(function (key) {
|
267 | filteredArgs_1[key] = args[key];
|
268 | });
|
269 | return "".concat(directives['connection']['key'], "(").concat(stringify(filteredArgs_1), ")");
|
270 | }
|
271 | else {
|
272 | return directives['connection']['key'];
|
273 | }
|
274 | }
|
275 | var completeFieldName = fieldName;
|
276 | if (args) {
|
277 | var stringifiedArgs = stringify(args);
|
278 | completeFieldName += "(".concat(stringifiedArgs, ")");
|
279 | }
|
280 | if (directives) {
|
281 | Object.keys(directives).forEach(function (key) {
|
282 | if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
|
283 | return;
|
284 | if (directives[key] && Object.keys(directives[key]).length) {
|
285 | completeFieldName += "@".concat(key, "(").concat(stringify(directives[key]), ")");
|
286 | }
|
287 | else {
|
288 | completeFieldName += "@".concat(key);
|
289 | }
|
290 | });
|
291 | }
|
292 | return completeFieldName;
|
293 | }, {
|
294 | setStringify: function (s) {
|
295 | var previous = stringify;
|
296 | stringify = s;
|
297 | return previous;
|
298 | },
|
299 | });
|
300 | var stringify = function defaultStringify(value) {
|
301 | return JSON.stringify(value, stringifyReplacer);
|
302 | };
|
303 | function stringifyReplacer(_key, value) {
|
304 | if (isNonNullObject(value) && !Array.isArray(value)) {
|
305 | value = Object.keys(value).sort().reduce(function (copy, key) {
|
306 | copy[key] = value[key];
|
307 | return copy;
|
308 | }, {});
|
309 | }
|
310 | return value;
|
311 | }
|
312 | function argumentsObjectFromField(field, variables) {
|
313 | if (field.arguments && field.arguments.length) {
|
314 | var argObj_1 = {};
|
315 | field.arguments.forEach(function (_a) {
|
316 | var name = _a.name, value = _a.value;
|
317 | return valueToObjectRepresentation(argObj_1, name, value, variables);
|
318 | });
|
319 | return argObj_1;
|
320 | }
|
321 | return null;
|
322 | }
|
323 | function resultKeyNameFromField(field) {
|
324 | return field.alias ? field.alias.value : field.name.value;
|
325 | }
|
326 | function getTypenameFromResult(result, selectionSet, fragmentMap) {
|
327 | if (typeof result.__typename === 'string') {
|
328 | return result.__typename;
|
329 | }
|
330 | for (var _i = 0, _a = selectionSet.selections; _i < _a.length; _i++) {
|
331 | var selection = _a[_i];
|
332 | if (isField(selection)) {
|
333 | if (selection.name.value === '__typename') {
|
334 | return result[resultKeyNameFromField(selection)];
|
335 | }
|
336 | }
|
337 | else {
|
338 | var typename = getTypenameFromResult(result, getFragmentFromSelection(selection, fragmentMap).selectionSet, fragmentMap);
|
339 | if (typeof typename === 'string') {
|
340 | return typename;
|
341 | }
|
342 | }
|
343 | }
|
344 | }
|
345 | function isField(selection) {
|
346 | return selection.kind === 'Field';
|
347 | }
|
348 | function isInlineFragment(selection) {
|
349 | return selection.kind === 'InlineFragment';
|
350 | }
|
351 |
|
352 | function checkDocument(doc) {
|
353 | __DEV__ ? globals.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : globals.invariant(doc && doc.kind === 'Document', 47);
|
354 | var operations = doc.definitions
|
355 | .filter(function (d) { return d.kind !== 'FragmentDefinition'; })
|
356 | .map(function (definition) {
|
357 | if (definition.kind !== 'OperationDefinition') {
|
358 | throw __DEV__ ? new globals.InvariantError("Schema type definitions not allowed in queries. Found: \"".concat(definition.kind, "\"")) : new globals.InvariantError(48);
|
359 | }
|
360 | return definition;
|
361 | });
|
362 | __DEV__ ? globals.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains ".concat(operations.length, " operations")) : globals.invariant(operations.length <= 1, 49);
|
363 | return doc;
|
364 | }
|
365 | function getOperationDefinition(doc) {
|
366 | checkDocument(doc);
|
367 | return doc.definitions.filter(function (definition) {
|
368 | return definition.kind === 'OperationDefinition';
|
369 | })[0];
|
370 | }
|
371 | function getOperationName(doc) {
|
372 | return (doc.definitions
|
373 | .filter(function (definition) {
|
374 | return definition.kind === 'OperationDefinition' && !!definition.name;
|
375 | })
|
376 | .map(function (x) { return x.name.value; })[0] || null);
|
377 | }
|
378 | function getFragmentDefinitions(doc) {
|
379 | return doc.definitions.filter(function (definition) {
|
380 | return definition.kind === 'FragmentDefinition';
|
381 | });
|
382 | }
|
383 | function getQueryDefinition(doc) {
|
384 | var queryDef = getOperationDefinition(doc);
|
385 | __DEV__ ? globals.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.') : globals.invariant(queryDef && queryDef.operation === 'query', 50);
|
386 | return queryDef;
|
387 | }
|
388 | function getFragmentDefinition(doc) {
|
389 | __DEV__ ? globals.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql") : globals.invariant(doc.kind === 'Document', 51);
|
390 | __DEV__ ? globals.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.') : globals.invariant(doc.definitions.length <= 1, 52);
|
391 | var fragmentDef = doc.definitions[0];
|
392 | __DEV__ ? globals.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.') : globals.invariant(fragmentDef.kind === 'FragmentDefinition', 53);
|
393 | return fragmentDef;
|
394 | }
|
395 | function getMainDefinition(queryDoc) {
|
396 | checkDocument(queryDoc);
|
397 | var fragmentDefinition;
|
398 | for (var _i = 0, _a = queryDoc.definitions; _i < _a.length; _i++) {
|
399 | var definition = _a[_i];
|
400 | if (definition.kind === 'OperationDefinition') {
|
401 | var operation = definition.operation;
|
402 | if (operation === 'query' ||
|
403 | operation === 'mutation' ||
|
404 | operation === 'subscription') {
|
405 | return definition;
|
406 | }
|
407 | }
|
408 | if (definition.kind === 'FragmentDefinition' && !fragmentDefinition) {
|
409 | fragmentDefinition = definition;
|
410 | }
|
411 | }
|
412 | if (fragmentDefinition) {
|
413 | return fragmentDefinition;
|
414 | }
|
415 | throw __DEV__ ? new globals.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.') : new globals.InvariantError(54);
|
416 | }
|
417 | function getDefaultValues(definition) {
|
418 | var defaultValues = Object.create(null);
|
419 | var defs = definition && definition.variableDefinitions;
|
420 | if (defs && defs.length) {
|
421 | defs.forEach(function (def) {
|
422 | if (def.defaultValue) {
|
423 | valueToObjectRepresentation(defaultValues, def.variable.name, def.defaultValue);
|
424 | }
|
425 | });
|
426 | }
|
427 | return defaultValues;
|
428 | }
|
429 |
|
430 | var isArray = Array.isArray;
|
431 | function isNonEmptyArray(value) {
|
432 | return Array.isArray(value) && value.length > 0;
|
433 | }
|
434 |
|
435 | var TYPENAME_FIELD = {
|
436 | kind: graphql.Kind.FIELD,
|
437 | name: {
|
438 | kind: graphql.Kind.NAME,
|
439 | value: '__typename',
|
440 | },
|
441 | };
|
442 | function isEmpty(op, fragmentMap) {
|
443 | return !op || op.selectionSet.selections.every(function (selection) { return selection.kind === graphql.Kind.FRAGMENT_SPREAD &&
|
444 | isEmpty(fragmentMap[selection.name.value], fragmentMap); });
|
445 | }
|
446 | function nullIfDocIsEmpty(doc) {
|
447 | return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))
|
448 | ? null
|
449 | : doc;
|
450 | }
|
451 | function getDirectiveMatcher(directives) {
|
452 | var nameSet = new Set();
|
453 | var tests = [];
|
454 | directives.forEach(function (directive) {
|
455 | if (directive.name) {
|
456 | nameSet.add(directive.name);
|
457 | }
|
458 | else if (directive.test) {
|
459 | tests.push(directive.test);
|
460 | }
|
461 | });
|
462 | return function (directive) { return (nameSet.has(directive.name.value) ||
|
463 | tests.some(function (test) { return test(directive); })); };
|
464 | }
|
465 | function makeInUseGetterFunction(defaultKey) {
|
466 | var map = new Map();
|
467 | return function inUseGetterFunction(key) {
|
468 | if (key === void 0) { key = defaultKey; }
|
469 | var inUse = map.get(key);
|
470 | if (!inUse) {
|
471 | map.set(key, inUse = {
|
472 | variables: new Set,
|
473 | fragmentSpreads: new Set,
|
474 | });
|
475 | }
|
476 | return inUse;
|
477 | };
|
478 | }
|
479 | function removeDirectivesFromDocument(directives, doc) {
|
480 | var getInUseByOperationName = makeInUseGetterFunction("");
|
481 | var getInUseByFragmentName = makeInUseGetterFunction("");
|
482 | var getInUse = function (ancestors) {
|
483 | for (var p = 0, ancestor = void 0; p < ancestors.length && (ancestor = ancestors[p]); ++p) {
|
484 | if (isArray(ancestor))
|
485 | continue;
|
486 | if (ancestor.kind === graphql.Kind.OPERATION_DEFINITION) {
|
487 | return getInUseByOperationName(ancestor.name && ancestor.name.value);
|
488 | }
|
489 | if (ancestor.kind === graphql.Kind.FRAGMENT_DEFINITION) {
|
490 | return getInUseByFragmentName(ancestor.name.value);
|
491 | }
|
492 | }
|
493 | __DEV__ && globals.invariant.error("Could not find operation or fragment");
|
494 | return null;
|
495 | };
|
496 | var operationCount = 0;
|
497 | for (var i = doc.definitions.length - 1; i >= 0; --i) {
|
498 | if (doc.definitions[i].kind === graphql.Kind.OPERATION_DEFINITION) {
|
499 | ++operationCount;
|
500 | }
|
501 | }
|
502 | var directiveMatcher = getDirectiveMatcher(directives);
|
503 | var hasRemoveDirective = directives.some(function (directive) { return directive.remove; });
|
504 | var shouldRemoveField = function (nodeDirectives) { return (hasRemoveDirective &&
|
505 | nodeDirectives &&
|
506 | nodeDirectives.some(directiveMatcher)); };
|
507 | var originalFragmentDefsByPath = new Map();
|
508 | var firstVisitMadeChanges = false;
|
509 | var fieldOrInlineFragmentVisitor = {
|
510 | enter: function (node) {
|
511 | if (shouldRemoveField(node.directives)) {
|
512 | firstVisitMadeChanges = true;
|
513 | return null;
|
514 | }
|
515 | },
|
516 | };
|
517 | var docWithoutDirectiveSubtrees = graphql.visit(doc, {
|
518 | Field: fieldOrInlineFragmentVisitor,
|
519 | InlineFragment: fieldOrInlineFragmentVisitor,
|
520 | VariableDefinition: {
|
521 | enter: function () {
|
522 | return false;
|
523 | },
|
524 | },
|
525 | Variable: {
|
526 | enter: function (node, _key, _parent, _path, ancestors) {
|
527 | var inUse = getInUse(ancestors);
|
528 | if (inUse) {
|
529 | inUse.variables.add(node.name.value);
|
530 | }
|
531 | },
|
532 | },
|
533 | FragmentSpread: {
|
534 | enter: function (node, _key, _parent, _path, ancestors) {
|
535 | if (shouldRemoveField(node.directives)) {
|
536 | firstVisitMadeChanges = true;
|
537 | return null;
|
538 | }
|
539 | var inUse = getInUse(ancestors);
|
540 | if (inUse) {
|
541 | inUse.fragmentSpreads.add(node.name.value);
|
542 | }
|
543 | },
|
544 | },
|
545 | FragmentDefinition: {
|
546 | enter: function (node, _key, _parent, path) {
|
547 | originalFragmentDefsByPath.set(JSON.stringify(path), node);
|
548 | },
|
549 | leave: function (node, _key, _parent, path) {
|
550 | var originalNode = originalFragmentDefsByPath.get(JSON.stringify(path));
|
551 | if (node === originalNode) {
|
552 | return node;
|
553 | }
|
554 | if (operationCount > 0 &&
|
555 | node.selectionSet.selections.every(function (selection) { return (selection.kind === graphql.Kind.FIELD &&
|
556 | selection.name.value === '__typename'); })) {
|
557 | getInUseByFragmentName(node.name.value).removed = true;
|
558 | firstVisitMadeChanges = true;
|
559 | return null;
|
560 | }
|
561 | },
|
562 | },
|
563 | Directive: {
|
564 | leave: function (node) {
|
565 | if (directiveMatcher(node)) {
|
566 | firstVisitMadeChanges = true;
|
567 | return null;
|
568 | }
|
569 | },
|
570 | },
|
571 | });
|
572 | if (!firstVisitMadeChanges) {
|
573 | return doc;
|
574 | }
|
575 | var populateTransitiveVars = function (inUse) {
|
576 | if (!inUse.transitiveVars) {
|
577 | inUse.transitiveVars = new Set(inUse.variables);
|
578 | if (!inUse.removed) {
|
579 | inUse.fragmentSpreads.forEach(function (childFragmentName) {
|
580 | populateTransitiveVars(getInUseByFragmentName(childFragmentName)).transitiveVars.forEach(function (varName) {
|
581 | inUse.transitiveVars.add(varName);
|
582 | });
|
583 | });
|
584 | }
|
585 | }
|
586 | return inUse;
|
587 | };
|
588 | var allFragmentNamesUsed = new Set();
|
589 | docWithoutDirectiveSubtrees.definitions.forEach(function (def) {
|
590 | if (def.kind === graphql.Kind.OPERATION_DEFINITION) {
|
591 | populateTransitiveVars(getInUseByOperationName(def.name && def.name.value)).fragmentSpreads.forEach(function (childFragmentName) {
|
592 | allFragmentNamesUsed.add(childFragmentName);
|
593 | });
|
594 | }
|
595 | else if (def.kind === graphql.Kind.FRAGMENT_DEFINITION &&
|
596 | operationCount === 0 &&
|
597 | !getInUseByFragmentName(def.name.value).removed) {
|
598 | allFragmentNamesUsed.add(def.name.value);
|
599 | }
|
600 | });
|
601 | allFragmentNamesUsed.forEach(function (fragmentName) {
|
602 | populateTransitiveVars(getInUseByFragmentName(fragmentName)).fragmentSpreads.forEach(function (childFragmentName) {
|
603 | allFragmentNamesUsed.add(childFragmentName);
|
604 | });
|
605 | });
|
606 | var fragmentWillBeRemoved = function (fragmentName) { return !!(!allFragmentNamesUsed.has(fragmentName) ||
|
607 | getInUseByFragmentName(fragmentName).removed); };
|
608 | var enterVisitor = {
|
609 | enter: function (node) {
|
610 | if (fragmentWillBeRemoved(node.name.value)) {
|
611 | return null;
|
612 | }
|
613 | },
|
614 | };
|
615 | return nullIfDocIsEmpty(graphql.visit(docWithoutDirectiveSubtrees, {
|
616 | FragmentSpread: enterVisitor,
|
617 | FragmentDefinition: enterVisitor,
|
618 | OperationDefinition: {
|
619 | leave: function (node) {
|
620 | if (node.variableDefinitions) {
|
621 | var usedVariableNames_1 = populateTransitiveVars(getInUseByOperationName(node.name && node.name.value)).transitiveVars;
|
622 | if (usedVariableNames_1.size < node.variableDefinitions.length) {
|
623 | return tslib.__assign(tslib.__assign({}, node), { variableDefinitions: node.variableDefinitions.filter(function (varDef) { return usedVariableNames_1.has(varDef.variable.name.value); }) });
|
624 | }
|
625 | }
|
626 | },
|
627 | },
|
628 | }));
|
629 | }
|
630 | var addTypenameToDocument = Object.assign(function (doc) {
|
631 | return graphql.visit(doc, {
|
632 | SelectionSet: {
|
633 | enter: function (node, _key, parent) {
|
634 | if (parent &&
|
635 | parent.kind === graphql.Kind.OPERATION_DEFINITION) {
|
636 | return;
|
637 | }
|
638 | var selections = node.selections;
|
639 | if (!selections) {
|
640 | return;
|
641 | }
|
642 | var skip = selections.some(function (selection) {
|
643 | return (isField(selection) &&
|
644 | (selection.name.value === '__typename' ||
|
645 | selection.name.value.lastIndexOf('__', 0) === 0));
|
646 | });
|
647 | if (skip) {
|
648 | return;
|
649 | }
|
650 | var field = parent;
|
651 | if (isField(field) &&
|
652 | field.directives &&
|
653 | field.directives.some(function (d) { return d.name.value === 'export'; })) {
|
654 | return;
|
655 | }
|
656 | return tslib.__assign(tslib.__assign({}, node), { selections: tslib.__spreadArray(tslib.__spreadArray([], selections, true), [TYPENAME_FIELD], false) });
|
657 | },
|
658 | },
|
659 | });
|
660 | }, {
|
661 | added: function (field) {
|
662 | return field === TYPENAME_FIELD;
|
663 | },
|
664 | });
|
665 | var connectionRemoveConfig = {
|
666 | test: function (directive) {
|
667 | var willRemove = directive.name.value === 'connection';
|
668 | if (willRemove) {
|
669 | if (!directive.arguments ||
|
670 | !directive.arguments.some(function (arg) { return arg.name.value === 'key'; })) {
|
671 | __DEV__ && globals.invariant.warn('Removing an @connection directive even though it does not have a key. ' +
|
672 | 'You may want to use the key parameter to specify a store key.');
|
673 | }
|
674 | }
|
675 | return willRemove;
|
676 | },
|
677 | };
|
678 | function removeConnectionDirectiveFromDocument(doc) {
|
679 | return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
|
680 | }
|
681 | function getArgumentMatcher(config) {
|
682 | return function argumentMatcher(argument) {
|
683 | return config.some(function (aConfig) {
|
684 | return argument.value &&
|
685 | argument.value.kind === graphql.Kind.VARIABLE &&
|
686 | argument.value.name &&
|
687 | (aConfig.name === argument.value.name.value ||
|
688 | (aConfig.test && aConfig.test(argument)));
|
689 | });
|
690 | };
|
691 | }
|
692 | function removeArgumentsFromDocument(config, doc) {
|
693 | var argMatcher = getArgumentMatcher(config);
|
694 | return nullIfDocIsEmpty(graphql.visit(doc, {
|
695 | OperationDefinition: {
|
696 | enter: function (node) {
|
697 | return tslib.__assign(tslib.__assign({}, node), { variableDefinitions: node.variableDefinitions ? node.variableDefinitions.filter(function (varDef) {
|
698 | return !config.some(function (arg) { return arg.name === varDef.variable.name.value; });
|
699 | }) : [] });
|
700 | },
|
701 | },
|
702 | Field: {
|
703 | enter: function (node) {
|
704 | var shouldRemoveField = config.some(function (argConfig) { return argConfig.remove; });
|
705 | if (shouldRemoveField) {
|
706 | var argMatchCount_1 = 0;
|
707 | if (node.arguments) {
|
708 | node.arguments.forEach(function (arg) {
|
709 | if (argMatcher(arg)) {
|
710 | argMatchCount_1 += 1;
|
711 | }
|
712 | });
|
713 | }
|
714 | if (argMatchCount_1 === 1) {
|
715 | return null;
|
716 | }
|
717 | }
|
718 | },
|
719 | },
|
720 | Argument: {
|
721 | enter: function (node) {
|
722 | if (argMatcher(node)) {
|
723 | return null;
|
724 | }
|
725 | },
|
726 | },
|
727 | }));
|
728 | }
|
729 | function removeFragmentSpreadFromDocument(config, doc) {
|
730 | function enter(node) {
|
731 | if (config.some(function (def) { return def.name === node.name.value; })) {
|
732 | return null;
|
733 | }
|
734 | }
|
735 | return nullIfDocIsEmpty(graphql.visit(doc, {
|
736 | FragmentSpread: { enter: enter },
|
737 | FragmentDefinition: { enter: enter },
|
738 | }));
|
739 | }
|
740 | function buildQueryFromSelectionSet(document) {
|
741 | var definition = getMainDefinition(document);
|
742 | var definitionOperation = definition.operation;
|
743 | if (definitionOperation === 'query') {
|
744 | return document;
|
745 | }
|
746 | var modifiedDoc = graphql.visit(document, {
|
747 | OperationDefinition: {
|
748 | enter: function (node) {
|
749 | return tslib.__assign(tslib.__assign({}, node), { operation: 'query' });
|
750 | },
|
751 | },
|
752 | });
|
753 | return modifiedDoc;
|
754 | }
|
755 | function removeClientSetsFromDocument(document) {
|
756 | checkDocument(document);
|
757 | var modifiedDoc = removeDirectivesFromDocument([
|
758 | {
|
759 | test: function (directive) { return directive.name.value === 'client'; },
|
760 | remove: true,
|
761 | },
|
762 | ], document);
|
763 | return modifiedDoc;
|
764 | }
|
765 |
|
766 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
767 | function mergeDeep() {
|
768 | var sources = [];
|
769 | for (var _i = 0; _i < arguments.length; _i++) {
|
770 | sources[_i] = arguments[_i];
|
771 | }
|
772 | return mergeDeepArray(sources);
|
773 | }
|
774 | function mergeDeepArray(sources) {
|
775 | var target = sources[0] || {};
|
776 | var count = sources.length;
|
777 | if (count > 1) {
|
778 | var merger = new DeepMerger();
|
779 | for (var i = 1; i < count; ++i) {
|
780 | target = merger.merge(target, sources[i]);
|
781 | }
|
782 | }
|
783 | return target;
|
784 | }
|
785 | var defaultReconciler = function (target, source, property) {
|
786 | return this.merge(target[property], source[property]);
|
787 | };
|
788 | var DeepMerger = (function () {
|
789 | function DeepMerger(reconciler) {
|
790 | if (reconciler === void 0) { reconciler = defaultReconciler; }
|
791 | this.reconciler = reconciler;
|
792 | this.isObject = isNonNullObject;
|
793 | this.pastCopies = new Set();
|
794 | }
|
795 | DeepMerger.prototype.merge = function (target, source) {
|
796 | var _this = this;
|
797 | var context = [];
|
798 | for (var _i = 2; _i < arguments.length; _i++) {
|
799 | context[_i - 2] = arguments[_i];
|
800 | }
|
801 | if (isNonNullObject(source) && isNonNullObject(target)) {
|
802 | Object.keys(source).forEach(function (sourceKey) {
|
803 | if (hasOwnProperty.call(target, sourceKey)) {
|
804 | var targetValue = target[sourceKey];
|
805 | if (source[sourceKey] !== targetValue) {
|
806 | var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
|
807 | if (result !== targetValue) {
|
808 | target = _this.shallowCopyForMerge(target);
|
809 | target[sourceKey] = result;
|
810 | }
|
811 | }
|
812 | }
|
813 | else {
|
814 | target = _this.shallowCopyForMerge(target);
|
815 | target[sourceKey] = source[sourceKey];
|
816 | }
|
817 | });
|
818 | return target;
|
819 | }
|
820 | return source;
|
821 | };
|
822 | DeepMerger.prototype.shallowCopyForMerge = function (value) {
|
823 | if (isNonNullObject(value)) {
|
824 | if (!this.pastCopies.has(value)) {
|
825 | if (Array.isArray(value)) {
|
826 | value = value.slice(0);
|
827 | }
|
828 | else {
|
829 | value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
|
830 | }
|
831 | this.pastCopies.add(value);
|
832 | }
|
833 | }
|
834 | return value;
|
835 | };
|
836 | return DeepMerger;
|
837 | }());
|
838 |
|
839 | function concatPagination(keyArgs) {
|
840 | if (keyArgs === void 0) { keyArgs = false; }
|
841 | return {
|
842 | keyArgs: keyArgs,
|
843 | merge: function (existing, incoming) {
|
844 | return existing ? tslib.__spreadArray(tslib.__spreadArray([], existing, true), incoming, true) : incoming;
|
845 | },
|
846 | };
|
847 | }
|
848 | function offsetLimitPagination(keyArgs) {
|
849 | if (keyArgs === void 0) { keyArgs = false; }
|
850 | return {
|
851 | keyArgs: keyArgs,
|
852 | merge: function (existing, incoming, _a) {
|
853 | var args = _a.args;
|
854 | var merged = existing ? existing.slice(0) : [];
|
855 | if (incoming) {
|
856 | if (args) {
|
857 | var _b = args.offset, offset = _b === void 0 ? 0 : _b;
|
858 | for (var i = 0; i < incoming.length; ++i) {
|
859 | merged[offset + i] = incoming[i];
|
860 | }
|
861 | }
|
862 | else {
|
863 | merged.push.apply(merged, incoming);
|
864 | }
|
865 | }
|
866 | return merged;
|
867 | },
|
868 | };
|
869 | }
|
870 | function relayStylePagination(keyArgs) {
|
871 | if (keyArgs === void 0) { keyArgs = false; }
|
872 | return {
|
873 | keyArgs: keyArgs,
|
874 | read: function (existing, _a) {
|
875 | var canRead = _a.canRead, readField = _a.readField;
|
876 | if (!existing)
|
877 | return existing;
|
878 | var edges = [];
|
879 | var firstEdgeCursor = "";
|
880 | var lastEdgeCursor = "";
|
881 | existing.edges.forEach(function (edge) {
|
882 | if (canRead(readField("node", edge))) {
|
883 | edges.push(edge);
|
884 | if (edge.cursor) {
|
885 | firstEdgeCursor = firstEdgeCursor || edge.cursor || "";
|
886 | lastEdgeCursor = edge.cursor || lastEdgeCursor;
|
887 | }
|
888 | }
|
889 | });
|
890 | var _b = existing.pageInfo || {}, startCursor = _b.startCursor, endCursor = _b.endCursor;
|
891 | return tslib.__assign(tslib.__assign({}, getExtras(existing)), { edges: edges, pageInfo: tslib.__assign(tslib.__assign({}, existing.pageInfo), { startCursor: startCursor || firstEdgeCursor, endCursor: endCursor || lastEdgeCursor }) });
|
892 | },
|
893 | merge: function (existing, incoming, _a) {
|
894 | var args = _a.args, isReference = _a.isReference, readField = _a.readField;
|
895 | if (!existing) {
|
896 | existing = makeEmptyData();
|
897 | }
|
898 | if (!incoming) {
|
899 | return existing;
|
900 | }
|
901 | var incomingEdges = incoming.edges ? incoming.edges.map(function (edge) {
|
902 | if (isReference(edge = tslib.__assign({}, edge))) {
|
903 | edge.cursor = readField("cursor", edge);
|
904 | }
|
905 | return edge;
|
906 | }) : [];
|
907 | if (incoming.pageInfo) {
|
908 | var pageInfo_1 = incoming.pageInfo;
|
909 | var startCursor = pageInfo_1.startCursor, endCursor = pageInfo_1.endCursor;
|
910 | var firstEdge = incomingEdges[0];
|
911 | var lastEdge = incomingEdges[incomingEdges.length - 1];
|
912 | if (firstEdge && startCursor) {
|
913 | firstEdge.cursor = startCursor;
|
914 | }
|
915 | if (lastEdge && endCursor) {
|
916 | lastEdge.cursor = endCursor;
|
917 | }
|
918 | var firstCursor = firstEdge && firstEdge.cursor;
|
919 | if (firstCursor && !startCursor) {
|
920 | incoming = mergeDeep(incoming, {
|
921 | pageInfo: {
|
922 | startCursor: firstCursor,
|
923 | },
|
924 | });
|
925 | }
|
926 | var lastCursor = lastEdge && lastEdge.cursor;
|
927 | if (lastCursor && !endCursor) {
|
928 | incoming = mergeDeep(incoming, {
|
929 | pageInfo: {
|
930 | endCursor: lastCursor,
|
931 | },
|
932 | });
|
933 | }
|
934 | }
|
935 | var prefix = existing.edges;
|
936 | var suffix = [];
|
937 | if (args && args.after) {
|
938 | var index = prefix.findIndex(function (edge) { return edge.cursor === args.after; });
|
939 | if (index >= 0) {
|
940 | prefix = prefix.slice(0, index + 1);
|
941 | }
|
942 | }
|
943 | else if (args && args.before) {
|
944 | var index = prefix.findIndex(function (edge) { return edge.cursor === args.before; });
|
945 | suffix = index < 0 ? prefix : prefix.slice(index);
|
946 | prefix = [];
|
947 | }
|
948 | else if (incoming.edges) {
|
949 | prefix = [];
|
950 | }
|
951 | var edges = tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], prefix, true), incomingEdges, true), suffix, true);
|
952 | var pageInfo = tslib.__assign(tslib.__assign({}, incoming.pageInfo), existing.pageInfo);
|
953 | if (incoming.pageInfo) {
|
954 | var _b = incoming.pageInfo, hasPreviousPage = _b.hasPreviousPage, hasNextPage = _b.hasNextPage, startCursor = _b.startCursor, endCursor = _b.endCursor, extras = tslib.__rest(_b, ["hasPreviousPage", "hasNextPage", "startCursor", "endCursor"]);
|
955 | Object.assign(pageInfo, extras);
|
956 | if (!prefix.length) {
|
957 | if (void 0 !== hasPreviousPage)
|
958 | pageInfo.hasPreviousPage = hasPreviousPage;
|
959 | if (void 0 !== startCursor)
|
960 | pageInfo.startCursor = startCursor;
|
961 | }
|
962 | if (!suffix.length) {
|
963 | if (void 0 !== hasNextPage)
|
964 | pageInfo.hasNextPage = hasNextPage;
|
965 | if (void 0 !== endCursor)
|
966 | pageInfo.endCursor = endCursor;
|
967 | }
|
968 | }
|
969 | return tslib.__assign(tslib.__assign(tslib.__assign({}, getExtras(existing)), getExtras(incoming)), { edges: edges, pageInfo: pageInfo });
|
970 | },
|
971 | };
|
972 | }
|
973 | var getExtras = function (obj) { return tslib.__rest(obj, notExtras); };
|
974 | var notExtras = ["edges", "pageInfo"];
|
975 | function makeEmptyData() {
|
976 | return {
|
977 | edges: [],
|
978 | pageInfo: {
|
979 | hasPreviousPage: false,
|
980 | hasNextPage: true,
|
981 | startCursor: "",
|
982 | endCursor: "",
|
983 | },
|
984 | };
|
985 | }
|
986 |
|
987 | var toString = Object.prototype.toString;
|
988 | function cloneDeep(value) {
|
989 | return cloneDeepHelper(value);
|
990 | }
|
991 | function cloneDeepHelper(val, seen) {
|
992 | switch (toString.call(val)) {
|
993 | case "[object Array]": {
|
994 | seen = seen || new Map;
|
995 | if (seen.has(val))
|
996 | return seen.get(val);
|
997 | var copy_1 = val.slice(0);
|
998 | seen.set(val, copy_1);
|
999 | copy_1.forEach(function (child, i) {
|
1000 | copy_1[i] = cloneDeepHelper(child, seen);
|
1001 | });
|
1002 | return copy_1;
|
1003 | }
|
1004 | case "[object Object]": {
|
1005 | seen = seen || new Map;
|
1006 | if (seen.has(val))
|
1007 | return seen.get(val);
|
1008 | var copy_2 = Object.create(Object.getPrototypeOf(val));
|
1009 | seen.set(val, copy_2);
|
1010 | Object.keys(val).forEach(function (key) {
|
1011 | copy_2[key] = cloneDeepHelper(val[key], seen);
|
1012 | });
|
1013 | return copy_2;
|
1014 | }
|
1015 | default:
|
1016 | return val;
|
1017 | }
|
1018 | }
|
1019 |
|
1020 | function deepFreeze(value) {
|
1021 | var workSet = new Set([value]);
|
1022 | workSet.forEach(function (obj) {
|
1023 | if (isNonNullObject(obj) && shallowFreeze(obj) === obj) {
|
1024 | Object.getOwnPropertyNames(obj).forEach(function (name) {
|
1025 | if (isNonNullObject(obj[name]))
|
1026 | workSet.add(obj[name]);
|
1027 | });
|
1028 | }
|
1029 | });
|
1030 | return value;
|
1031 | }
|
1032 | function shallowFreeze(obj) {
|
1033 | if (__DEV__ && !Object.isFrozen(obj)) {
|
1034 | try {
|
1035 | Object.freeze(obj);
|
1036 | }
|
1037 | catch (e) {
|
1038 | if (e instanceof TypeError)
|
1039 | return null;
|
1040 | throw e;
|
1041 | }
|
1042 | }
|
1043 | return obj;
|
1044 | }
|
1045 | function maybeDeepFreeze(obj) {
|
1046 | if (__DEV__) {
|
1047 | deepFreeze(obj);
|
1048 | }
|
1049 | return obj;
|
1050 | }
|
1051 |
|
1052 | function iterateObserversSafely(observers, method, argument) {
|
1053 | var observersWithMethod = [];
|
1054 | observers.forEach(function (obs) { return obs[method] && observersWithMethod.push(obs); });
|
1055 | observersWithMethod.forEach(function (obs) { return obs[method](argument); });
|
1056 | }
|
1057 |
|
1058 | function asyncMap(observable, mapFn, catchFn) {
|
1059 | return new zenObservableTs.Observable(function (observer) {
|
1060 | var next = observer.next, error = observer.error, complete = observer.complete;
|
1061 | var activeCallbackCount = 0;
|
1062 | var completed = false;
|
1063 | var promiseQueue = {
|
1064 | then: function (callback) {
|
1065 | return new Promise(function (resolve) { return resolve(callback()); });
|
1066 | },
|
1067 | };
|
1068 | function makeCallback(examiner, delegate) {
|
1069 | if (examiner) {
|
1070 | return function (arg) {
|
1071 | ++activeCallbackCount;
|
1072 | var both = function () { return examiner(arg); };
|
1073 | promiseQueue = promiseQueue.then(both, both).then(function (result) {
|
1074 | --activeCallbackCount;
|
1075 | next && next.call(observer, result);
|
1076 | if (completed) {
|
1077 | handler.complete();
|
1078 | }
|
1079 | }, function (error) {
|
1080 | --activeCallbackCount;
|
1081 | throw error;
|
1082 | }).catch(function (caught) {
|
1083 | error && error.call(observer, caught);
|
1084 | });
|
1085 | };
|
1086 | }
|
1087 | else {
|
1088 | return function (arg) { return delegate && delegate.call(observer, arg); };
|
1089 | }
|
1090 | }
|
1091 | var handler = {
|
1092 | next: makeCallback(mapFn, next),
|
1093 | error: makeCallback(catchFn, error),
|
1094 | complete: function () {
|
1095 | completed = true;
|
1096 | if (!activeCallbackCount) {
|
1097 | complete && complete.call(observer);
|
1098 | }
|
1099 | },
|
1100 | };
|
1101 | var sub = observable.subscribe(handler);
|
1102 | return function () { return sub.unsubscribe(); };
|
1103 | });
|
1104 | }
|
1105 |
|
1106 | var canUseWeakMap = typeof WeakMap === 'function' &&
|
1107 | globals.maybe(function () { return navigator.product; }) !== 'ReactNative';
|
1108 | var canUseWeakSet = typeof WeakSet === 'function';
|
1109 | var canUseSymbol = typeof Symbol === 'function' &&
|
1110 | typeof Symbol.for === 'function';
|
1111 | var canUseAsyncIteratorSymbol = canUseSymbol && Symbol.asyncIterator;
|
1112 | var canUseDOM = typeof globals.maybe(function () { return window.document.createElement; }) === "function";
|
1113 | var usingJSDOM = globals.maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
|
1114 | var canUseLayoutEffect = canUseDOM && !usingJSDOM;
|
1115 |
|
1116 | function fixObservableSubclass(subclass) {
|
1117 | function set(key) {
|
1118 | Object.defineProperty(subclass, key, { value: zenObservableTs.Observable });
|
1119 | }
|
1120 | if (canUseSymbol && Symbol.species) {
|
1121 | set(Symbol.species);
|
1122 | }
|
1123 | set("@@species");
|
1124 | return subclass;
|
1125 | }
|
1126 |
|
1127 | function isPromiseLike(value) {
|
1128 | return value && typeof value.then === "function";
|
1129 | }
|
1130 | var Concast = (function (_super) {
|
1131 | tslib.__extends(Concast, _super);
|
1132 | function Concast(sources) {
|
1133 | var _this = _super.call(this, function (observer) {
|
1134 | _this.addObserver(observer);
|
1135 | return function () { return _this.removeObserver(observer); };
|
1136 | }) || this;
|
1137 | _this.observers = new Set();
|
1138 | _this.promise = new Promise(function (resolve, reject) {
|
1139 | _this.resolve = resolve;
|
1140 | _this.reject = reject;
|
1141 | });
|
1142 | _this.handlers = {
|
1143 | next: function (result) {
|
1144 | if (_this.sub !== null) {
|
1145 | _this.latest = ["next", result];
|
1146 | _this.notify("next", result);
|
1147 | iterateObserversSafely(_this.observers, "next", result);
|
1148 | }
|
1149 | },
|
1150 | error: function (error) {
|
1151 | var sub = _this.sub;
|
1152 | if (sub !== null) {
|
1153 | if (sub)
|
1154 | setTimeout(function () { return sub.unsubscribe(); });
|
1155 | _this.sub = null;
|
1156 | _this.latest = ["error", error];
|
1157 | _this.reject(error);
|
1158 | _this.notify("error", error);
|
1159 | iterateObserversSafely(_this.observers, "error", error);
|
1160 | }
|
1161 | },
|
1162 | complete: function () {
|
1163 | var _a = _this, sub = _a.sub, _b = _a.sources, sources = _b === void 0 ? [] : _b;
|
1164 | if (sub !== null) {
|
1165 | var value = sources.shift();
|
1166 | if (!value) {
|
1167 | if (sub)
|
1168 | setTimeout(function () { return sub.unsubscribe(); });
|
1169 | _this.sub = null;
|
1170 | if (_this.latest &&
|
1171 | _this.latest[0] === "next") {
|
1172 | _this.resolve(_this.latest[1]);
|
1173 | }
|
1174 | else {
|
1175 | _this.resolve();
|
1176 | }
|
1177 | _this.notify("complete");
|
1178 | iterateObserversSafely(_this.observers, "complete");
|
1179 | }
|
1180 | else if (isPromiseLike(value)) {
|
1181 | value.then(function (obs) { return _this.sub = obs.subscribe(_this.handlers); });
|
1182 | }
|
1183 | else {
|
1184 | _this.sub = value.subscribe(_this.handlers);
|
1185 | }
|
1186 | }
|
1187 | },
|
1188 | };
|
1189 | _this.nextResultListeners = new Set();
|
1190 | _this.cancel = function (reason) {
|
1191 | _this.reject(reason);
|
1192 | _this.sources = [];
|
1193 | _this.handlers.complete();
|
1194 | };
|
1195 | _this.promise.catch(function (_) { });
|
1196 | if (typeof sources === "function") {
|
1197 | sources = [new zenObservableTs.Observable(sources)];
|
1198 | }
|
1199 | if (isPromiseLike(sources)) {
|
1200 | sources.then(function (iterable) { return _this.start(iterable); }, _this.handlers.error);
|
1201 | }
|
1202 | else {
|
1203 | _this.start(sources);
|
1204 | }
|
1205 | return _this;
|
1206 | }
|
1207 | Concast.prototype.start = function (sources) {
|
1208 | if (this.sub !== void 0)
|
1209 | return;
|
1210 | this.sources = Array.from(sources);
|
1211 | this.handlers.complete();
|
1212 | };
|
1213 | Concast.prototype.deliverLastMessage = function (observer) {
|
1214 | if (this.latest) {
|
1215 | var nextOrError = this.latest[0];
|
1216 | var method = observer[nextOrError];
|
1217 | if (method) {
|
1218 | method.call(observer, this.latest[1]);
|
1219 | }
|
1220 | if (this.sub === null &&
|
1221 | nextOrError === "next" &&
|
1222 | observer.complete) {
|
1223 | observer.complete();
|
1224 | }
|
1225 | }
|
1226 | };
|
1227 | Concast.prototype.addObserver = function (observer) {
|
1228 | if (!this.observers.has(observer)) {
|
1229 | this.deliverLastMessage(observer);
|
1230 | this.observers.add(observer);
|
1231 | }
|
1232 | };
|
1233 | Concast.prototype.removeObserver = function (observer) {
|
1234 | if (this.observers.delete(observer) &&
|
1235 | this.observers.size < 1) {
|
1236 | this.handlers.complete();
|
1237 | }
|
1238 | };
|
1239 | Concast.prototype.notify = function (method, arg) {
|
1240 | var nextResultListeners = this.nextResultListeners;
|
1241 | if (nextResultListeners.size) {
|
1242 | this.nextResultListeners = new Set;
|
1243 | nextResultListeners.forEach(function (listener) { return listener(method, arg); });
|
1244 | }
|
1245 | };
|
1246 | Concast.prototype.beforeNext = function (callback) {
|
1247 | var called = false;
|
1248 | this.nextResultListeners.add(function (method, arg) {
|
1249 | if (!called) {
|
1250 | called = true;
|
1251 | callback(method, arg);
|
1252 | }
|
1253 | });
|
1254 | };
|
1255 | return Concast;
|
1256 | }(zenObservableTs.Observable));
|
1257 | fixObservableSubclass(Concast);
|
1258 |
|
1259 | function isExecutionPatchIncrementalResult(value) {
|
1260 | return "incremental" in value;
|
1261 | }
|
1262 |
|
1263 | function graphQLResultHasError(result) {
|
1264 | var errors = getGraphQLErrorsFromResult(result);
|
1265 | return isNonEmptyArray(errors);
|
1266 | }
|
1267 | function getGraphQLErrorsFromResult(result) {
|
1268 | var graphQLErrors = isNonEmptyArray(result.errors)
|
1269 | ? result.errors.slice(0)
|
1270 | : [];
|
1271 | if (isExecutionPatchIncrementalResult(result) &&
|
1272 | isNonEmptyArray(result.incremental)) {
|
1273 | result.incremental.forEach(function (incrementalResult) {
|
1274 | if (incrementalResult.errors) {
|
1275 | graphQLErrors.push.apply(graphQLErrors, incrementalResult.errors);
|
1276 | }
|
1277 | });
|
1278 | }
|
1279 | return graphQLErrors;
|
1280 | }
|
1281 |
|
1282 | function compact() {
|
1283 | var objects = [];
|
1284 | for (var _i = 0; _i < arguments.length; _i++) {
|
1285 | objects[_i] = arguments[_i];
|
1286 | }
|
1287 | var result = Object.create(null);
|
1288 | objects.forEach(function (obj) {
|
1289 | if (!obj)
|
1290 | return;
|
1291 | Object.keys(obj).forEach(function (key) {
|
1292 | var value = obj[key];
|
1293 | if (value !== void 0) {
|
1294 | result[key] = value;
|
1295 | }
|
1296 | });
|
1297 | });
|
1298 | return result;
|
1299 | }
|
1300 |
|
1301 | var prefixCounts = new Map();
|
1302 | function makeUniqueId(prefix) {
|
1303 | var count = prefixCounts.get(prefix) || 1;
|
1304 | prefixCounts.set(prefix, count + 1);
|
1305 | return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
|
1306 | }
|
1307 |
|
1308 | function stringifyForDisplay(value) {
|
1309 | var undefId = makeUniqueId("stringifyForDisplay");
|
1310 | return JSON.stringify(value, function (key, value) {
|
1311 | return value === void 0 ? undefId : value;
|
1312 | }).split(JSON.stringify(undefId)).join("<undefined>");
|
1313 | }
|
1314 |
|
1315 | function mergeOptions(defaults, options) {
|
1316 | return compact(defaults, options, options.variables && {
|
1317 | variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
|
1318 | });
|
1319 | }
|
1320 |
|
1321 | exports.DEV = globals.DEV;
|
1322 | exports.maybe = globals.maybe;
|
1323 | exports.Observable = zenObservableTs.Observable;
|
1324 | exports.Concast = Concast;
|
1325 | exports.DeepMerger = DeepMerger;
|
1326 | exports.addTypenameToDocument = addTypenameToDocument;
|
1327 | exports.argumentsObjectFromField = argumentsObjectFromField;
|
1328 | exports.asyncMap = asyncMap;
|
1329 | exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
|
1330 | exports.canUseAsyncIteratorSymbol = canUseAsyncIteratorSymbol;
|
1331 | exports.canUseDOM = canUseDOM;
|
1332 | exports.canUseLayoutEffect = canUseLayoutEffect;
|
1333 | exports.canUseSymbol = canUseSymbol;
|
1334 | exports.canUseWeakMap = canUseWeakMap;
|
1335 | exports.canUseWeakSet = canUseWeakSet;
|
1336 | exports.checkDocument = checkDocument;
|
1337 | exports.cloneDeep = cloneDeep;
|
1338 | exports.compact = compact;
|
1339 | exports.concatPagination = concatPagination;
|
1340 | exports.createFragmentMap = createFragmentMap;
|
1341 | exports.fixObservableSubclass = fixObservableSubclass;
|
1342 | exports.getDefaultValues = getDefaultValues;
|
1343 | exports.getDirectiveNames = getDirectiveNames;
|
1344 | exports.getFragmentDefinition = getFragmentDefinition;
|
1345 | exports.getFragmentDefinitions = getFragmentDefinitions;
|
1346 | exports.getFragmentFromSelection = getFragmentFromSelection;
|
1347 | exports.getFragmentQueryDocument = getFragmentQueryDocument;
|
1348 | exports.getGraphQLErrorsFromResult = getGraphQLErrorsFromResult;
|
1349 | exports.getInclusionDirectives = getInclusionDirectives;
|
1350 | exports.getMainDefinition = getMainDefinition;
|
1351 | exports.getOperationDefinition = getOperationDefinition;
|
1352 | exports.getOperationName = getOperationName;
|
1353 | exports.getQueryDefinition = getQueryDefinition;
|
1354 | exports.getStoreKeyName = getStoreKeyName;
|
1355 | exports.getTypenameFromResult = getTypenameFromResult;
|
1356 | exports.graphQLResultHasError = graphQLResultHasError;
|
1357 | exports.hasAllDirectives = hasAllDirectives;
|
1358 | exports.hasAnyDirectives = hasAnyDirectives;
|
1359 | exports.hasClientExports = hasClientExports;
|
1360 | exports.hasDirectives = hasDirectives;
|
1361 | exports.isArray = isArray;
|
1362 | exports.isDocumentNode = isDocumentNode;
|
1363 | exports.isField = isField;
|
1364 | exports.isInlineFragment = isInlineFragment;
|
1365 | exports.isNonEmptyArray = isNonEmptyArray;
|
1366 | exports.isNonNullObject = isNonNullObject;
|
1367 | exports.isReference = isReference;
|
1368 | exports.iterateObserversSafely = iterateObserversSafely;
|
1369 | exports.makeReference = makeReference;
|
1370 | exports.makeUniqueId = makeUniqueId;
|
1371 | exports.maybeDeepFreeze = maybeDeepFreeze;
|
1372 | exports.mergeDeep = mergeDeep;
|
1373 | exports.mergeDeepArray = mergeDeepArray;
|
1374 | exports.mergeOptions = mergeOptions;
|
1375 | exports.offsetLimitPagination = offsetLimitPagination;
|
1376 | exports.relayStylePagination = relayStylePagination;
|
1377 | exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
|
1378 | exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
|
1379 | exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
|
1380 | exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
|
1381 | exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
|
1382 | exports.resultKeyNameFromField = resultKeyNameFromField;
|
1383 | exports.shouldInclude = shouldInclude;
|
1384 | exports.storeKeyNameFromField = storeKeyNameFromField;
|
1385 | exports.stringifyForDisplay = stringifyForDisplay;
|
1386 | exports.valueToObjectRepresentation = valueToObjectRepresentation;
|
1387 |
|