@apollo/client 3.5.10 → 3.6.5

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