1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-utilities'), require('zen-observable'), require('graphql/language/printer'), require('symbol-observable'), require('optimism'), require('graphql-anywhere/lib/async'), require('graphql-tag')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', 'apollo-utilities', 'zen-observable', 'graphql/language/printer', 'symbol-observable', 'optimism', 'graphql-anywhere/lib/async', 'graphql-tag'], factory) :
|
4 | (global = global || self, factory((global.apollo = global.apollo || {}, global.apollo.boost = {}), global.apolloUtilities, global.zenObservable, global.print, global.$$observable, global.optimism, global.graphqlAnywhere.async, global.gql));
|
5 | }(this, function (exports, apolloUtilities, zenObservable, printer, $$observable, optimism, Async, graphqlTag) { 'use strict';
|
6 |
|
7 | zenObservable = zenObservable && zenObservable.hasOwnProperty('default') ? zenObservable['default'] : zenObservable;
|
8 | $$observable = $$observable && $$observable.hasOwnProperty('default') ? $$observable['default'] : $$observable;
|
9 | graphqlTag = graphqlTag && graphqlTag.hasOwnProperty('default') ? graphqlTag['default'] : graphqlTag;
|
10 |
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | var extendStatics = function(d, b) {
|
28 | extendStatics = Object.setPrototypeOf ||
|
29 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
30 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
31 | return extendStatics(d, b);
|
32 | };
|
33 |
|
34 | function __extends(d, b) {
|
35 | extendStatics(d, b);
|
36 | function __() { this.constructor = d; }
|
37 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
38 | }
|
39 |
|
40 | var __assign = function() {
|
41 | __assign = Object.assign || function __assign(t) {
|
42 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
43 | s = arguments[i];
|
44 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
45 | }
|
46 | return t;
|
47 | };
|
48 | return __assign.apply(this, arguments);
|
49 | };
|
50 |
|
51 | (function (NetworkStatus) {
|
52 | NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
|
53 | NetworkStatus[NetworkStatus["setVariables"] = 2] = "setVariables";
|
54 | NetworkStatus[NetworkStatus["fetchMore"] = 3] = "fetchMore";
|
55 | NetworkStatus[NetworkStatus["refetch"] = 4] = "refetch";
|
56 | NetworkStatus[NetworkStatus["poll"] = 6] = "poll";
|
57 | NetworkStatus[NetworkStatus["ready"] = 7] = "ready";
|
58 | NetworkStatus[NetworkStatus["error"] = 8] = "error";
|
59 | })(exports.NetworkStatus || (exports.NetworkStatus = {}));
|
60 | function isNetworkRequestInFlight(networkStatus) {
|
61 | return networkStatus < 7;
|
62 | }
|
63 |
|
64 |
|
65 | var Observable = zenObservable;
|
66 |
|
67 | var __extends$1 = (undefined && undefined.__extends) || (function () {
|
68 | var extendStatics = function (d, b) {
|
69 | extendStatics = Object.setPrototypeOf ||
|
70 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
71 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
72 | return extendStatics(d, b);
|
73 | };
|
74 | return function (d, b) {
|
75 | extendStatics(d, b);
|
76 | function __() { this.constructor = d; }
|
77 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
78 | };
|
79 | })();
|
80 | var __assign$1 = (undefined && undefined.__assign) || function () {
|
81 | __assign$1 = Object.assign || function(t) {
|
82 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
83 | s = arguments[i];
|
84 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
85 | t[p] = s[p];
|
86 | }
|
87 | return t;
|
88 | };
|
89 | return __assign$1.apply(this, arguments);
|
90 | };
|
91 | function validateOperation(operation) {
|
92 | var OPERATION_FIELDS = [
|
93 | 'query',
|
94 | 'operationName',
|
95 | 'variables',
|
96 | 'extensions',
|
97 | 'context',
|
98 | ];
|
99 | for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
|
100 | var key = _a[_i];
|
101 | if (OPERATION_FIELDS.indexOf(key) < 0) {
|
102 | throw new Error("illegal argument: " + key);
|
103 | }
|
104 | }
|
105 | return operation;
|
106 | }
|
107 | var LinkError = (function (_super) {
|
108 | __extends$1(LinkError, _super);
|
109 | function LinkError(message, link) {
|
110 | var _this = _super.call(this, message) || this;
|
111 | _this.link = link;
|
112 | return _this;
|
113 | }
|
114 | return LinkError;
|
115 | }(Error));
|
116 | function isTerminating(link) {
|
117 | return link.request.length <= 1;
|
118 | }
|
119 | function transformOperation(operation) {
|
120 | var transformedOperation = {
|
121 | variables: operation.variables || {},
|
122 | extensions: operation.extensions || {},
|
123 | operationName: operation.operationName,
|
124 | query: operation.query,
|
125 | };
|
126 |
|
127 | if (!transformedOperation.operationName) {
|
128 | transformedOperation.operationName =
|
129 | typeof transformedOperation.query !== 'string'
|
130 | ? apolloUtilities.getOperationName(transformedOperation.query)
|
131 | : '';
|
132 | }
|
133 | return transformedOperation;
|
134 | }
|
135 | function createOperation(starting, operation) {
|
136 | var context = __assign$1({}, starting);
|
137 | var setContext = function (next) {
|
138 | if (typeof next === 'function') {
|
139 | context = __assign$1({}, context, next(context));
|
140 | }
|
141 | else {
|
142 | context = __assign$1({}, context, next);
|
143 | }
|
144 | };
|
145 | var getContext = function () { return (__assign$1({}, context)); };
|
146 | Object.defineProperty(operation, 'setContext', {
|
147 | enumerable: false,
|
148 | value: setContext,
|
149 | });
|
150 | Object.defineProperty(operation, 'getContext', {
|
151 | enumerable: false,
|
152 | value: getContext,
|
153 | });
|
154 | Object.defineProperty(operation, 'toKey', {
|
155 | enumerable: false,
|
156 | value: function () { return getKey(operation); },
|
157 | });
|
158 | return operation;
|
159 | }
|
160 | function getKey(operation) {
|
161 |
|
162 |
|
163 | return printer.print(operation.query) + "|" + JSON.stringify(operation.variables) + "|" + operation.operationName;
|
164 | }
|
165 |
|
166 | var passthrough = function (op, forward) { return (forward ? forward(op) : Observable.of()); };
|
167 | var toLink = function (handler) {
|
168 | return typeof handler === 'function' ? new ApolloLink(handler) : handler;
|
169 | };
|
170 | var empty = function () {
|
171 | return new ApolloLink(function (op, forward) { return Observable.of(); });
|
172 | };
|
173 | var from = function (links) {
|
174 | if (links.length === 0)
|
175 | return empty();
|
176 | return links.map(toLink).reduce(function (x, y) { return x.concat(y); });
|
177 | };
|
178 | var split = function (test, left, right) {
|
179 | if (right === void 0) { right = new ApolloLink(passthrough); }
|
180 | var leftLink = toLink(left);
|
181 | var rightLink = toLink(right);
|
182 | if (isTerminating(leftLink) && isTerminating(rightLink)) {
|
183 | return new ApolloLink(function (operation) {
|
184 | return test(operation)
|
185 | ? leftLink.request(operation) || Observable.of()
|
186 | : rightLink.request(operation) || Observable.of();
|
187 | });
|
188 | }
|
189 | else {
|
190 | return new ApolloLink(function (operation, forward) {
|
191 | return test(operation)
|
192 | ? leftLink.request(operation, forward) || Observable.of()
|
193 | : rightLink.request(operation, forward) || Observable.of();
|
194 | });
|
195 | }
|
196 | };
|
197 |
|
198 | var concat = function (first, second) {
|
199 | var firstLink = toLink(first);
|
200 | if (isTerminating(firstLink)) {
|
201 | console.warn(new LinkError("You are calling concat on a terminating link, which will have no effect", firstLink));
|
202 | return firstLink;
|
203 | }
|
204 | var nextLink = toLink(second);
|
205 | if (isTerminating(nextLink)) {
|
206 | return new ApolloLink(function (operation) {
|
207 | return firstLink.request(operation, function (op) { return nextLink.request(op) || Observable.of(); }) || Observable.of();
|
208 | });
|
209 | }
|
210 | else {
|
211 | return new ApolloLink(function (operation, forward) {
|
212 | return (firstLink.request(operation, function (op) {
|
213 | return nextLink.request(op, forward) || Observable.of();
|
214 | }) || Observable.of());
|
215 | });
|
216 | }
|
217 | };
|
218 | var ApolloLink = (function () {
|
219 | function ApolloLink(request) {
|
220 | if (request)
|
221 | this.request = request;
|
222 | }
|
223 | ApolloLink.prototype.split = function (test, left, right) {
|
224 | if (right === void 0) { right = new ApolloLink(passthrough); }
|
225 | return this.concat(split(test, left, right));
|
226 | };
|
227 | ApolloLink.prototype.concat = function (next) {
|
228 | return concat(this, next);
|
229 | };
|
230 | ApolloLink.prototype.request = function (operation, forward) {
|
231 | throw new Error('request is not implemented');
|
232 | };
|
233 | ApolloLink.empty = empty;
|
234 | ApolloLink.from = from;
|
235 | ApolloLink.split = split;
|
236 | ApolloLink.execute = execute;
|
237 | return ApolloLink;
|
238 | }());
|
239 | function execute(link, operation) {
|
240 | return (link.request(createOperation(operation.context, transformOperation(validateOperation(operation)))) || Observable.of());
|
241 | }
|
242 |
|
243 | var Observable$1 = (function (_super) {
|
244 | __extends(Observable$$1, _super);
|
245 | function Observable$$1() {
|
246 | return _super !== null && _super.apply(this, arguments) || this;
|
247 | }
|
248 | Observable$$1.prototype[$$observable] = function () {
|
249 | return this;
|
250 | };
|
251 | Observable$$1.prototype['@@observable'] = function () {
|
252 | return this;
|
253 | };
|
254 | return Observable$$1;
|
255 | }(Observable));
|
256 |
|
257 | function isApolloError(err) {
|
258 | return err.hasOwnProperty('graphQLErrors');
|
259 | }
|
260 | var generateErrorMessage = function (err) {
|
261 | var message = '';
|
262 | if (Array.isArray(err.graphQLErrors) && err.graphQLErrors.length !== 0) {
|
263 | err.graphQLErrors.forEach(function (graphQLError) {
|
264 | var errorMessage = graphQLError
|
265 | ? graphQLError.message
|
266 | : 'Error message not found.';
|
267 | message += "GraphQL error: " + errorMessage + "\n";
|
268 | });
|
269 | }
|
270 | if (err.networkError) {
|
271 | message += 'Network error: ' + err.networkError.message + '\n';
|
272 | }
|
273 | message = message.replace(/\n$/, '');
|
274 | return message;
|
275 | };
|
276 | var ApolloError = (function (_super) {
|
277 | __extends(ApolloError, _super);
|
278 | function ApolloError(_a) {
|
279 | var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
|
280 | var _this = _super.call(this, errorMessage) || this;
|
281 | _this.graphQLErrors = graphQLErrors || [];
|
282 | _this.networkError = networkError || null;
|
283 | if (!errorMessage) {
|
284 | _this.message = generateErrorMessage(_this);
|
285 | }
|
286 | else {
|
287 | _this.message = errorMessage;
|
288 | }
|
289 | _this.extraInfo = extraInfo;
|
290 | _this.__proto__ = ApolloError.prototype;
|
291 | return _this;
|
292 | }
|
293 | return ApolloError;
|
294 | }(Error));
|
295 |
|
296 | (function (FetchType) {
|
297 | FetchType[FetchType["normal"] = 1] = "normal";
|
298 | FetchType[FetchType["refetch"] = 2] = "refetch";
|
299 | FetchType[FetchType["poll"] = 3] = "poll";
|
300 | })(exports.FetchType || (exports.FetchType = {}));
|
301 |
|
302 | var hasError = function (storeValue, policy) {
|
303 | if (policy === void 0) { policy = 'none'; }
|
304 | return storeValue &&
|
305 | ((storeValue.graphQLErrors &&
|
306 | storeValue.graphQLErrors.length > 0 &&
|
307 | policy === 'none') ||
|
308 | storeValue.networkError);
|
309 | };
|
310 | var ObservableQuery = (function (_super) {
|
311 | __extends(ObservableQuery, _super);
|
312 | function ObservableQuery(_a) {
|
313 | var queryManager = _a.queryManager, options = _a.options, _b = _a.shouldSubscribe, shouldSubscribe = _b === void 0 ? true : _b;
|
314 | var _this = _super.call(this, function (observer) {
|
315 | return _this.onSubscribe(observer);
|
316 | }) || this;
|
317 | _this.isTornDown = false;
|
318 | _this.options = options;
|
319 | _this.variables = options.variables || {};
|
320 | _this.queryId = queryManager.generateQueryId();
|
321 | _this.shouldSubscribe = shouldSubscribe;
|
322 | _this.queryManager = queryManager;
|
323 | _this.observers = [];
|
324 | _this.subscriptionHandles = [];
|
325 | return _this;
|
326 | }
|
327 | ObservableQuery.prototype.result = function () {
|
328 | var that = this;
|
329 | return new Promise(function (resolve, reject) {
|
330 | var subscription;
|
331 | var observer = {
|
332 | next: function (result) {
|
333 | resolve(result);
|
334 | if (!that.observers.some(function (obs) { return obs !== observer; })) {
|
335 | that.queryManager.removeQuery(that.queryId);
|
336 | }
|
337 | setTimeout(function () {
|
338 | subscription.unsubscribe();
|
339 | }, 0);
|
340 | },
|
341 | error: function (error) {
|
342 | reject(error);
|
343 | },
|
344 | };
|
345 | subscription = that.subscribe(observer);
|
346 | });
|
347 | };
|
348 | ObservableQuery.prototype.currentResult = function () {
|
349 | if (this.isTornDown) {
|
350 | return {
|
351 | data: this.lastError ? {} : this.lastResult ? this.lastResult.data : {},
|
352 | error: this.lastError,
|
353 | loading: false,
|
354 | networkStatus: exports.NetworkStatus.error,
|
355 | };
|
356 | }
|
357 | var queryStoreValue = this.queryManager.queryStore.get(this.queryId);
|
358 | if (hasError(queryStoreValue, this.options.errorPolicy)) {
|
359 | return {
|
360 | data: {},
|
361 | loading: false,
|
362 | networkStatus: queryStoreValue.networkStatus,
|
363 | error: new ApolloError({
|
364 | graphQLErrors: queryStoreValue.graphQLErrors,
|
365 | networkError: queryStoreValue.networkError,
|
366 | }),
|
367 | };
|
368 | }
|
369 | var _a = this.queryManager.getCurrentQueryResult(this), data = _a.data, partial = _a.partial;
|
370 | var queryLoading = !queryStoreValue ||
|
371 | queryStoreValue.networkStatus === exports.NetworkStatus.loading;
|
372 | var loading = (this.options.fetchPolicy === 'network-only' && queryLoading) ||
|
373 | (partial && this.options.fetchPolicy !== 'cache-only');
|
374 | var networkStatus;
|
375 | if (queryStoreValue) {
|
376 | networkStatus = queryStoreValue.networkStatus;
|
377 | }
|
378 | else {
|
379 | networkStatus = loading ? exports.NetworkStatus.loading : exports.NetworkStatus.ready;
|
380 | }
|
381 | var result = {
|
382 | data: data,
|
383 | loading: isNetworkRequestInFlight(networkStatus),
|
384 | networkStatus: networkStatus,
|
385 | };
|
386 | if (queryStoreValue &&
|
387 | queryStoreValue.graphQLErrors &&
|
388 | this.options.errorPolicy === 'all') {
|
389 | result.errors = queryStoreValue.graphQLErrors;
|
390 | }
|
391 | if (!partial) {
|
392 | this.lastResult = __assign({}, result, { stale: false });
|
393 | this.lastResultSnapshot = apolloUtilities.cloneDeep(this.lastResult);
|
394 | }
|
395 | return __assign({}, result, { partial: partial });
|
396 | };
|
397 | ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
|
398 | var snapshot = this.lastResultSnapshot;
|
399 | return !(snapshot &&
|
400 | newResult &&
|
401 | snapshot.networkStatus === newResult.networkStatus &&
|
402 | snapshot.stale === newResult.stale &&
|
403 | apolloUtilities.isEqual(snapshot.data, newResult.data));
|
404 | };
|
405 | ObservableQuery.prototype.getLastResult = function () {
|
406 | return this.lastResult;
|
407 | };
|
408 | ObservableQuery.prototype.getLastError = function () {
|
409 | return this.lastError;
|
410 | };
|
411 | ObservableQuery.prototype.resetLastResults = function () {
|
412 | delete this.lastResult;
|
413 | delete this.lastResultSnapshot;
|
414 | delete this.lastError;
|
415 | this.isTornDown = false;
|
416 | };
|
417 | ObservableQuery.prototype.refetch = function (variables) {
|
418 | var fetchPolicy = this.options.fetchPolicy;
|
419 | if (fetchPolicy === 'cache-only') {
|
420 | return Promise.reject(new Error('cache-only fetchPolicy option should not be used together with query refetch.'));
|
421 | }
|
422 | if (!apolloUtilities.isEqual(this.variables, variables)) {
|
423 | this.variables = Object.assign({}, this.variables, variables);
|
424 | }
|
425 | if (!apolloUtilities.isEqual(this.options.variables, this.variables)) {
|
426 | this.options.variables = Object.assign({}, this.options.variables, this.variables);
|
427 | }
|
428 | var isNetworkFetchPolicy = fetchPolicy === 'network-only' || fetchPolicy === 'no-cache';
|
429 | var combinedOptions = __assign({}, this.options, { fetchPolicy: isNetworkFetchPolicy ? fetchPolicy : 'network-only' });
|
430 | return this.queryManager
|
431 | .fetchQuery(this.queryId, combinedOptions, exports.FetchType.refetch)
|
432 | .then(function (result) { return result; });
|
433 | };
|
434 | ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
435 | var _this = this;
|
436 | if (!fetchMoreOptions.updateQuery) {
|
437 | throw new Error('updateQuery option is required. This function defines how to update the query data with the new results.');
|
438 | }
|
439 | var combinedOptions;
|
440 | return Promise.resolve()
|
441 | .then(function () {
|
442 | var qid = _this.queryManager.generateQueryId();
|
443 | if (fetchMoreOptions.query) {
|
444 | combinedOptions = fetchMoreOptions;
|
445 | }
|
446 | else {
|
447 | combinedOptions = __assign({}, _this.options, fetchMoreOptions, { variables: Object.assign({}, _this.variables, fetchMoreOptions.variables) });
|
448 | }
|
449 | combinedOptions.fetchPolicy = 'network-only';
|
450 | return _this.queryManager.fetchQuery(qid, combinedOptions, exports.FetchType.normal, _this.queryId);
|
451 | })
|
452 | .then(function (fetchMoreResult) {
|
453 | _this.updateQuery(function (previousResult) {
|
454 | return fetchMoreOptions.updateQuery(previousResult, {
|
455 | fetchMoreResult: fetchMoreResult.data,
|
456 | variables: combinedOptions.variables,
|
457 | });
|
458 | });
|
459 | return fetchMoreResult;
|
460 | });
|
461 | };
|
462 | ObservableQuery.prototype.subscribeToMore = function (options) {
|
463 | var _this = this;
|
464 | var subscription = this.queryManager
|
465 | .startGraphQLSubscription({
|
466 | query: options.document,
|
467 | variables: options.variables,
|
468 | })
|
469 | .subscribe({
|
470 | next: function (subscriptionData) {
|
471 | if (options.updateQuery) {
|
472 | _this.updateQuery(function (previous, _a) {
|
473 | var variables = _a.variables;
|
474 | return options.updateQuery(previous, {
|
475 | subscriptionData: subscriptionData,
|
476 | variables: variables,
|
477 | });
|
478 | });
|
479 | }
|
480 | },
|
481 | error: function (err) {
|
482 | if (options.onError) {
|
483 | options.onError(err);
|
484 | return;
|
485 | }
|
486 | console.error('Unhandled GraphQL subscription error', err);
|
487 | },
|
488 | });
|
489 | this.subscriptionHandles.push(subscription);
|
490 | return function () {
|
491 | var i = _this.subscriptionHandles.indexOf(subscription);
|
492 | if (i >= 0) {
|
493 | _this.subscriptionHandles.splice(i, 1);
|
494 | subscription.unsubscribe();
|
495 | }
|
496 | };
|
497 | };
|
498 | ObservableQuery.prototype.setOptions = function (opts) {
|
499 | var oldOptions = this.options;
|
500 | this.options = Object.assign({}, this.options, opts);
|
501 | if (opts.pollInterval) {
|
502 | this.startPolling(opts.pollInterval);
|
503 | }
|
504 | else if (opts.pollInterval === 0) {
|
505 | this.stopPolling();
|
506 | }
|
507 | var tryFetch = (oldOptions.fetchPolicy !== 'network-only' &&
|
508 | opts.fetchPolicy === 'network-only') ||
|
509 | (oldOptions.fetchPolicy === 'cache-only' &&
|
510 | opts.fetchPolicy !== 'cache-only') ||
|
511 | (oldOptions.fetchPolicy === 'standby' &&
|
512 | opts.fetchPolicy !== 'standby') ||
|
513 | false;
|
514 | return this.setVariables(this.options.variables, tryFetch, opts.fetchResults);
|
515 | };
|
516 | ObservableQuery.prototype.setVariables = function (variables, tryFetch, fetchResults) {
|
517 | if (tryFetch === void 0) { tryFetch = false; }
|
518 | if (fetchResults === void 0) { fetchResults = true; }
|
519 | this.isTornDown = false;
|
520 | var newVariables = variables ? variables : this.variables;
|
521 | if (apolloUtilities.isEqual(newVariables, this.variables) && !tryFetch) {
|
522 | if (this.observers.length === 0 || !fetchResults) {
|
523 | return new Promise(function (resolve) { return resolve(); });
|
524 | }
|
525 | return this.result();
|
526 | }
|
527 | else {
|
528 | this.variables = newVariables;
|
529 | this.options.variables = newVariables;
|
530 | if (this.observers.length === 0) {
|
531 | return new Promise(function (resolve) { return resolve(); });
|
532 | }
|
533 | return this.queryManager
|
534 | .fetchQuery(this.queryId, __assign({}, this.options, { variables: this.variables }))
|
535 | .then(function (result) { return result; });
|
536 | }
|
537 | };
|
538 | ObservableQuery.prototype.updateQuery = function (mapFn) {
|
539 | var _a = this.queryManager.getQueryWithPreviousResult(this.queryId), previousResult = _a.previousResult, variables = _a.variables, document = _a.document;
|
540 | var newResult = apolloUtilities.tryFunctionOrLogError(function () {
|
541 | return mapFn(previousResult, { variables: variables });
|
542 | });
|
543 | if (newResult) {
|
544 | this.queryManager.dataStore.markUpdateQueryResult(document, variables, newResult);
|
545 | this.queryManager.broadcastQueries();
|
546 | }
|
547 | };
|
548 | ObservableQuery.prototype.stopPolling = function () {
|
549 | this.queryManager.stopPollingQuery(this.queryId);
|
550 | this.options.pollInterval = undefined;
|
551 | };
|
552 | ObservableQuery.prototype.startPolling = function (pollInterval) {
|
553 | if (this.options.fetchPolicy === 'cache-first' ||
|
554 | this.options.fetchPolicy === 'cache-only') {
|
555 | throw new Error('Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries.');
|
556 | }
|
557 | this.options.pollInterval = pollInterval;
|
558 | this.queryManager.startPollingQuery(this.options, this.queryId);
|
559 | };
|
560 | ObservableQuery.prototype.onSubscribe = function (observer) {
|
561 | var _this = this;
|
562 | if (observer._subscription &&
|
563 | observer._subscription._observer &&
|
564 | !observer._subscription._observer.error) {
|
565 | observer._subscription._observer.error = function (error) {
|
566 | console.error('Unhandled error', error.message, error.stack);
|
567 | };
|
568 | }
|
569 | this.observers.push(observer);
|
570 | if (observer.next && this.lastResult)
|
571 | observer.next(this.lastResult);
|
572 | if (observer.error && this.lastError)
|
573 | observer.error(this.lastError);
|
574 | if (this.observers.length === 1)
|
575 | this.setUpQuery();
|
576 | return function () {
|
577 | _this.observers = _this.observers.filter(function (obs) { return obs !== observer; });
|
578 | if (_this.observers.length === 0) {
|
579 | _this.tearDownQuery();
|
580 | }
|
581 | };
|
582 | };
|
583 | ObservableQuery.prototype.setUpQuery = function () {
|
584 | var _this = this;
|
585 | if (this.shouldSubscribe) {
|
586 | this.queryManager.addObservableQuery(this.queryId, this);
|
587 | }
|
588 | if (!!this.options.pollInterval) {
|
589 | if (this.options.fetchPolicy === 'cache-first' ||
|
590 | this.options.fetchPolicy === 'cache-only') {
|
591 | throw new Error('Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries.');
|
592 | }
|
593 | this.queryManager.startPollingQuery(this.options, this.queryId);
|
594 | }
|
595 | var observer = {
|
596 | next: function (result) {
|
597 | _this.lastResult = result;
|
598 | _this.lastResultSnapshot = apolloUtilities.cloneDeep(result);
|
599 | _this.observers.forEach(function (obs) { return obs.next && obs.next(result); });
|
600 | },
|
601 | error: function (error) {
|
602 | _this.lastError = error;
|
603 | _this.observers.forEach(function (obs) { return obs.error && obs.error(error); });
|
604 | },
|
605 | };
|
606 | this.queryManager.startQuery(this.queryId, this.options, this.queryManager.queryListenerForObserver(this.queryId, this.options, observer));
|
607 | };
|
608 | ObservableQuery.prototype.tearDownQuery = function () {
|
609 | this.isTornDown = true;
|
610 | this.queryManager.stopPollingQuery(this.queryId);
|
611 | this.subscriptionHandles.forEach(function (sub) { return sub.unsubscribe(); });
|
612 | this.subscriptionHandles = [];
|
613 | this.queryManager.removeObservableQuery(this.queryId);
|
614 | this.queryManager.stopQuery(this.queryId);
|
615 | this.observers = [];
|
616 | };
|
617 | return ObservableQuery;
|
618 | }(Observable$1));
|
619 |
|
620 | var __extends$2 = (undefined && undefined.__extends) || (function () {
|
621 | var extendStatics = function (d, b) {
|
622 | extendStatics = Object.setPrototypeOf ||
|
623 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
624 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
625 | return extendStatics(d, b);
|
626 | };
|
627 | return function (d, b) {
|
628 | extendStatics(d, b);
|
629 | function __() { this.constructor = d; }
|
630 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
631 | };
|
632 | })();
|
633 | |
634 |
|
635 |
|
636 | var DedupLink = (function (_super) {
|
637 | __extends$2(DedupLink, _super);
|
638 | function DedupLink() {
|
639 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
640 | _this.inFlightRequestObservables = new Map();
|
641 | _this.subscribers = new Map();
|
642 | return _this;
|
643 | }
|
644 | DedupLink.prototype.request = function (operation, forward) {
|
645 | var _this = this;
|
646 |
|
647 | if (operation.getContext().forceFetch) {
|
648 | return forward(operation);
|
649 | }
|
650 | var key = operation.toKey();
|
651 | var cleanup = function (operationKey) {
|
652 | _this.inFlightRequestObservables.delete(operationKey);
|
653 | var prev = _this.subscribers.get(operationKey);
|
654 | return prev;
|
655 | };
|
656 | if (!this.inFlightRequestObservables.get(key)) {
|
657 |
|
658 |
|
659 | var singleObserver_1 = forward(operation);
|
660 | var subscription_1;
|
661 | var sharedObserver = new Observable(function (observer) {
|
662 |
|
663 |
|
664 | var prev = _this.subscribers.get(key);
|
665 | if (!prev)
|
666 | prev = { next: [], error: [], complete: [] };
|
667 | _this.subscribers.set(key, {
|
668 | next: prev.next.concat([observer.next.bind(observer)]),
|
669 | error: prev.error.concat([observer.error.bind(observer)]),
|
670 | complete: prev.complete.concat([observer.complete.bind(observer)]),
|
671 | });
|
672 | if (!subscription_1) {
|
673 | subscription_1 = singleObserver_1.subscribe({
|
674 | next: function (result) {
|
675 | var previous = cleanup(key);
|
676 | _this.subscribers.delete(key);
|
677 | if (previous) {
|
678 | previous.next.forEach(function (next) { return next(result); });
|
679 | previous.complete.forEach(function (complete) { return complete(); });
|
680 | }
|
681 | },
|
682 | error: function (error) {
|
683 | var previous = cleanup(key);
|
684 | _this.subscribers.delete(key);
|
685 | if (previous)
|
686 | previous.error.forEach(function (err) { return err(error); });
|
687 | },
|
688 | });
|
689 | }
|
690 | return function () {
|
691 | if (subscription_1)
|
692 | subscription_1.unsubscribe();
|
693 | _this.inFlightRequestObservables.delete(key);
|
694 | };
|
695 | });
|
696 | this.inFlightRequestObservables.set(key, sharedObserver);
|
697 | }
|
698 |
|
699 | return this.inFlightRequestObservables.get(key);
|
700 | };
|
701 | return DedupLink;
|
702 | }(ApolloLink));
|
703 |
|
704 | var MutationStore = (function () {
|
705 | function MutationStore() {
|
706 | this.store = {};
|
707 | }
|
708 | MutationStore.prototype.getStore = function () {
|
709 | return this.store;
|
710 | };
|
711 | MutationStore.prototype.get = function (mutationId) {
|
712 | return this.store[mutationId];
|
713 | };
|
714 | MutationStore.prototype.initMutation = function (mutationId, mutation, variables) {
|
715 | this.store[mutationId] = {
|
716 | mutation: mutation,
|
717 | variables: variables || {},
|
718 | loading: true,
|
719 | error: null,
|
720 | };
|
721 | };
|
722 | MutationStore.prototype.markMutationError = function (mutationId, error) {
|
723 | var mutation = this.store[mutationId];
|
724 | if (!mutation) {
|
725 | return;
|
726 | }
|
727 | mutation.loading = false;
|
728 | mutation.error = error;
|
729 | };
|
730 | MutationStore.prototype.markMutationResult = function (mutationId) {
|
731 | var mutation = this.store[mutationId];
|
732 | if (!mutation) {
|
733 | return;
|
734 | }
|
735 | mutation.loading = false;
|
736 | mutation.error = null;
|
737 | };
|
738 | MutationStore.prototype.reset = function () {
|
739 | this.store = {};
|
740 | };
|
741 | return MutationStore;
|
742 | }());
|
743 |
|
744 | var QueryStore = (function () {
|
745 | function QueryStore() {
|
746 | this.store = {};
|
747 | }
|
748 | QueryStore.prototype.getStore = function () {
|
749 | return this.store;
|
750 | };
|
751 | QueryStore.prototype.get = function (queryId) {
|
752 | return this.store[queryId];
|
753 | };
|
754 | QueryStore.prototype.initQuery = function (query) {
|
755 | var previousQuery = this.store[query.queryId];
|
756 | if (previousQuery &&
|
757 | previousQuery.document !== query.document &&
|
758 | !apolloUtilities.isEqual(previousQuery.document, query.document)) {
|
759 | throw new Error('Internal Error: may not update existing query string in store');
|
760 | }
|
761 | var isSetVariables = false;
|
762 | var previousVariables = null;
|
763 | if (query.storePreviousVariables &&
|
764 | previousQuery &&
|
765 | previousQuery.networkStatus !== exports.NetworkStatus.loading) {
|
766 | if (!apolloUtilities.isEqual(previousQuery.variables, query.variables)) {
|
767 | isSetVariables = true;
|
768 | previousVariables = previousQuery.variables;
|
769 | }
|
770 | }
|
771 | var networkStatus;
|
772 | if (isSetVariables) {
|
773 | networkStatus = exports.NetworkStatus.setVariables;
|
774 | }
|
775 | else if (query.isPoll) {
|
776 | networkStatus = exports.NetworkStatus.poll;
|
777 | }
|
778 | else if (query.isRefetch) {
|
779 | networkStatus = exports.NetworkStatus.refetch;
|
780 | }
|
781 | else {
|
782 | networkStatus = exports.NetworkStatus.loading;
|
783 | }
|
784 | var graphQLErrors = [];
|
785 | if (previousQuery && previousQuery.graphQLErrors) {
|
786 | graphQLErrors = previousQuery.graphQLErrors;
|
787 | }
|
788 | this.store[query.queryId] = {
|
789 | document: query.document,
|
790 | variables: query.variables,
|
791 | previousVariables: previousVariables,
|
792 | networkError: null,
|
793 | graphQLErrors: graphQLErrors,
|
794 | networkStatus: networkStatus,
|
795 | metadata: query.metadata,
|
796 | };
|
797 | if (typeof query.fetchMoreForQueryId === 'string' &&
|
798 | this.store[query.fetchMoreForQueryId]) {
|
799 | this.store[query.fetchMoreForQueryId].networkStatus =
|
800 | exports.NetworkStatus.fetchMore;
|
801 | }
|
802 | };
|
803 | QueryStore.prototype.markQueryResult = function (queryId, result, fetchMoreForQueryId) {
|
804 | if (!this.store || !this.store[queryId])
|
805 | return;
|
806 | this.store[queryId].networkError = null;
|
807 | this.store[queryId].graphQLErrors =
|
808 | result.errors && result.errors.length ? result.errors : [];
|
809 | this.store[queryId].previousVariables = null;
|
810 | this.store[queryId].networkStatus = exports.NetworkStatus.ready;
|
811 | if (typeof fetchMoreForQueryId === 'string' &&
|
812 | this.store[fetchMoreForQueryId]) {
|
813 | this.store[fetchMoreForQueryId].networkStatus = exports.NetworkStatus.ready;
|
814 | }
|
815 | };
|
816 | QueryStore.prototype.markQueryError = function (queryId, error, fetchMoreForQueryId) {
|
817 | if (!this.store || !this.store[queryId])
|
818 | return;
|
819 | this.store[queryId].networkError = error;
|
820 | this.store[queryId].networkStatus = exports.NetworkStatus.error;
|
821 | if (typeof fetchMoreForQueryId === 'string') {
|
822 | this.markQueryResultClient(fetchMoreForQueryId, true);
|
823 | }
|
824 | };
|
825 | QueryStore.prototype.markQueryResultClient = function (queryId, complete) {
|
826 | if (!this.store || !this.store[queryId])
|
827 | return;
|
828 | this.store[queryId].networkError = null;
|
829 | this.store[queryId].previousVariables = null;
|
830 | this.store[queryId].networkStatus = complete
|
831 | ? exports.NetworkStatus.ready
|
832 | : exports.NetworkStatus.loading;
|
833 | };
|
834 | QueryStore.prototype.stopQuery = function (queryId) {
|
835 | delete this.store[queryId];
|
836 | };
|
837 | QueryStore.prototype.reset = function (observableQueryIds) {
|
838 | var _this = this;
|
839 | this.store = Object.keys(this.store)
|
840 | .filter(function (queryId) {
|
841 | return observableQueryIds.indexOf(queryId) > -1;
|
842 | })
|
843 | .reduce(function (res, key) {
|
844 | res[key] = __assign({}, _this.store[key], { networkStatus: exports.NetworkStatus.loading });
|
845 | return res;
|
846 | }, {});
|
847 | };
|
848 | return QueryStore;
|
849 | }());
|
850 |
|
851 | var QueryManager = (function () {
|
852 | function QueryManager(_a) {
|
853 | var link = _a.link, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, store = _a.store, _c = _a.onBroadcast, onBroadcast = _c === void 0 ? function () { return undefined; } : _c, _d = _a.ssrMode, ssrMode = _d === void 0 ? false : _d, _e = _a.clientAwareness, clientAwareness = _e === void 0 ? {} : _e;
|
854 | this.mutationStore = new MutationStore();
|
855 | this.queryStore = new QueryStore();
|
856 | this.clientAwareness = {};
|
857 | this.idCounter = 1;
|
858 | this.queries = new Map();
|
859 | this.fetchQueryRejectFns = new Set();
|
860 | this.queryIdsByName = {};
|
861 | this.pollingInfoByQueryId = new Map();
|
862 | this.nextPoll = null;
|
863 | this.link = link;
|
864 | this.deduplicator = ApolloLink.from([new DedupLink(), link]);
|
865 | this.queryDeduplication = queryDeduplication;
|
866 | this.dataStore = store;
|
867 | this.onBroadcast = onBroadcast;
|
868 | this.clientAwareness = clientAwareness;
|
869 | this.ssrMode = ssrMode;
|
870 | }
|
871 | QueryManager.prototype.mutate = function (_a) {
|
872 | var _this = this;
|
873 | var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueriesByName = _a.updateQueries, _b = _a.refetchQueries, refetchQueries = _b === void 0 ? [] : _b, _c = _a.awaitRefetchQueries, awaitRefetchQueries = _c === void 0 ? false : _c, updateWithProxyFn = _a.update, _d = _a.errorPolicy, errorPolicy = _d === void 0 ? 'none' : _d, fetchPolicy = _a.fetchPolicy, _e = _a.context, context = _e === void 0 ? {} : _e;
|
874 | if (!mutation) {
|
875 | throw new Error('mutation option is required. You must specify your GraphQL document in the mutation option.');
|
876 | }
|
877 | if (fetchPolicy && fetchPolicy !== 'no-cache') {
|
878 | throw new Error("fetchPolicy for mutations currently only supports the 'no-cache' policy");
|
879 | }
|
880 | var mutationId = this.generateQueryId();
|
881 | var cache = this.dataStore.getCache();
|
882 | (mutation = cache.transformDocument(mutation)),
|
883 | (variables = apolloUtilities.assign({}, apolloUtilities.getDefaultValues(apolloUtilities.getMutationDefinition(mutation)), variables));
|
884 | this.setQuery(mutationId, function () { return ({ document: mutation }); });
|
885 | var generateUpdateQueriesInfo = function () {
|
886 | var ret = {};
|
887 | if (updateQueriesByName) {
|
888 | Object.keys(updateQueriesByName).forEach(function (queryName) {
|
889 | return (_this.queryIdsByName[queryName] || []).forEach(function (queryId) {
|
890 | ret[queryId] = {
|
891 | updater: updateQueriesByName[queryName],
|
892 | query: _this.queryStore.get(queryId),
|
893 | };
|
894 | });
|
895 | });
|
896 | }
|
897 | return ret;
|
898 | };
|
899 | this.mutationStore.initMutation(mutationId, mutation, variables);
|
900 | this.dataStore.markMutationInit({
|
901 | mutationId: mutationId,
|
902 | document: mutation,
|
903 | variables: variables || {},
|
904 | updateQueries: generateUpdateQueriesInfo(),
|
905 | update: updateWithProxyFn,
|
906 | optimisticResponse: optimisticResponse,
|
907 | });
|
908 | this.broadcastQueries();
|
909 | return new Promise(function (resolve, reject) {
|
910 | var storeResult;
|
911 | var error;
|
912 | var operation = _this.buildOperationForLink(mutation, variables, __assign({}, context, { optimisticResponse: optimisticResponse }));
|
913 | var completeMutation = function () {
|
914 | if (error) {
|
915 | _this.mutationStore.markMutationError(mutationId, error);
|
916 | }
|
917 | _this.dataStore.markMutationComplete({
|
918 | mutationId: mutationId,
|
919 | optimisticResponse: optimisticResponse,
|
920 | });
|
921 | _this.broadcastQueries();
|
922 | if (error) {
|
923 | return Promise.reject(error);
|
924 | }
|
925 | if (typeof refetchQueries === 'function') {
|
926 | refetchQueries = refetchQueries(storeResult);
|
927 | }
|
928 | var refetchQueryPromises = [];
|
929 | for (var _i = 0, refetchQueries_1 = refetchQueries; _i < refetchQueries_1.length; _i++) {
|
930 | var refetchQuery = refetchQueries_1[_i];
|
931 | if (typeof refetchQuery === 'string') {
|
932 | var promise = _this.refetchQueryByName(refetchQuery);
|
933 | if (promise) {
|
934 | refetchQueryPromises.push(promise);
|
935 | }
|
936 | continue;
|
937 | }
|
938 | var queryOptions = {
|
939 | query: refetchQuery.query,
|
940 | variables: refetchQuery.variables,
|
941 | fetchPolicy: 'network-only',
|
942 | };
|
943 | if (refetchQuery.context) {
|
944 | queryOptions.context = refetchQuery.context;
|
945 | }
|
946 | refetchQueryPromises.push(_this.query(queryOptions));
|
947 | }
|
948 | return Promise.all(awaitRefetchQueries ? refetchQueryPromises : []).then(function () {
|
949 | _this.setQuery(mutationId, function () { return ({ document: undefined }); });
|
950 | if (errorPolicy === 'ignore' &&
|
951 | storeResult &&
|
952 | apolloUtilities.graphQLResultHasError(storeResult)) {
|
953 | delete storeResult.errors;
|
954 | }
|
955 | return storeResult;
|
956 | });
|
957 | };
|
958 | execute(_this.link, operation).subscribe({
|
959 | next: function (result) {
|
960 | if (apolloUtilities.graphQLResultHasError(result) && errorPolicy === 'none') {
|
961 | error = new ApolloError({
|
962 | graphQLErrors: result.errors,
|
963 | });
|
964 | return;
|
965 | }
|
966 | _this.mutationStore.markMutationResult(mutationId);
|
967 | if (fetchPolicy !== 'no-cache') {
|
968 | _this.dataStore.markMutationResult({
|
969 | mutationId: mutationId,
|
970 | result: result,
|
971 | document: mutation,
|
972 | variables: variables || {},
|
973 | updateQueries: generateUpdateQueriesInfo(),
|
974 | update: updateWithProxyFn,
|
975 | });
|
976 | }
|
977 | storeResult = result;
|
978 | },
|
979 | error: function (err) {
|
980 | _this.mutationStore.markMutationError(mutationId, err);
|
981 | _this.dataStore.markMutationComplete({
|
982 | mutationId: mutationId,
|
983 | optimisticResponse: optimisticResponse,
|
984 | });
|
985 | _this.broadcastQueries();
|
986 | _this.setQuery(mutationId, function () { return ({ document: undefined }); });
|
987 | reject(new ApolloError({
|
988 | networkError: err,
|
989 | }));
|
990 | },
|
991 | complete: function () { return completeMutation().then(resolve, reject); },
|
992 | });
|
993 | });
|
994 | };
|
995 | QueryManager.prototype.fetchQuery = function (queryId, options, fetchType, fetchMoreForQueryId) {
|
996 | var _this = this;
|
997 | var _a = options.variables, variables = _a === void 0 ? {} : _a, _b = options.metadata, metadata = _b === void 0 ? null : _b, _c = options.fetchPolicy, fetchPolicy = _c === void 0 ? 'cache-first' : _c;
|
998 | var cache = this.dataStore.getCache();
|
999 | var query = cache.transformDocument(options.query);
|
1000 | var storeResult;
|
1001 | var needToFetch = fetchPolicy === 'network-only' || fetchPolicy === 'no-cache';
|
1002 | if (fetchType !== exports.FetchType.refetch &&
|
1003 | fetchPolicy !== 'network-only' &&
|
1004 | fetchPolicy !== 'no-cache') {
|
1005 | var _d = this.dataStore.getCache().diff({
|
1006 | query: query,
|
1007 | variables: variables,
|
1008 | returnPartialData: true,
|
1009 | optimistic: false,
|
1010 | }), complete = _d.complete, result = _d.result;
|
1011 | needToFetch = !complete || fetchPolicy === 'cache-and-network';
|
1012 | storeResult = result;
|
1013 | }
|
1014 | var shouldFetch = needToFetch && fetchPolicy !== 'cache-only' && fetchPolicy !== 'standby';
|
1015 | if (apolloUtilities.hasDirectives(['live'], query))
|
1016 | shouldFetch = true;
|
1017 | var requestId = this.generateRequestId();
|
1018 | var cancel = this.updateQueryWatch(queryId, query, options);
|
1019 | this.setQuery(queryId, function () { return ({
|
1020 | document: query,
|
1021 | lastRequestId: requestId,
|
1022 | invalidated: true,
|
1023 | cancel: cancel,
|
1024 | }); });
|
1025 | this.invalidate(true, fetchMoreForQueryId);
|
1026 | this.queryStore.initQuery({
|
1027 | queryId: queryId,
|
1028 | document: query,
|
1029 | storePreviousVariables: shouldFetch,
|
1030 | variables: variables,
|
1031 | isPoll: fetchType === exports.FetchType.poll,
|
1032 | isRefetch: fetchType === exports.FetchType.refetch,
|
1033 | metadata: metadata,
|
1034 | fetchMoreForQueryId: fetchMoreForQueryId,
|
1035 | });
|
1036 | this.broadcastQueries();
|
1037 | var shouldDispatchClientResult = !shouldFetch || fetchPolicy === 'cache-and-network';
|
1038 | if (shouldDispatchClientResult) {
|
1039 | this.queryStore.markQueryResultClient(queryId, !shouldFetch);
|
1040 | this.invalidate(true, queryId, fetchMoreForQueryId);
|
1041 | this.broadcastQueries();
|
1042 | }
|
1043 | if (shouldFetch) {
|
1044 | var networkResult = this.fetchRequest({
|
1045 | requestId: requestId,
|
1046 | queryId: queryId,
|
1047 | document: query,
|
1048 | options: options,
|
1049 | fetchMoreForQueryId: fetchMoreForQueryId,
|
1050 | }).catch(function (error) {
|
1051 | if (isApolloError(error)) {
|
1052 | throw error;
|
1053 | }
|
1054 | else {
|
1055 | var lastRequestId = _this.getQuery(queryId).lastRequestId;
|
1056 | if (requestId >= (lastRequestId || 1)) {
|
1057 | _this.queryStore.markQueryError(queryId, error, fetchMoreForQueryId);
|
1058 | _this.invalidate(true, queryId, fetchMoreForQueryId);
|
1059 | _this.broadcastQueries();
|
1060 | }
|
1061 | throw new ApolloError({ networkError: error });
|
1062 | }
|
1063 | });
|
1064 | if (fetchPolicy !== 'cache-and-network') {
|
1065 | return networkResult;
|
1066 | }
|
1067 | else {
|
1068 | networkResult.catch(function () { });
|
1069 | }
|
1070 | }
|
1071 | return Promise.resolve({ data: storeResult });
|
1072 | };
|
1073 | QueryManager.prototype.queryListenerForObserver = function (queryId, options, observer) {
|
1074 | var _this = this;
|
1075 | var previouslyHadError = false;
|
1076 | return function (queryStoreValue, newData) {
|
1077 | _this.invalidate(false, queryId);
|
1078 | if (!queryStoreValue)
|
1079 | return;
|
1080 | var observableQuery = _this.getQuery(queryId).observableQuery;
|
1081 | var fetchPolicy = observableQuery
|
1082 | ? observableQuery.options.fetchPolicy
|
1083 | : options.fetchPolicy;
|
1084 | if (fetchPolicy === 'standby')
|
1085 | return;
|
1086 | var errorPolicy = observableQuery
|
1087 | ? observableQuery.options.errorPolicy
|
1088 | : options.errorPolicy;
|
1089 | var lastResult = observableQuery
|
1090 | ? observableQuery.getLastResult()
|
1091 | : null;
|
1092 | var lastError = observableQuery ? observableQuery.getLastError() : null;
|
1093 | var shouldNotifyIfLoading = (!newData && queryStoreValue.previousVariables != null) ||
|
1094 | fetchPolicy === 'cache-only' ||
|
1095 | fetchPolicy === 'cache-and-network';
|
1096 | var networkStatusChanged = Boolean(lastResult &&
|
1097 | queryStoreValue.networkStatus !== lastResult.networkStatus);
|
1098 | var errorStatusChanged = errorPolicy &&
|
1099 | (lastError && lastError.graphQLErrors) !==
|
1100 | queryStoreValue.graphQLErrors &&
|
1101 | errorPolicy !== 'none';
|
1102 | if (!isNetworkRequestInFlight(queryStoreValue.networkStatus) ||
|
1103 | (networkStatusChanged && options.notifyOnNetworkStatusChange) ||
|
1104 | shouldNotifyIfLoading) {
|
1105 | if (((!errorPolicy || errorPolicy === 'none') &&
|
1106 | queryStoreValue.graphQLErrors &&
|
1107 | queryStoreValue.graphQLErrors.length > 0) ||
|
1108 | queryStoreValue.networkError) {
|
1109 | var apolloError_1 = new ApolloError({
|
1110 | graphQLErrors: queryStoreValue.graphQLErrors,
|
1111 | networkError: queryStoreValue.networkError,
|
1112 | });
|
1113 | previouslyHadError = true;
|
1114 | if (observer.error) {
|
1115 | try {
|
1116 | observer.error(apolloError_1);
|
1117 | }
|
1118 | catch (e) {
|
1119 | setTimeout(function () {
|
1120 | throw e;
|
1121 | }, 0);
|
1122 | }
|
1123 | }
|
1124 | else {
|
1125 | setTimeout(function () {
|
1126 | throw apolloError_1;
|
1127 | }, 0);
|
1128 | if (!apolloUtilities.isProduction()) {
|
1129 | console.info('An unhandled error was thrown because no error handler is registered ' +
|
1130 | 'for the query ' +
|
1131 | JSON.stringify(queryStoreValue.document));
|
1132 | }
|
1133 | }
|
1134 | return;
|
1135 | }
|
1136 | try {
|
1137 | var data = void 0;
|
1138 | var isMissing = void 0;
|
1139 | if (newData) {
|
1140 | if (fetchPolicy !== 'no-cache') {
|
1141 | _this.setQuery(queryId, function () { return ({ newData: null }); });
|
1142 | }
|
1143 | data = newData.result;
|
1144 | isMissing = !newData.complete || false;
|
1145 | }
|
1146 | else {
|
1147 | if (lastResult && lastResult.data && !errorStatusChanged) {
|
1148 | data = lastResult.data;
|
1149 | isMissing = false;
|
1150 | }
|
1151 | else {
|
1152 | var document_1 = _this.getQuery(queryId).document;
|
1153 | var readResult = _this.dataStore.getCache().diff({
|
1154 | query: document_1,
|
1155 | variables: queryStoreValue.previousVariables ||
|
1156 | queryStoreValue.variables,
|
1157 | optimistic: true,
|
1158 | });
|
1159 | data = readResult.result;
|
1160 | isMissing = !readResult.complete;
|
1161 | }
|
1162 | }
|
1163 | var resultFromStore = void 0;
|
1164 | if (isMissing && fetchPolicy !== 'cache-only') {
|
1165 | resultFromStore = {
|
1166 | data: lastResult && lastResult.data,
|
1167 | loading: isNetworkRequestInFlight(queryStoreValue.networkStatus),
|
1168 | networkStatus: queryStoreValue.networkStatus,
|
1169 | stale: true,
|
1170 | };
|
1171 | }
|
1172 | else {
|
1173 | resultFromStore = {
|
1174 | data: data,
|
1175 | loading: isNetworkRequestInFlight(queryStoreValue.networkStatus),
|
1176 | networkStatus: queryStoreValue.networkStatus,
|
1177 | stale: false,
|
1178 | };
|
1179 | }
|
1180 | if (errorPolicy === 'all' &&
|
1181 | queryStoreValue.graphQLErrors &&
|
1182 | queryStoreValue.graphQLErrors.length > 0) {
|
1183 | resultFromStore.errors = queryStoreValue.graphQLErrors;
|
1184 | }
|
1185 | if (observer.next) {
|
1186 | if (previouslyHadError ||
|
1187 | !observableQuery ||
|
1188 | observableQuery.isDifferentFromLastResult(resultFromStore)) {
|
1189 | try {
|
1190 | observer.next(resultFromStore);
|
1191 | }
|
1192 | catch (e) {
|
1193 | setTimeout(function () {
|
1194 | throw e;
|
1195 | }, 0);
|
1196 | }
|
1197 | }
|
1198 | }
|
1199 | previouslyHadError = false;
|
1200 | }
|
1201 | catch (error) {
|
1202 | previouslyHadError = true;
|
1203 | if (observer.error)
|
1204 | observer.error(new ApolloError({ networkError: error }));
|
1205 | return;
|
1206 | }
|
1207 | }
|
1208 | };
|
1209 | };
|
1210 | QueryManager.prototype.watchQuery = function (options, shouldSubscribe) {
|
1211 | if (shouldSubscribe === void 0) { shouldSubscribe = true; }
|
1212 | if (options.fetchPolicy === 'standby') {
|
1213 | throw new Error('client.watchQuery cannot be called with fetchPolicy set to "standby"');
|
1214 | }
|
1215 | var queryDefinition = apolloUtilities.getQueryDefinition(options.query);
|
1216 | if (queryDefinition.variableDefinitions &&
|
1217 | queryDefinition.variableDefinitions.length) {
|
1218 | var defaultValues = apolloUtilities.getDefaultValues(queryDefinition);
|
1219 | options.variables = apolloUtilities.assign({}, defaultValues, options.variables);
|
1220 | }
|
1221 | if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
|
1222 | options.notifyOnNetworkStatusChange = false;
|
1223 | }
|
1224 | var transformedOptions = __assign({}, options);
|
1225 | return new ObservableQuery({
|
1226 | queryManager: this,
|
1227 | options: transformedOptions,
|
1228 | shouldSubscribe: shouldSubscribe,
|
1229 | });
|
1230 | };
|
1231 | QueryManager.prototype.query = function (options) {
|
1232 | var _this = this;
|
1233 | if (!options.query) {
|
1234 | throw new Error('query option is required. You must specify your GraphQL document ' +
|
1235 | 'in the query option.');
|
1236 | }
|
1237 | if (options.query.kind !== 'Document') {
|
1238 | throw new Error('You must wrap the query string in a "gql" tag.');
|
1239 | }
|
1240 | if (options.returnPartialData) {
|
1241 | throw new Error('returnPartialData option only supported on watchQuery.');
|
1242 | }
|
1243 | if (options.pollInterval) {
|
1244 | throw new Error('pollInterval option only supported on watchQuery.');
|
1245 | }
|
1246 | return new Promise(function (resolve, reject) {
|
1247 | _this.fetchQueryRejectFns.add(reject);
|
1248 | _this.watchQuery(options, false)
|
1249 | .result()
|
1250 | .then(resolve, reject)
|
1251 | .then(function () { return _this.fetchQueryRejectFns.delete(reject); });
|
1252 | });
|
1253 | };
|
1254 | QueryManager.prototype.generateQueryId = function () {
|
1255 | var queryId = this.idCounter.toString();
|
1256 | this.idCounter++;
|
1257 | return queryId;
|
1258 | };
|
1259 | QueryManager.prototype.stopQueryInStore = function (queryId) {
|
1260 | this.queryStore.stopQuery(queryId);
|
1261 | this.invalidate(true, queryId);
|
1262 | this.broadcastQueries();
|
1263 | };
|
1264 | QueryManager.prototype.addQueryListener = function (queryId, listener) {
|
1265 | this.setQuery(queryId, function (_a) {
|
1266 | var _b = _a.listeners, listeners = _b === void 0 ? [] : _b;
|
1267 | return ({
|
1268 | listeners: listeners.concat([listener]),
|
1269 | invalidate: false,
|
1270 | });
|
1271 | });
|
1272 | };
|
1273 | QueryManager.prototype.updateQueryWatch = function (queryId, document, options) {
|
1274 | var _this = this;
|
1275 | var cancel = this.getQuery(queryId).cancel;
|
1276 | if (cancel)
|
1277 | cancel();
|
1278 | var previousResult = function () {
|
1279 | var previousResult = null;
|
1280 | var observableQuery = _this.getQuery(queryId).observableQuery;
|
1281 | if (observableQuery) {
|
1282 | var lastResult = observableQuery.getLastResult();
|
1283 | if (lastResult) {
|
1284 | previousResult = lastResult.data;
|
1285 | }
|
1286 | }
|
1287 | return previousResult;
|
1288 | };
|
1289 | return this.dataStore.getCache().watch({
|
1290 | query: document,
|
1291 | variables: options.variables,
|
1292 | optimistic: true,
|
1293 | previousResult: previousResult,
|
1294 | callback: function (newData) {
|
1295 | _this.setQuery(queryId, function () { return ({ invalidated: true, newData: newData }); });
|
1296 | },
|
1297 | });
|
1298 | };
|
1299 | QueryManager.prototype.addObservableQuery = function (queryId, observableQuery) {
|
1300 | this.setQuery(queryId, function () { return ({ observableQuery: observableQuery }); });
|
1301 | var queryDef = apolloUtilities.getQueryDefinition(observableQuery.options.query);
|
1302 | if (queryDef.name && queryDef.name.value) {
|
1303 | var queryName = queryDef.name.value;
|
1304 | this.queryIdsByName[queryName] = this.queryIdsByName[queryName] || [];
|
1305 | this.queryIdsByName[queryName].push(observableQuery.queryId);
|
1306 | }
|
1307 | };
|
1308 | QueryManager.prototype.removeObservableQuery = function (queryId) {
|
1309 | var _a = this.getQuery(queryId), observableQuery = _a.observableQuery, cancel = _a.cancel;
|
1310 | if (cancel)
|
1311 | cancel();
|
1312 | if (!observableQuery)
|
1313 | return;
|
1314 | var definition = apolloUtilities.getQueryDefinition(observableQuery.options.query);
|
1315 | var queryName = definition.name ? definition.name.value : null;
|
1316 | this.setQuery(queryId, function () { return ({ observableQuery: null }); });
|
1317 | if (queryName) {
|
1318 | this.queryIdsByName[queryName] = this.queryIdsByName[queryName].filter(function (val) {
|
1319 | return !(observableQuery.queryId === val);
|
1320 | });
|
1321 | }
|
1322 | };
|
1323 | QueryManager.prototype.clearStore = function () {
|
1324 | this.fetchQueryRejectFns.forEach(function (reject) {
|
1325 | reject(new Error('Store reset while query was in flight(not completed in link chain)'));
|
1326 | });
|
1327 | var resetIds = [];
|
1328 | this.queries.forEach(function (_a, queryId) {
|
1329 | var observableQuery = _a.observableQuery;
|
1330 | if (observableQuery)
|
1331 | resetIds.push(queryId);
|
1332 | });
|
1333 | this.queryStore.reset(resetIds);
|
1334 | this.mutationStore.reset();
|
1335 | var reset = this.dataStore.reset();
|
1336 | return reset;
|
1337 | };
|
1338 | QueryManager.prototype.resetStore = function () {
|
1339 | var _this = this;
|
1340 | return this.clearStore().then(function () {
|
1341 | return _this.reFetchObservableQueries();
|
1342 | });
|
1343 | };
|
1344 | QueryManager.prototype.reFetchObservableQueries = function (includeStandby) {
|
1345 | var observableQueryPromises = this.getObservableQueryPromises(includeStandby);
|
1346 | this.broadcastQueries();
|
1347 | return Promise.all(observableQueryPromises);
|
1348 | };
|
1349 | QueryManager.prototype.startQuery = function (queryId, options, listener) {
|
1350 | this.addQueryListener(queryId, listener);
|
1351 | this.fetchQuery(queryId, options)
|
1352 | .catch(function () { return undefined; });
|
1353 | return queryId;
|
1354 | };
|
1355 | QueryManager.prototype.startGraphQLSubscription = function (options) {
|
1356 | var _this = this;
|
1357 | var query = options.query;
|
1358 | var isCacheEnabled = !(options.fetchPolicy && options.fetchPolicy === 'no-cache');
|
1359 | var cache = this.dataStore.getCache();
|
1360 | var transformedDoc = cache.transformDocument(query);
|
1361 | var variables = apolloUtilities.assign({}, apolloUtilities.getDefaultValues(apolloUtilities.getOperationDefinition(query)), options.variables);
|
1362 | var sub;
|
1363 | var observers = [];
|
1364 | return new Observable$1(function (observer) {
|
1365 | observers.push(observer);
|
1366 | if (observers.length === 1) {
|
1367 | var handler = {
|
1368 | next: function (result) {
|
1369 | if (isCacheEnabled) {
|
1370 | _this.dataStore.markSubscriptionResult(result, transformedDoc, variables);
|
1371 | _this.broadcastQueries();
|
1372 | }
|
1373 | observers.forEach(function (obs) {
|
1374 | if (apolloUtilities.graphQLResultHasError(result) && obs.error) {
|
1375 | obs.error(new ApolloError({
|
1376 | graphQLErrors: result.errors,
|
1377 | }));
|
1378 | }
|
1379 | else if (obs.next) {
|
1380 | obs.next(result);
|
1381 | }
|
1382 | });
|
1383 | },
|
1384 | error: function (error) {
|
1385 | observers.forEach(function (obs) {
|
1386 | if (obs.error) {
|
1387 | obs.error(error);
|
1388 | }
|
1389 | });
|
1390 | },
|
1391 | complete: function () {
|
1392 | observers.forEach(function (obs) {
|
1393 | if (obs.complete) {
|
1394 | obs.complete();
|
1395 | }
|
1396 | });
|
1397 | }
|
1398 | };
|
1399 | var operation = _this.buildOperationForLink(transformedDoc, variables);
|
1400 | sub = execute(_this.link, operation).subscribe(handler);
|
1401 | }
|
1402 | return function () {
|
1403 | observers = observers.filter(function (obs) { return obs !== observer; });
|
1404 | if (observers.length === 0 && sub) {
|
1405 | sub.unsubscribe();
|
1406 | }
|
1407 | };
|
1408 | });
|
1409 | };
|
1410 | QueryManager.prototype.stopQuery = function (queryId) {
|
1411 | this.stopQueryInStore(queryId);
|
1412 | this.removeQuery(queryId);
|
1413 | };
|
1414 | QueryManager.prototype.removeQuery = function (queryId) {
|
1415 | var subscriptions = this.getQuery(queryId).subscriptions;
|
1416 | subscriptions.forEach(function (x) { return x.unsubscribe(); });
|
1417 | this.queries.delete(queryId);
|
1418 | };
|
1419 | QueryManager.prototype.getCurrentQueryResult = function (observableQuery, optimistic) {
|
1420 | if (optimistic === void 0) { optimistic = true; }
|
1421 | var _a = observableQuery.options, variables = _a.variables, query = _a.query;
|
1422 | var lastResult = observableQuery.getLastResult();
|
1423 | var newData = this.getQuery(observableQuery.queryId).newData;
|
1424 | if (newData && newData.complete) {
|
1425 | return { data: newData.result, partial: false };
|
1426 | }
|
1427 | else {
|
1428 | try {
|
1429 | var data = this.dataStore.getCache().read({
|
1430 | query: query,
|
1431 | variables: variables,
|
1432 | previousResult: lastResult ? lastResult.data : undefined,
|
1433 | optimistic: optimistic,
|
1434 | });
|
1435 | return { data: data, partial: false };
|
1436 | }
|
1437 | catch (e) {
|
1438 | return { data: {}, partial: true };
|
1439 | }
|
1440 | }
|
1441 | };
|
1442 | QueryManager.prototype.getQueryWithPreviousResult = function (queryIdOrObservable) {
|
1443 | var observableQuery;
|
1444 | if (typeof queryIdOrObservable === 'string') {
|
1445 | var foundObserveableQuery = this.getQuery(queryIdOrObservable).observableQuery;
|
1446 | if (!foundObserveableQuery) {
|
1447 | throw new Error("ObservableQuery with this id doesn't exist: " + queryIdOrObservable);
|
1448 | }
|
1449 | observableQuery = foundObserveableQuery;
|
1450 | }
|
1451 | else {
|
1452 | observableQuery = queryIdOrObservable;
|
1453 | }
|
1454 | var _a = observableQuery.options, variables = _a.variables, query = _a.query;
|
1455 | var data = this.getCurrentQueryResult(observableQuery, false).data;
|
1456 | return {
|
1457 | previousResult: data,
|
1458 | variables: variables,
|
1459 | document: query,
|
1460 | };
|
1461 | };
|
1462 | QueryManager.prototype.broadcastQueries = function () {
|
1463 | var _this = this;
|
1464 | this.onBroadcast();
|
1465 | this.queries.forEach(function (info, id) {
|
1466 | if (!info.invalidated || !info.listeners)
|
1467 | return;
|
1468 | info.listeners
|
1469 | .filter(function (x) { return !!x; })
|
1470 | .forEach(function (listener) {
|
1471 | listener(_this.queryStore.get(id), info.newData);
|
1472 | });
|
1473 | });
|
1474 | };
|
1475 | QueryManager.prototype.getObservableQueryPromises = function (includeStandby) {
|
1476 | var _this = this;
|
1477 | var observableQueryPromises = [];
|
1478 | this.queries.forEach(function (_a, queryId) {
|
1479 | var observableQuery = _a.observableQuery;
|
1480 | if (!observableQuery)
|
1481 | return;
|
1482 | var fetchPolicy = observableQuery.options.fetchPolicy;
|
1483 | observableQuery.resetLastResults();
|
1484 | if (fetchPolicy !== 'cache-only' &&
|
1485 | (includeStandby || fetchPolicy !== 'standby')) {
|
1486 | observableQueryPromises.push(observableQuery.refetch());
|
1487 | }
|
1488 | _this.setQuery(queryId, function () { return ({ newData: null }); });
|
1489 | _this.invalidate(true, queryId);
|
1490 | });
|
1491 | return observableQueryPromises;
|
1492 | };
|
1493 | QueryManager.prototype.fetchRequest = function (_a) {
|
1494 | var _this = this;
|
1495 | var requestId = _a.requestId, queryId = _a.queryId, document = _a.document, options = _a.options, fetchMoreForQueryId = _a.fetchMoreForQueryId;
|
1496 | var variables = options.variables, context = options.context, _b = options.errorPolicy, errorPolicy = _b === void 0 ? 'none' : _b, fetchPolicy = options.fetchPolicy;
|
1497 | var operation = this.buildOperationForLink(document, variables, __assign({}, context, { forceFetch: !this.queryDeduplication }));
|
1498 | var resultFromStore;
|
1499 | var errorsFromStore;
|
1500 | var rejectFetchPromise;
|
1501 | return new Promise(function (resolve, reject) {
|
1502 | _this.fetchQueryRejectFns.add(rejectFetchPromise = reject);
|
1503 | var subscription = execute(_this.deduplicator, operation).subscribe({
|
1504 | next: function (result) {
|
1505 | var lastRequestId = _this.getQuery(queryId).lastRequestId;
|
1506 | if (requestId >= (lastRequestId || 1)) {
|
1507 | if (fetchPolicy !== 'no-cache') {
|
1508 | try {
|
1509 | _this.dataStore.markQueryResult(result, document, variables, fetchMoreForQueryId, errorPolicy === 'ignore' || errorPolicy === 'all');
|
1510 | }
|
1511 | catch (e) {
|
1512 | reject(e);
|
1513 | return;
|
1514 | }
|
1515 | }
|
1516 | else {
|
1517 | _this.setQuery(queryId, function () { return ({
|
1518 | newData: { result: result.data, complete: true },
|
1519 | }); });
|
1520 | }
|
1521 | _this.queryStore.markQueryResult(queryId, result, fetchMoreForQueryId);
|
1522 | _this.invalidate(true, queryId, fetchMoreForQueryId);
|
1523 | _this.broadcastQueries();
|
1524 | }
|
1525 | if (result.errors && errorPolicy === 'none') {
|
1526 | reject(new ApolloError({
|
1527 | graphQLErrors: result.errors,
|
1528 | }));
|
1529 | return;
|
1530 | }
|
1531 | else if (errorPolicy === 'all') {
|
1532 | errorsFromStore = result.errors;
|
1533 | }
|
1534 | if (fetchMoreForQueryId || fetchPolicy === 'no-cache') {
|
1535 | resultFromStore = result.data;
|
1536 | }
|
1537 | else {
|
1538 | try {
|
1539 | resultFromStore = _this.dataStore.getCache().read({
|
1540 | variables: variables,
|
1541 | query: document,
|
1542 | optimistic: false,
|
1543 | });
|
1544 | }
|
1545 | catch (e) { }
|
1546 | }
|
1547 | },
|
1548 | error: function (error) {
|
1549 | _this.fetchQueryRejectFns.delete(reject);
|
1550 | _this.setQuery(queryId, function (_a) {
|
1551 | var subscriptions = _a.subscriptions;
|
1552 | return ({
|
1553 | subscriptions: subscriptions.filter(function (x) { return x !== subscription; }),
|
1554 | });
|
1555 | });
|
1556 | reject(error);
|
1557 | },
|
1558 | complete: function () {
|
1559 | _this.fetchQueryRejectFns.delete(reject);
|
1560 | _this.setQuery(queryId, function (_a) {
|
1561 | var subscriptions = _a.subscriptions;
|
1562 | return ({
|
1563 | subscriptions: subscriptions.filter(function (x) { return x !== subscription; }),
|
1564 | });
|
1565 | });
|
1566 | resolve({
|
1567 | data: resultFromStore,
|
1568 | errors: errorsFromStore,
|
1569 | loading: false,
|
1570 | networkStatus: exports.NetworkStatus.ready,
|
1571 | stale: false,
|
1572 | });
|
1573 | },
|
1574 | });
|
1575 | _this.setQuery(queryId, function (_a) {
|
1576 | var subscriptions = _a.subscriptions;
|
1577 | return ({
|
1578 | subscriptions: subscriptions.concat([subscription]),
|
1579 | });
|
1580 | });
|
1581 | }).catch(function (error) {
|
1582 | _this.fetchQueryRejectFns.delete(rejectFetchPromise);
|
1583 | throw error;
|
1584 | });
|
1585 | };
|
1586 | QueryManager.prototype.refetchQueryByName = function (queryName) {
|
1587 | var _this = this;
|
1588 | var refetchedQueries = this.queryIdsByName[queryName];
|
1589 | if (refetchedQueries === undefined)
|
1590 | return;
|
1591 | return Promise.all(refetchedQueries
|
1592 | .map(function (id) { return _this.getQuery(id).observableQuery; })
|
1593 | .filter(function (x) { return !!x; })
|
1594 | .map(function (x) { return x.refetch(); }));
|
1595 | };
|
1596 | QueryManager.prototype.generateRequestId = function () {
|
1597 | var requestId = this.idCounter;
|
1598 | this.idCounter++;
|
1599 | return requestId;
|
1600 | };
|
1601 | QueryManager.prototype.getQuery = function (queryId) {
|
1602 | return (this.queries.get(queryId) || {
|
1603 | listeners: [],
|
1604 | invalidated: false,
|
1605 | document: null,
|
1606 | newData: null,
|
1607 | lastRequestId: null,
|
1608 | observableQuery: null,
|
1609 | subscriptions: [],
|
1610 | });
|
1611 | };
|
1612 | QueryManager.prototype.setQuery = function (queryId, updater) {
|
1613 | var prev = this.getQuery(queryId);
|
1614 | var newInfo = __assign({}, prev, updater(prev));
|
1615 | this.queries.set(queryId, newInfo);
|
1616 | };
|
1617 | QueryManager.prototype.invalidate = function (invalidated, queryId, fetchMoreForQueryId) {
|
1618 | if (queryId)
|
1619 | this.setQuery(queryId, function () { return ({ invalidated: invalidated }); });
|
1620 | if (fetchMoreForQueryId) {
|
1621 | this.setQuery(fetchMoreForQueryId, function () { return ({ invalidated: invalidated }); });
|
1622 | }
|
1623 | };
|
1624 | QueryManager.prototype.buildOperationForLink = function (document, variables, extraContext) {
|
1625 | var cache = this.dataStore.getCache();
|
1626 | return {
|
1627 | query: cache.transformForLink
|
1628 | ? cache.transformForLink(document)
|
1629 | : document,
|
1630 | variables: variables,
|
1631 | operationName: apolloUtilities.getOperationName(document) || undefined,
|
1632 | context: __assign({}, extraContext, { cache: cache, getCacheKey: function (obj) {
|
1633 | if (cache.config) {
|
1634 | return cache.config.dataIdFromObject(obj);
|
1635 | }
|
1636 | else {
|
1637 | throw new Error('To use context.getCacheKey, you need to use a cache that has a configurable dataIdFromObject, like apollo-cache-inmemory.');
|
1638 | }
|
1639 | }, clientAwareness: this.clientAwareness }),
|
1640 | };
|
1641 | };
|
1642 | QueryManager.prototype.checkInFlight = function (queryId) {
|
1643 | var query = this.queryStore.get(queryId);
|
1644 | return (query &&
|
1645 | query.networkStatus !== exports.NetworkStatus.ready &&
|
1646 | query.networkStatus !== exports.NetworkStatus.error);
|
1647 | };
|
1648 | QueryManager.prototype.startPollingQuery = function (options, queryId, listener) {
|
1649 | var pollInterval = options.pollInterval;
|
1650 | if (!pollInterval) {
|
1651 | throw new Error('Attempted to start a polling query without a polling interval.');
|
1652 | }
|
1653 | if (!this.ssrMode) {
|
1654 | this.pollingInfoByQueryId.set(queryId, {
|
1655 | interval: pollInterval,
|
1656 | lastPollTimeMs: Date.now() - 10,
|
1657 | options: __assign({}, options, { fetchPolicy: 'network-only' }),
|
1658 | });
|
1659 | if (listener) {
|
1660 | this.addQueryListener(queryId, listener);
|
1661 | }
|
1662 | this.schedulePoll(pollInterval);
|
1663 | }
|
1664 | return queryId;
|
1665 | };
|
1666 | QueryManager.prototype.stopPollingQuery = function (queryId) {
|
1667 | this.pollingInfoByQueryId.delete(queryId);
|
1668 | };
|
1669 | QueryManager.prototype.schedulePoll = function (timeLimitMs) {
|
1670 | var _this = this;
|
1671 | var now = Date.now();
|
1672 | if (this.nextPoll) {
|
1673 | if (timeLimitMs < this.nextPoll.time - now) {
|
1674 | clearTimeout(this.nextPoll.timeout);
|
1675 | }
|
1676 | else {
|
1677 | return;
|
1678 | }
|
1679 | }
|
1680 | this.nextPoll = {
|
1681 | time: now + timeLimitMs,
|
1682 | timeout: setTimeout(function () {
|
1683 | _this.nextPoll = null;
|
1684 | var nextTimeLimitMs = Infinity;
|
1685 | _this.pollingInfoByQueryId.forEach(function (info, queryId) {
|
1686 | if (info.interval < nextTimeLimitMs) {
|
1687 | nextTimeLimitMs = info.interval;
|
1688 | }
|
1689 | if (!_this.checkInFlight(queryId)) {
|
1690 | if (Date.now() - info.lastPollTimeMs >= info.interval) {
|
1691 | var updateLastPollTime = function () {
|
1692 | info.lastPollTimeMs = Date.now();
|
1693 | };
|
1694 | _this.fetchQuery(queryId, info.options, exports.FetchType.poll).then(updateLastPollTime, updateLastPollTime);
|
1695 | }
|
1696 | }
|
1697 | });
|
1698 | if (isFinite(nextTimeLimitMs)) {
|
1699 | _this.schedulePoll(nextTimeLimitMs);
|
1700 | }
|
1701 | }, timeLimitMs),
|
1702 | };
|
1703 | };
|
1704 | return QueryManager;
|
1705 | }());
|
1706 |
|
1707 | var DataStore = (function () {
|
1708 | function DataStore(initialCache) {
|
1709 | this.cache = initialCache;
|
1710 | }
|
1711 | DataStore.prototype.getCache = function () {
|
1712 | return this.cache;
|
1713 | };
|
1714 | DataStore.prototype.markQueryResult = function (result, document, variables, fetchMoreForQueryId, ignoreErrors) {
|
1715 | if (ignoreErrors === void 0) { ignoreErrors = false; }
|
1716 | var writeWithErrors = !apolloUtilities.graphQLResultHasError(result);
|
1717 | if (ignoreErrors && apolloUtilities.graphQLResultHasError(result) && result.data) {
|
1718 | writeWithErrors = true;
|
1719 | }
|
1720 | if (!fetchMoreForQueryId && writeWithErrors) {
|
1721 | this.cache.write({
|
1722 | result: result.data,
|
1723 | dataId: 'ROOT_QUERY',
|
1724 | query: document,
|
1725 | variables: variables,
|
1726 | });
|
1727 | }
|
1728 | };
|
1729 | DataStore.prototype.markSubscriptionResult = function (result, document, variables) {
|
1730 | if (!apolloUtilities.graphQLResultHasError(result)) {
|
1731 | this.cache.write({
|
1732 | result: result.data,
|
1733 | dataId: 'ROOT_SUBSCRIPTION',
|
1734 | query: document,
|
1735 | variables: variables,
|
1736 | });
|
1737 | }
|
1738 | };
|
1739 | DataStore.prototype.markMutationInit = function (mutation) {
|
1740 | var _this = this;
|
1741 | if (mutation.optimisticResponse) {
|
1742 | var optimistic_1;
|
1743 | if (typeof mutation.optimisticResponse === 'function') {
|
1744 | optimistic_1 = mutation.optimisticResponse(mutation.variables);
|
1745 | }
|
1746 | else {
|
1747 | optimistic_1 = mutation.optimisticResponse;
|
1748 | }
|
1749 | var changeFn_1 = function () {
|
1750 | _this.markMutationResult({
|
1751 | mutationId: mutation.mutationId,
|
1752 | result: { data: optimistic_1 },
|
1753 | document: mutation.document,
|
1754 | variables: mutation.variables,
|
1755 | updateQueries: mutation.updateQueries,
|
1756 | update: mutation.update,
|
1757 | });
|
1758 | };
|
1759 | this.cache.recordOptimisticTransaction(function (c) {
|
1760 | var orig = _this.cache;
|
1761 | _this.cache = c;
|
1762 | try {
|
1763 | changeFn_1();
|
1764 | }
|
1765 | finally {
|
1766 | _this.cache = orig;
|
1767 | }
|
1768 | }, mutation.mutationId);
|
1769 | }
|
1770 | };
|
1771 | DataStore.prototype.markMutationResult = function (mutation) {
|
1772 | var _this = this;
|
1773 | if (!apolloUtilities.graphQLResultHasError(mutation.result)) {
|
1774 | var cacheWrites_1 = [];
|
1775 | cacheWrites_1.push({
|
1776 | result: mutation.result.data,
|
1777 | dataId: 'ROOT_MUTATION',
|
1778 | query: mutation.document,
|
1779 | variables: mutation.variables,
|
1780 | });
|
1781 | if (mutation.updateQueries) {
|
1782 | Object.keys(mutation.updateQueries)
|
1783 | .filter(function (id) { return mutation.updateQueries[id]; })
|
1784 | .forEach(function (queryId) {
|
1785 | var _a = mutation.updateQueries[queryId], query = _a.query, updater = _a.updater;
|
1786 | var _b = _this.cache.diff({
|
1787 | query: query.document,
|
1788 | variables: query.variables,
|
1789 | returnPartialData: true,
|
1790 | optimistic: false,
|
1791 | }), currentQueryResult = _b.result, complete = _b.complete;
|
1792 | if (!complete) {
|
1793 | return;
|
1794 | }
|
1795 | var nextQueryResult = apolloUtilities.tryFunctionOrLogError(function () {
|
1796 | return updater(currentQueryResult, {
|
1797 | mutationResult: mutation.result,
|
1798 | queryName: apolloUtilities.getOperationName(query.document) || undefined,
|
1799 | queryVariables: query.variables,
|
1800 | });
|
1801 | });
|
1802 | if (nextQueryResult) {
|
1803 | cacheWrites_1.push({
|
1804 | result: nextQueryResult,
|
1805 | dataId: 'ROOT_QUERY',
|
1806 | query: query.document,
|
1807 | variables: query.variables,
|
1808 | });
|
1809 | }
|
1810 | });
|
1811 | }
|
1812 | this.cache.performTransaction(function (c) {
|
1813 | cacheWrites_1.forEach(function (write) { return c.write(write); });
|
1814 | });
|
1815 | var update_1 = mutation.update;
|
1816 | if (update_1) {
|
1817 | this.cache.performTransaction(function (c) {
|
1818 | apolloUtilities.tryFunctionOrLogError(function () { return update_1(c, mutation.result); });
|
1819 | });
|
1820 | }
|
1821 | }
|
1822 | };
|
1823 | DataStore.prototype.markMutationComplete = function (_a) {
|
1824 | var mutationId = _a.mutationId, optimisticResponse = _a.optimisticResponse;
|
1825 | if (!optimisticResponse)
|
1826 | return;
|
1827 | this.cache.removeOptimistic(mutationId);
|
1828 | };
|
1829 | DataStore.prototype.markUpdateQueryResult = function (document, variables, newResult) {
|
1830 | this.cache.write({
|
1831 | result: newResult,
|
1832 | dataId: 'ROOT_QUERY',
|
1833 | variables: variables,
|
1834 | query: document,
|
1835 | });
|
1836 | };
|
1837 | DataStore.prototype.reset = function () {
|
1838 | return this.cache.reset();
|
1839 | };
|
1840 | return DataStore;
|
1841 | }());
|
1842 |
|
1843 | var version = 'local';
|
1844 |
|
1845 | var hasSuggestedDevtools = false;
|
1846 | var ApolloClient = (function () {
|
1847 | function ApolloClient(options) {
|
1848 | var _this = this;
|
1849 | this.defaultOptions = {};
|
1850 | this.resetStoreCallbacks = [];
|
1851 | this.clearStoreCallbacks = [];
|
1852 | this.clientAwareness = {};
|
1853 | var link = options.link, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, connectToDevTools = options.connectToDevTools, _c = options.queryDeduplication, queryDeduplication = _c === void 0 ? true : _c, defaultOptions = options.defaultOptions, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
|
1854 | if (!link || !cache) {
|
1855 | throw new Error("\n In order to initialize Apollo Client, you must specify link & cache properties on the config object.\n This is part of the required upgrade when migrating from Apollo Client 1.0 to Apollo Client 2.0.\n For more information, please visit:\n https://www.apollographql.com/docs/react/basics/setup.html\n to help you get started.\n ");
|
1856 | }
|
1857 | var supportedCache = new Map();
|
1858 | var supportedDirectives = new ApolloLink(function (operation, forward) {
|
1859 | var result = supportedCache.get(operation.query);
|
1860 | if (!result) {
|
1861 | result = apolloUtilities.removeConnectionDirectiveFromDocument(operation.query);
|
1862 | supportedCache.set(operation.query, result);
|
1863 | supportedCache.set(result, result);
|
1864 | }
|
1865 | operation.query = result;
|
1866 | return forward(operation);
|
1867 | });
|
1868 | this.link = supportedDirectives.concat(link);
|
1869 | this.cache = cache;
|
1870 | this.store = new DataStore(cache);
|
1871 | this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
|
1872 | this.queryDeduplication = queryDeduplication;
|
1873 | this.ssrMode = ssrMode;
|
1874 | this.defaultOptions = defaultOptions || {};
|
1875 | if (ssrForceFetchDelay) {
|
1876 | setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
|
1877 | }
|
1878 | this.watchQuery = this.watchQuery.bind(this);
|
1879 | this.query = this.query.bind(this);
|
1880 | this.mutate = this.mutate.bind(this);
|
1881 | this.resetStore = this.resetStore.bind(this);
|
1882 | this.reFetchObservableQueries = this.reFetchObservableQueries.bind(this);
|
1883 | var defaultConnectToDevTools = !apolloUtilities.isProduction() &&
|
1884 | typeof window !== 'undefined' &&
|
1885 | !window.__APOLLO_CLIENT__;
|
1886 | if (typeof connectToDevTools === 'undefined'
|
1887 | ? defaultConnectToDevTools
|
1888 | : connectToDevTools && typeof window !== 'undefined') {
|
1889 | window.__APOLLO_CLIENT__ = this;
|
1890 | }
|
1891 | if (!hasSuggestedDevtools && !apolloUtilities.isProduction()) {
|
1892 | hasSuggestedDevtools = true;
|
1893 | if (typeof window !== 'undefined' &&
|
1894 | window.document &&
|
1895 | window.top === window.self) {
|
1896 | if (typeof window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
|
1897 | if (window.navigator &&
|
1898 | window.navigator.userAgent &&
|
1899 | window.navigator.userAgent.indexOf('Chrome') > -1) {
|
1900 | console.debug('Download the Apollo DevTools ' +
|
1901 | 'for a better development experience: ' +
|
1902 | 'https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm');
|
1903 | }
|
1904 | }
|
1905 | }
|
1906 | }
|
1907 | this.version = version;
|
1908 | if (clientAwarenessName) {
|
1909 | this.clientAwareness.name = clientAwarenessName;
|
1910 | }
|
1911 | if (clientAwarenessVersion) {
|
1912 | this.clientAwareness.version = clientAwarenessVersion;
|
1913 | }
|
1914 | }
|
1915 | ApolloClient.prototype.watchQuery = function (options) {
|
1916 | if (this.defaultOptions.watchQuery) {
|
1917 | options = __assign({}, this.defaultOptions.watchQuery, options);
|
1918 | }
|
1919 | if (this.disableNetworkFetches &&
|
1920 | (options.fetchPolicy === 'network-only' ||
|
1921 | options.fetchPolicy === 'cache-and-network')) {
|
1922 | options = __assign({}, options, { fetchPolicy: 'cache-first' });
|
1923 | }
|
1924 | return this.initQueryManager().watchQuery(options);
|
1925 | };
|
1926 | ApolloClient.prototype.query = function (options) {
|
1927 | if (this.defaultOptions.query) {
|
1928 | options = __assign({}, this.defaultOptions.query, options);
|
1929 | }
|
1930 | if (options.fetchPolicy === 'cache-and-network') {
|
1931 | throw new Error('cache-and-network fetchPolicy can only be used with watchQuery');
|
1932 | }
|
1933 | if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
|
1934 | options = __assign({}, options, { fetchPolicy: 'cache-first' });
|
1935 | }
|
1936 | return this.initQueryManager().query(options);
|
1937 | };
|
1938 | ApolloClient.prototype.mutate = function (options) {
|
1939 | if (this.defaultOptions.mutate) {
|
1940 | options = __assign({}, this.defaultOptions.mutate, options);
|
1941 | }
|
1942 | return this.initQueryManager().mutate(options);
|
1943 | };
|
1944 | ApolloClient.prototype.subscribe = function (options) {
|
1945 | return this.initQueryManager().startGraphQLSubscription(options);
|
1946 | };
|
1947 | ApolloClient.prototype.readQuery = function (options, optimistic) {
|
1948 | if (optimistic === void 0) { optimistic = false; }
|
1949 | return this.initProxy().readQuery(options, optimistic);
|
1950 | };
|
1951 | ApolloClient.prototype.readFragment = function (options, optimistic) {
|
1952 | if (optimistic === void 0) { optimistic = false; }
|
1953 | return this.initProxy().readFragment(options, optimistic);
|
1954 | };
|
1955 | ApolloClient.prototype.writeQuery = function (options) {
|
1956 | var result = this.initProxy().writeQuery(options);
|
1957 | this.initQueryManager().broadcastQueries();
|
1958 | return result;
|
1959 | };
|
1960 | ApolloClient.prototype.writeFragment = function (options) {
|
1961 | var result = this.initProxy().writeFragment(options);
|
1962 | this.initQueryManager().broadcastQueries();
|
1963 | return result;
|
1964 | };
|
1965 | ApolloClient.prototype.writeData = function (options) {
|
1966 | var result = this.initProxy().writeData(options);
|
1967 | this.initQueryManager().broadcastQueries();
|
1968 | return result;
|
1969 | };
|
1970 | ApolloClient.prototype.__actionHookForDevTools = function (cb) {
|
1971 | this.devToolsHookCb = cb;
|
1972 | };
|
1973 | ApolloClient.prototype.__requestRaw = function (payload) {
|
1974 | return execute(this.link, payload);
|
1975 | };
|
1976 | ApolloClient.prototype.resetStore = function () {
|
1977 | var _this = this;
|
1978 | return Promise.resolve()
|
1979 | .then(function () {
|
1980 | return _this.queryManager
|
1981 | ? _this.queryManager.clearStore()
|
1982 | : Promise.resolve(null);
|
1983 | })
|
1984 | .then(function () { return Promise.all(_this.resetStoreCallbacks.map(function (fn) { return fn(); })); })
|
1985 | .then(function () {
|
1986 | return _this.queryManager && _this.queryManager.reFetchObservableQueries
|
1987 | ? _this.queryManager.reFetchObservableQueries()
|
1988 | : Promise.resolve(null);
|
1989 | });
|
1990 | };
|
1991 | ApolloClient.prototype.clearStore = function () {
|
1992 | var _this = this;
|
1993 | var queryManager = this.queryManager;
|
1994 | return Promise.resolve()
|
1995 | .then(function () { return Promise.all(_this.clearStoreCallbacks.map(function (fn) { return fn(); })); })
|
1996 | .then(function () {
|
1997 | return queryManager ? queryManager.clearStore() : Promise.resolve(null);
|
1998 | });
|
1999 | };
|
2000 | ApolloClient.prototype.onResetStore = function (cb) {
|
2001 | var _this = this;
|
2002 | this.resetStoreCallbacks.push(cb);
|
2003 | return function () {
|
2004 | _this.resetStoreCallbacks = _this.resetStoreCallbacks.filter(function (c) { return c !== cb; });
|
2005 | };
|
2006 | };
|
2007 | ApolloClient.prototype.onClearStore = function (cb) {
|
2008 | var _this = this;
|
2009 | this.clearStoreCallbacks.push(cb);
|
2010 | return function () {
|
2011 | _this.clearStoreCallbacks = _this.clearStoreCallbacks.filter(function (c) { return c !== cb; });
|
2012 | };
|
2013 | };
|
2014 | ApolloClient.prototype.reFetchObservableQueries = function (includeStandby) {
|
2015 | return this.queryManager
|
2016 | ? this.queryManager.reFetchObservableQueries(includeStandby)
|
2017 | : Promise.resolve(null);
|
2018 | };
|
2019 | ApolloClient.prototype.extract = function (optimistic) {
|
2020 | return this.initProxy().extract(optimistic);
|
2021 | };
|
2022 | ApolloClient.prototype.restore = function (serializedState) {
|
2023 | return this.initProxy().restore(serializedState);
|
2024 | };
|
2025 | ApolloClient.prototype.initQueryManager = function () {
|
2026 | var _this = this;
|
2027 | if (!this.queryManager) {
|
2028 | this.queryManager = new QueryManager({
|
2029 | link: this.link,
|
2030 | store: this.store,
|
2031 | queryDeduplication: this.queryDeduplication,
|
2032 | ssrMode: this.ssrMode,
|
2033 | clientAwareness: this.clientAwareness,
|
2034 | onBroadcast: function () {
|
2035 | if (_this.devToolsHookCb) {
|
2036 | _this.devToolsHookCb({
|
2037 | action: {},
|
2038 | state: {
|
2039 | queries: _this.queryManager
|
2040 | ? _this.queryManager.queryStore.getStore()
|
2041 | : {},
|
2042 | mutations: _this.queryManager
|
2043 | ? _this.queryManager.mutationStore.getStore()
|
2044 | : {},
|
2045 | },
|
2046 | dataWithOptimisticResults: _this.cache.extract(true),
|
2047 | });
|
2048 | }
|
2049 | },
|
2050 | });
|
2051 | }
|
2052 | return this.queryManager;
|
2053 | };
|
2054 | ApolloClient.prototype.initProxy = function () {
|
2055 | if (!this.proxy) {
|
2056 | this.initQueryManager();
|
2057 | this.proxy = this.cache;
|
2058 | }
|
2059 | return this.proxy;
|
2060 | };
|
2061 | return ApolloClient;
|
2062 | }());
|
2063 |
|
2064 |
|
2065 | var Observable$2 = zenObservable;
|
2066 |
|
2067 | var __extends$3 = (undefined && undefined.__extends) || (function () {
|
2068 | var extendStatics = function (d, b) {
|
2069 | extendStatics = Object.setPrototypeOf ||
|
2070 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
2071 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
2072 | return extendStatics(d, b);
|
2073 | };
|
2074 | return function (d, b) {
|
2075 | extendStatics(d, b);
|
2076 | function __() { this.constructor = d; }
|
2077 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
2078 | };
|
2079 | })();
|
2080 | var __assign$2 = (undefined && undefined.__assign) || function () {
|
2081 | __assign$2 = Object.assign || function(t) {
|
2082 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
2083 | s = arguments[i];
|
2084 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
2085 | t[p] = s[p];
|
2086 | }
|
2087 | return t;
|
2088 | };
|
2089 | return __assign$2.apply(this, arguments);
|
2090 | };
|
2091 | function validateOperation$1(operation) {
|
2092 | var OPERATION_FIELDS = [
|
2093 | 'query',
|
2094 | 'operationName',
|
2095 | 'variables',
|
2096 | 'extensions',
|
2097 | 'context',
|
2098 | ];
|
2099 | for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
|
2100 | var key = _a[_i];
|
2101 | if (OPERATION_FIELDS.indexOf(key) < 0) {
|
2102 | throw new Error("illegal argument: " + key);
|
2103 | }
|
2104 | }
|
2105 | return operation;
|
2106 | }
|
2107 | var LinkError$1 = (function (_super) {
|
2108 | __extends$3(LinkError, _super);
|
2109 | function LinkError(message, link) {
|
2110 | var _this = _super.call(this, message) || this;
|
2111 | _this.link = link;
|
2112 | return _this;
|
2113 | }
|
2114 | return LinkError;
|
2115 | }(Error));
|
2116 | function isTerminating$1(link) {
|
2117 | return link.request.length <= 1;
|
2118 | }
|
2119 | function toPromise$1(observable) {
|
2120 | var completed = false;
|
2121 | return new Promise(function (resolve, reject) {
|
2122 | observable.subscribe({
|
2123 | next: function (data) {
|
2124 | if (completed) {
|
2125 | console.warn("Promise Wrapper does not support multiple results from Observable");
|
2126 | }
|
2127 | else {
|
2128 | completed = true;
|
2129 | resolve(data);
|
2130 | }
|
2131 | },
|
2132 | error: reject,
|
2133 | });
|
2134 | });
|
2135 | }
|
2136 |
|
2137 | var makePromise$1 = toPromise$1;
|
2138 | function fromPromise$1(promise) {
|
2139 | return new Observable$2(function (observer) {
|
2140 | promise
|
2141 | .then(function (value) {
|
2142 | observer.next(value);
|
2143 | observer.complete();
|
2144 | })
|
2145 | .catch(observer.error.bind(observer));
|
2146 | });
|
2147 | }
|
2148 | function fromError$1(errorValue) {
|
2149 | return new Observable$2(function (observer) {
|
2150 | observer.error(errorValue);
|
2151 | });
|
2152 | }
|
2153 | function transformOperation$1(operation) {
|
2154 | var transformedOperation = {
|
2155 | variables: operation.variables || {},
|
2156 | extensions: operation.extensions || {},
|
2157 | operationName: operation.operationName,
|
2158 | query: operation.query,
|
2159 | };
|
2160 |
|
2161 | if (!transformedOperation.operationName) {
|
2162 | transformedOperation.operationName =
|
2163 | typeof transformedOperation.query !== 'string'
|
2164 | ? apolloUtilities.getOperationName(transformedOperation.query)
|
2165 | : '';
|
2166 | }
|
2167 | return transformedOperation;
|
2168 | }
|
2169 | function createOperation$1(starting, operation) {
|
2170 | var context = __assign$2({}, starting);
|
2171 | var setContext = function (next) {
|
2172 | if (typeof next === 'function') {
|
2173 | context = __assign$2({}, context, next(context));
|
2174 | }
|
2175 | else {
|
2176 | context = __assign$2({}, context, next);
|
2177 | }
|
2178 | };
|
2179 | var getContext = function () { return (__assign$2({}, context)); };
|
2180 | Object.defineProperty(operation, 'setContext', {
|
2181 | enumerable: false,
|
2182 | value: setContext,
|
2183 | });
|
2184 | Object.defineProperty(operation, 'getContext', {
|
2185 | enumerable: false,
|
2186 | value: getContext,
|
2187 | });
|
2188 | Object.defineProperty(operation, 'toKey', {
|
2189 | enumerable: false,
|
2190 | value: function () { return getKey$1(operation); },
|
2191 | });
|
2192 | return operation;
|
2193 | }
|
2194 | function getKey$1(operation) {
|
2195 |
|
2196 |
|
2197 | return printer.print(operation.query) + "|" + JSON.stringify(operation.variables) + "|" + operation.operationName;
|
2198 | }
|
2199 |
|
2200 | var passthrough$1 = function (op, forward) { return (forward ? forward(op) : Observable$2.of()); };
|
2201 | var toLink$1 = function (handler) {
|
2202 | return typeof handler === 'function' ? new ApolloLink$1(handler) : handler;
|
2203 | };
|
2204 | var empty$1 = function () {
|
2205 | return new ApolloLink$1(function (op, forward) { return Observable$2.of(); });
|
2206 | };
|
2207 | var from$1 = function (links) {
|
2208 | if (links.length === 0)
|
2209 | return empty$1();
|
2210 | return links.map(toLink$1).reduce(function (x, y) { return x.concat(y); });
|
2211 | };
|
2212 | var split$1 = function (test, left, right) {
|
2213 | if (right === void 0) { right = new ApolloLink$1(passthrough$1); }
|
2214 | var leftLink = toLink$1(left);
|
2215 | var rightLink = toLink$1(right);
|
2216 | if (isTerminating$1(leftLink) && isTerminating$1(rightLink)) {
|
2217 | return new ApolloLink$1(function (operation) {
|
2218 | return test(operation)
|
2219 | ? leftLink.request(operation) || Observable$2.of()
|
2220 | : rightLink.request(operation) || Observable$2.of();
|
2221 | });
|
2222 | }
|
2223 | else {
|
2224 | return new ApolloLink$1(function (operation, forward) {
|
2225 | return test(operation)
|
2226 | ? leftLink.request(operation, forward) || Observable$2.of()
|
2227 | : rightLink.request(operation, forward) || Observable$2.of();
|
2228 | });
|
2229 | }
|
2230 | };
|
2231 |
|
2232 | var concat$1 = function (first, second) {
|
2233 | var firstLink = toLink$1(first);
|
2234 | if (isTerminating$1(firstLink)) {
|
2235 | console.warn(new LinkError$1("You are calling concat on a terminating link, which will have no effect", firstLink));
|
2236 | return firstLink;
|
2237 | }
|
2238 | var nextLink = toLink$1(second);
|
2239 | if (isTerminating$1(nextLink)) {
|
2240 | return new ApolloLink$1(function (operation) {
|
2241 | return firstLink.request(operation, function (op) { return nextLink.request(op) || Observable$2.of(); }) || Observable$2.of();
|
2242 | });
|
2243 | }
|
2244 | else {
|
2245 | return new ApolloLink$1(function (operation, forward) {
|
2246 | return (firstLink.request(operation, function (op) {
|
2247 | return nextLink.request(op, forward) || Observable$2.of();
|
2248 | }) || Observable$2.of());
|
2249 | });
|
2250 | }
|
2251 | };
|
2252 | var ApolloLink$1 = (function () {
|
2253 | function ApolloLink(request) {
|
2254 | if (request)
|
2255 | this.request = request;
|
2256 | }
|
2257 | ApolloLink.prototype.split = function (test, left, right) {
|
2258 | if (right === void 0) { right = new ApolloLink(passthrough$1); }
|
2259 | return this.concat(split$1(test, left, right));
|
2260 | };
|
2261 | ApolloLink.prototype.concat = function (next) {
|
2262 | return concat$1(this, next);
|
2263 | };
|
2264 | ApolloLink.prototype.request = function (operation, forward) {
|
2265 | throw new Error('request is not implemented');
|
2266 | };
|
2267 | ApolloLink.empty = empty$1;
|
2268 | ApolloLink.from = from$1;
|
2269 | ApolloLink.split = split$1;
|
2270 | ApolloLink.execute = execute$1;
|
2271 | return ApolloLink;
|
2272 | }());
|
2273 | function execute$1(link, operation) {
|
2274 | return (link.request(createOperation$1(operation.context, transformOperation$1(validateOperation$1(operation)))) || Observable$2.of());
|
2275 | }
|
2276 |
|
2277 | var testMap = new Map();
|
2278 | if (testMap.set(1, 2) !== testMap) {
|
2279 | var set_1 = testMap.set;
|
2280 | Map.prototype.set = function () {
|
2281 | var args = [];
|
2282 | for (var _i = 0; _i < arguments.length; _i++) {
|
2283 | args[_i] = arguments[_i];
|
2284 | }
|
2285 | set_1.apply(this, args);
|
2286 | return this;
|
2287 | };
|
2288 | }
|
2289 | var testSet = new Set();
|
2290 | if (testSet.add(3) !== testSet) {
|
2291 | var add_1 = testSet.add;
|
2292 | Set.prototype.add = function () {
|
2293 | var args = [];
|
2294 | for (var _i = 0; _i < arguments.length; _i++) {
|
2295 | args[_i] = arguments[_i];
|
2296 | }
|
2297 | add_1.apply(this, args);
|
2298 | return this;
|
2299 | };
|
2300 | }
|
2301 | var frozen = {};
|
2302 | if (typeof Object.freeze === 'function') {
|
2303 | Object.freeze(frozen);
|
2304 | }
|
2305 | try {
|
2306 | testMap.set(frozen, frozen).delete(frozen);
|
2307 | }
|
2308 | catch (_a) {
|
2309 | var wrap = function (method) {
|
2310 | return method && (function (obj) {
|
2311 | try {
|
2312 | testMap.set(obj, obj).delete(obj);
|
2313 | }
|
2314 | finally {
|
2315 | return method.call(Object, obj);
|
2316 | }
|
2317 | });
|
2318 | };
|
2319 | Object.freeze = wrap(Object.freeze);
|
2320 | Object.seal = wrap(Object.seal);
|
2321 | Object.preventExtensions = wrap(Object.preventExtensions);
|
2322 | }
|
2323 |
|
2324 | function queryFromPojo(obj) {
|
2325 | var op = {
|
2326 | kind: 'OperationDefinition',
|
2327 | operation: 'query',
|
2328 | name: {
|
2329 | kind: 'Name',
|
2330 | value: 'GeneratedClientQuery',
|
2331 | },
|
2332 | selectionSet: selectionSetFromObj(obj),
|
2333 | };
|
2334 | var out = {
|
2335 | kind: 'Document',
|
2336 | definitions: [op],
|
2337 | };
|
2338 | return out;
|
2339 | }
|
2340 | function fragmentFromPojo(obj, typename) {
|
2341 | var frag = {
|
2342 | kind: 'FragmentDefinition',
|
2343 | typeCondition: {
|
2344 | kind: 'NamedType',
|
2345 | name: {
|
2346 | kind: 'Name',
|
2347 | value: typename || '__FakeType',
|
2348 | },
|
2349 | },
|
2350 | name: {
|
2351 | kind: 'Name',
|
2352 | value: 'GeneratedClientQuery',
|
2353 | },
|
2354 | selectionSet: selectionSetFromObj(obj),
|
2355 | };
|
2356 | var out = {
|
2357 | kind: 'Document',
|
2358 | definitions: [frag],
|
2359 | };
|
2360 | return out;
|
2361 | }
|
2362 | function selectionSetFromObj(obj) {
|
2363 | if (typeof obj === 'number' ||
|
2364 | typeof obj === 'boolean' ||
|
2365 | typeof obj === 'string' ||
|
2366 | typeof obj === 'undefined' ||
|
2367 | obj === null) {
|
2368 | return null;
|
2369 | }
|
2370 | if (Array.isArray(obj)) {
|
2371 | return selectionSetFromObj(obj[0]);
|
2372 | }
|
2373 | var selections = [];
|
2374 | Object.keys(obj).forEach(function (key) {
|
2375 | var nestedSelSet = selectionSetFromObj(obj[key]);
|
2376 | var field = {
|
2377 | kind: 'Field',
|
2378 | name: {
|
2379 | kind: 'Name',
|
2380 | value: key,
|
2381 | },
|
2382 | selectionSet: nestedSelSet || undefined,
|
2383 | };
|
2384 | selections.push(field);
|
2385 | });
|
2386 | var selectionSet = {
|
2387 | kind: 'SelectionSet',
|
2388 | selections: selections,
|
2389 | };
|
2390 | return selectionSet;
|
2391 | }
|
2392 | var justTypenameQuery = {
|
2393 | kind: 'Document',
|
2394 | definitions: [
|
2395 | {
|
2396 | kind: 'OperationDefinition',
|
2397 | operation: 'query',
|
2398 | name: null,
|
2399 | variableDefinitions: null,
|
2400 | directives: [],
|
2401 | selectionSet: {
|
2402 | kind: 'SelectionSet',
|
2403 | selections: [
|
2404 | {
|
2405 | kind: 'Field',
|
2406 | alias: null,
|
2407 | name: {
|
2408 | kind: 'Name',
|
2409 | value: '__typename',
|
2410 | },
|
2411 | arguments: [],
|
2412 | directives: [],
|
2413 | selectionSet: null,
|
2414 | },
|
2415 | ],
|
2416 | },
|
2417 | },
|
2418 | ],
|
2419 | };
|
2420 |
|
2421 | var ApolloCache = (function () {
|
2422 | function ApolloCache() {
|
2423 | }
|
2424 | ApolloCache.prototype.transformDocument = function (document) {
|
2425 | return document;
|
2426 | };
|
2427 | ApolloCache.prototype.transformForLink = function (document) {
|
2428 | return document;
|
2429 | };
|
2430 | ApolloCache.prototype.readQuery = function (options, optimistic) {
|
2431 | if (optimistic === void 0) { optimistic = false; }
|
2432 | return this.read({
|
2433 | query: options.query,
|
2434 | variables: options.variables,
|
2435 | optimistic: optimistic,
|
2436 | });
|
2437 | };
|
2438 | ApolloCache.prototype.readFragment = function (options, optimistic) {
|
2439 | if (optimistic === void 0) { optimistic = false; }
|
2440 | return this.read({
|
2441 | query: apolloUtilities.getFragmentQueryDocument(options.fragment, options.fragmentName),
|
2442 | variables: options.variables,
|
2443 | rootId: options.id,
|
2444 | optimistic: optimistic,
|
2445 | });
|
2446 | };
|
2447 | ApolloCache.prototype.writeQuery = function (options) {
|
2448 | this.write({
|
2449 | dataId: 'ROOT_QUERY',
|
2450 | result: options.data,
|
2451 | query: options.query,
|
2452 | variables: options.variables,
|
2453 | });
|
2454 | };
|
2455 | ApolloCache.prototype.writeFragment = function (options) {
|
2456 | this.write({
|
2457 | dataId: options.id,
|
2458 | result: options.data,
|
2459 | variables: options.variables,
|
2460 | query: apolloUtilities.getFragmentQueryDocument(options.fragment, options.fragmentName),
|
2461 | });
|
2462 | };
|
2463 | ApolloCache.prototype.writeData = function (_a) {
|
2464 | var id = _a.id, data = _a.data;
|
2465 | if (typeof id !== 'undefined') {
|
2466 | var typenameResult = null;
|
2467 | try {
|
2468 | typenameResult = this.read({
|
2469 | rootId: id,
|
2470 | optimistic: false,
|
2471 | query: justTypenameQuery,
|
2472 | });
|
2473 | }
|
2474 | catch (e) {
|
2475 | }
|
2476 | var __typename = (typenameResult && typenameResult.__typename) || '__ClientData';
|
2477 | var dataToWrite = Object.assign({ __typename: __typename }, data);
|
2478 | this.writeFragment({
|
2479 | id: id,
|
2480 | fragment: fragmentFromPojo(dataToWrite, __typename),
|
2481 | data: dataToWrite,
|
2482 | });
|
2483 | }
|
2484 | else {
|
2485 | this.writeQuery({ query: queryFromPojo(data), data: data });
|
2486 | }
|
2487 | };
|
2488 | return ApolloCache;
|
2489 | }());
|
2490 |
|
2491 | var haveWarned = false;
|
2492 | var HeuristicFragmentMatcher = (function () {
|
2493 | function HeuristicFragmentMatcher() {
|
2494 | }
|
2495 | HeuristicFragmentMatcher.prototype.ensureReady = function () {
|
2496 | return Promise.resolve();
|
2497 | };
|
2498 | HeuristicFragmentMatcher.prototype.canBypassInit = function () {
|
2499 | return true;
|
2500 | };
|
2501 | HeuristicFragmentMatcher.prototype.match = function (idValue, typeCondition, context) {
|
2502 | var obj = context.store.get(idValue.id);
|
2503 | if (!obj && idValue.id === 'ROOT_QUERY') {
|
2504 | return true;
|
2505 | }
|
2506 | if (!obj) {
|
2507 | return false;
|
2508 | }
|
2509 | if (!obj.__typename) {
|
2510 | if (!haveWarned) {
|
2511 | console.warn("You're using fragments in your queries, but either don't have the addTypename:\n true option set in Apollo Client, or you are trying to write a fragment to the store without the __typename.\n Please turn on the addTypename option and include __typename when writing fragments so that Apollo Client\n can accurately match fragments.");
|
2512 | console.warn('Could not find __typename on Fragment ', typeCondition, obj);
|
2513 | console.warn("DEPRECATION WARNING: using fragments without __typename is unsupported behavior " +
|
2514 | "and will be removed in future versions of Apollo client. You should fix this and set addTypename to true now.");
|
2515 | if (!apolloUtilities.isTest()) {
|
2516 | haveWarned = true;
|
2517 | }
|
2518 | }
|
2519 | return 'heuristic';
|
2520 | }
|
2521 | if (obj.__typename === typeCondition) {
|
2522 | return true;
|
2523 | }
|
2524 | apolloUtilities.warnOnceInDevelopment('You are using the simple (heuristic) fragment matcher, but your ' +
|
2525 | 'queries contain union or interface types. Apollo Client will not be ' +
|
2526 | 'able to accurately map fragments. To make this error go away, use ' +
|
2527 | 'the `IntrospectionFragmentMatcher` as described in the docs: ' +
|
2528 | 'https://www.apollographql.com/docs/react/advanced/fragments.html#fragment-matcher', 'error');
|
2529 | return 'heuristic';
|
2530 | };
|
2531 | return HeuristicFragmentMatcher;
|
2532 | }());
|
2533 | var IntrospectionFragmentMatcher = (function () {
|
2534 | function IntrospectionFragmentMatcher(options) {
|
2535 | if (options && options.introspectionQueryResultData) {
|
2536 | this.possibleTypesMap = this.parseIntrospectionResult(options.introspectionQueryResultData);
|
2537 | this.isReady = true;
|
2538 | }
|
2539 | else {
|
2540 | this.isReady = false;
|
2541 | }
|
2542 | this.match = this.match.bind(this);
|
2543 | }
|
2544 | IntrospectionFragmentMatcher.prototype.match = function (idValue, typeCondition, context) {
|
2545 | if (!this.isReady) {
|
2546 | throw new Error('FragmentMatcher.match() was called before FragmentMatcher.init()');
|
2547 | }
|
2548 | var obj = context.store.get(idValue.id);
|
2549 | if (!obj) {
|
2550 | return false;
|
2551 | }
|
2552 | if (!obj.__typename) {
|
2553 | throw new Error("Cannot match fragment because __typename property is missing: " + JSON.stringify(obj));
|
2554 | }
|
2555 | if (obj.__typename === typeCondition) {
|
2556 | return true;
|
2557 | }
|
2558 | var implementingTypes = this.possibleTypesMap[typeCondition];
|
2559 | if (implementingTypes && implementingTypes.indexOf(obj.__typename) > -1) {
|
2560 | return true;
|
2561 | }
|
2562 | return false;
|
2563 | };
|
2564 | IntrospectionFragmentMatcher.prototype.parseIntrospectionResult = function (introspectionResultData) {
|
2565 | var typeMap = {};
|
2566 | introspectionResultData.__schema.types.forEach(function (type) {
|
2567 | if (type.kind === 'UNION' || type.kind === 'INTERFACE') {
|
2568 | typeMap[type.name] = type.possibleTypes.map(function (implementingType) { return implementingType.name; });
|
2569 | }
|
2570 | });
|
2571 | return typeMap;
|
2572 | };
|
2573 | return IntrospectionFragmentMatcher;
|
2574 | }());
|
2575 |
|
2576 | var CacheKeyNode = (function () {
|
2577 | function CacheKeyNode() {
|
2578 | this.children = null;
|
2579 | this.key = null;
|
2580 | }
|
2581 | CacheKeyNode.prototype.lookup = function () {
|
2582 | var args = [];
|
2583 | for (var _i = 0; _i < arguments.length; _i++) {
|
2584 | args[_i] = arguments[_i];
|
2585 | }
|
2586 | return this.lookupArray(args);
|
2587 | };
|
2588 | CacheKeyNode.prototype.lookupArray = function (array) {
|
2589 | var node = this;
|
2590 | array.forEach(function (value) {
|
2591 | node = node.getOrCreate(value);
|
2592 | });
|
2593 | return node.key || (node.key = Object.create(null));
|
2594 | };
|
2595 | CacheKeyNode.prototype.getOrCreate = function (value) {
|
2596 | var map = this.children || (this.children = new Map());
|
2597 | var node = map.get(value);
|
2598 | if (!node) {
|
2599 | map.set(value, (node = new CacheKeyNode()));
|
2600 | }
|
2601 | return node;
|
2602 | };
|
2603 | return CacheKeyNode;
|
2604 | }());
|
2605 |
|
2606 | var hasOwn = Object.prototype.hasOwnProperty;
|
2607 | var DepTrackingCache = (function () {
|
2608 | function DepTrackingCache(data) {
|
2609 | if (data === void 0) { data = Object.create(null); }
|
2610 | var _this = this;
|
2611 | this.data = data;
|
2612 | this.depend = optimism.wrap(function (dataId) { return _this.data[dataId]; }, {
|
2613 | disposable: true,
|
2614 | makeCacheKey: function (dataId) {
|
2615 | return dataId;
|
2616 | }
|
2617 | });
|
2618 | }
|
2619 | DepTrackingCache.prototype.toObject = function () {
|
2620 | return this.data;
|
2621 | };
|
2622 | DepTrackingCache.prototype.get = function (dataId) {
|
2623 | this.depend(dataId);
|
2624 | return this.data[dataId];
|
2625 | };
|
2626 | DepTrackingCache.prototype.set = function (dataId, value) {
|
2627 | var oldValue = this.data[dataId];
|
2628 | if (value !== oldValue) {
|
2629 | this.data[dataId] = value;
|
2630 | this.depend.dirty(dataId);
|
2631 | }
|
2632 | };
|
2633 | DepTrackingCache.prototype.delete = function (dataId) {
|
2634 | if (hasOwn.call(this.data, dataId)) {
|
2635 | delete this.data[dataId];
|
2636 | this.depend.dirty(dataId);
|
2637 | }
|
2638 | };
|
2639 | DepTrackingCache.prototype.clear = function () {
|
2640 | this.replace(null);
|
2641 | };
|
2642 | DepTrackingCache.prototype.replace = function (newData) {
|
2643 | var _this = this;
|
2644 | if (newData) {
|
2645 | Object.keys(newData).forEach(function (dataId) {
|
2646 | _this.set(dataId, newData[dataId]);
|
2647 | });
|
2648 | Object.keys(this.data).forEach(function (dataId) {
|
2649 | if (!hasOwn.call(newData, dataId)) {
|
2650 | _this.delete(dataId);
|
2651 | }
|
2652 | });
|
2653 | }
|
2654 | else {
|
2655 | Object.keys(this.data).forEach(function (dataId) {
|
2656 | _this.delete(dataId);
|
2657 | });
|
2658 | }
|
2659 | };
|
2660 | return DepTrackingCache;
|
2661 | }());
|
2662 | function defaultNormalizedCacheFactory(seed) {
|
2663 | return new DepTrackingCache(seed);
|
2664 | }
|
2665 |
|
2666 | var StoreReader = (function () {
|
2667 | function StoreReader(cacheKeyRoot) {
|
2668 | if (cacheKeyRoot === void 0) { cacheKeyRoot = new CacheKeyNode; }
|
2669 | var _this = this;
|
2670 | this.cacheKeyRoot = cacheKeyRoot;
|
2671 | var reader = this;
|
2672 | var executeStoreQuery = reader.executeStoreQuery, executeSelectionSet = reader.executeSelectionSet;
|
2673 | this.executeStoreQuery = optimism.wrap(function (options) {
|
2674 | return executeStoreQuery.call(_this, options);
|
2675 | }, {
|
2676 | makeCacheKey: function (_a) {
|
2677 | var query = _a.query, rootValue = _a.rootValue, contextValue = _a.contextValue, variableValues = _a.variableValues, fragmentMatcher = _a.fragmentMatcher;
|
2678 | if (contextValue.store instanceof DepTrackingCache) {
|
2679 | return reader.cacheKeyRoot.lookup(query, contextValue.store, fragmentMatcher, JSON.stringify(variableValues), rootValue.id);
|
2680 | }
|
2681 | return;
|
2682 | }
|
2683 | });
|
2684 | this.executeSelectionSet = optimism.wrap(function (options) {
|
2685 | return executeSelectionSet.call(_this, options);
|
2686 | }, {
|
2687 | makeCacheKey: function (_a) {
|
2688 | var selectionSet = _a.selectionSet, rootValue = _a.rootValue, execContext = _a.execContext;
|
2689 | if (execContext.contextValue.store instanceof DepTrackingCache) {
|
2690 | return reader.cacheKeyRoot.lookup(selectionSet, execContext.contextValue.store, execContext.fragmentMatcher, JSON.stringify(execContext.variableValues), rootValue.id);
|
2691 | }
|
2692 | return;
|
2693 | }
|
2694 | });
|
2695 | }
|
2696 | StoreReader.prototype.readQueryFromStore = function (options) {
|
2697 | var optsPatch = { returnPartialData: false };
|
2698 | return this.diffQueryAgainstStore(__assign({}, options, optsPatch)).result;
|
2699 | };
|
2700 | StoreReader.prototype.diffQueryAgainstStore = function (_a) {
|
2701 | var store = _a.store, query = _a.query, variables = _a.variables, previousResult = _a.previousResult, _b = _a.returnPartialData, returnPartialData = _b === void 0 ? true : _b, _c = _a.rootId, rootId = _c === void 0 ? 'ROOT_QUERY' : _c, fragmentMatcherFunction = _a.fragmentMatcherFunction, config = _a.config;
|
2702 | var queryDefinition = apolloUtilities.getQueryDefinition(query);
|
2703 | variables = apolloUtilities.assign({}, apolloUtilities.getDefaultValues(queryDefinition), variables);
|
2704 | var context = {
|
2705 | store: store,
|
2706 | dataIdFromObject: (config && config.dataIdFromObject) || null,
|
2707 | cacheRedirects: (config && config.cacheRedirects) || {},
|
2708 | };
|
2709 | var execResult = this.executeStoreQuery({
|
2710 | query: query,
|
2711 | rootValue: {
|
2712 | type: 'id',
|
2713 | id: rootId,
|
2714 | generated: true,
|
2715 | typename: 'Query',
|
2716 | },
|
2717 | contextValue: context,
|
2718 | variableValues: variables,
|
2719 | fragmentMatcher: fragmentMatcherFunction,
|
2720 | });
|
2721 | var hasMissingFields = execResult.missing && execResult.missing.length > 0;
|
2722 | if (hasMissingFields && !returnPartialData) {
|
2723 | execResult.missing.forEach(function (info) {
|
2724 | if (info.tolerable)
|
2725 | return;
|
2726 | throw new Error("Can't find field " + info.fieldName + " on object " + JSON.stringify(info.object, null, 2) + ".");
|
2727 | });
|
2728 | }
|
2729 | if (previousResult) {
|
2730 | if (apolloUtilities.isEqual(previousResult, execResult.result)) {
|
2731 | execResult.result = previousResult;
|
2732 | }
|
2733 | }
|
2734 | return {
|
2735 | result: execResult.result,
|
2736 | complete: !hasMissingFields,
|
2737 | };
|
2738 | };
|
2739 | StoreReader.prototype.executeStoreQuery = function (_a) {
|
2740 | var query = _a.query, rootValue = _a.rootValue, contextValue = _a.contextValue, variableValues = _a.variableValues, _b = _a.fragmentMatcher, fragmentMatcher = _b === void 0 ? defaultFragmentMatcher : _b;
|
2741 | var mainDefinition = apolloUtilities.getMainDefinition(query);
|
2742 | var fragments = apolloUtilities.getFragmentDefinitions(query);
|
2743 | var fragmentMap = apolloUtilities.createFragmentMap(fragments);
|
2744 | var execContext = {
|
2745 | query: query,
|
2746 | fragmentMap: fragmentMap,
|
2747 | contextValue: contextValue,
|
2748 | variableValues: variableValues,
|
2749 | fragmentMatcher: fragmentMatcher,
|
2750 | };
|
2751 | return this.executeSelectionSet({
|
2752 | selectionSet: mainDefinition.selectionSet,
|
2753 | rootValue: rootValue,
|
2754 | execContext: execContext,
|
2755 | });
|
2756 | };
|
2757 | StoreReader.prototype.executeSelectionSet = function (_a) {
|
2758 | var _this = this;
|
2759 | var selectionSet = _a.selectionSet, rootValue = _a.rootValue, execContext = _a.execContext;
|
2760 | var fragmentMap = execContext.fragmentMap, contextValue = execContext.contextValue, variables = execContext.variableValues;
|
2761 | var finalResult = {
|
2762 | result: {},
|
2763 | };
|
2764 | var objectsToMerge = [];
|
2765 | var object = contextValue.store.get(rootValue.id);
|
2766 | var typename = (object && object.__typename) ||
|
2767 | (rootValue.id === 'ROOT_QUERY' && 'Query') ||
|
2768 | void 0;
|
2769 | function handleMissing(result) {
|
2770 | var _a;
|
2771 | if (result.missing) {
|
2772 | finalResult.missing = finalResult.missing || [];
|
2773 | (_a = finalResult.missing).push.apply(_a, result.missing);
|
2774 | }
|
2775 | return result.result;
|
2776 | }
|
2777 | selectionSet.selections.forEach(function (selection) {
|
2778 | var _a;
|
2779 | if (!apolloUtilities.shouldInclude(selection, variables)) {
|
2780 | return;
|
2781 | }
|
2782 | if (apolloUtilities.isField(selection)) {
|
2783 | var fieldResult = handleMissing(_this.executeField(object, typename, selection, execContext));
|
2784 | if (typeof fieldResult !== 'undefined') {
|
2785 | objectsToMerge.push((_a = {},
|
2786 | _a[apolloUtilities.resultKeyNameFromField(selection)] = fieldResult,
|
2787 | _a));
|
2788 | }
|
2789 | }
|
2790 | else {
|
2791 | var fragment = void 0;
|
2792 | if (apolloUtilities.isInlineFragment(selection)) {
|
2793 | fragment = selection;
|
2794 | }
|
2795 | else {
|
2796 | fragment = fragmentMap[selection.name.value];
|
2797 | if (!fragment) {
|
2798 | throw new Error("No fragment named " + selection.name.value);
|
2799 | }
|
2800 | }
|
2801 | var typeCondition = fragment.typeCondition.name.value;
|
2802 | var match = execContext.fragmentMatcher(rootValue, typeCondition, contextValue);
|
2803 | if (match) {
|
2804 | var fragmentExecResult = _this.executeSelectionSet({
|
2805 | selectionSet: fragment.selectionSet,
|
2806 | rootValue: rootValue,
|
2807 | execContext: execContext,
|
2808 | });
|
2809 | if (match === 'heuristic' && fragmentExecResult.missing) {
|
2810 | fragmentExecResult = __assign({}, fragmentExecResult, { missing: fragmentExecResult.missing.map(function (info) {
|
2811 | return __assign({}, info, { tolerable: true });
|
2812 | }) });
|
2813 | }
|
2814 | objectsToMerge.push(handleMissing(fragmentExecResult));
|
2815 | }
|
2816 | }
|
2817 | });
|
2818 | merge(finalResult.result, objectsToMerge);
|
2819 | return finalResult;
|
2820 | };
|
2821 | StoreReader.prototype.executeField = function (object, typename, field, execContext) {
|
2822 | var variables = execContext.variableValues, contextValue = execContext.contextValue;
|
2823 | var fieldName = field.name.value;
|
2824 | var args = apolloUtilities.argumentsObjectFromField(field, variables);
|
2825 | var info = {
|
2826 | resultKey: apolloUtilities.resultKeyNameFromField(field),
|
2827 | directives: apolloUtilities.getDirectiveInfoFromField(field, variables),
|
2828 | };
|
2829 | var readStoreResult = readStoreResolver(object, typename, fieldName, args, contextValue, info);
|
2830 | if (Array.isArray(readStoreResult.result)) {
|
2831 | return this.combineExecResults(readStoreResult, this.executeSubSelectedArray(field, readStoreResult.result, execContext));
|
2832 | }
|
2833 | if (!field.selectionSet) {
|
2834 | assertSelectionSetForIdValue(field, readStoreResult.result);
|
2835 | return readStoreResult;
|
2836 | }
|
2837 | if (readStoreResult.result == null) {
|
2838 | return readStoreResult;
|
2839 | }
|
2840 | return this.combineExecResults(readStoreResult, this.executeSelectionSet({
|
2841 | selectionSet: field.selectionSet,
|
2842 | rootValue: readStoreResult.result,
|
2843 | execContext: execContext,
|
2844 | }));
|
2845 | };
|
2846 | StoreReader.prototype.combineExecResults = function () {
|
2847 | var execResults = [];
|
2848 | for (var _i = 0; _i < arguments.length; _i++) {
|
2849 | execResults[_i] = arguments[_i];
|
2850 | }
|
2851 | var missing = null;
|
2852 | execResults.forEach(function (execResult) {
|
2853 | if (execResult.missing) {
|
2854 | missing = missing || [];
|
2855 | missing.push.apply(missing, execResult.missing);
|
2856 | }
|
2857 | });
|
2858 | return {
|
2859 | result: execResults.pop().result,
|
2860 | missing: missing,
|
2861 | };
|
2862 | };
|
2863 | StoreReader.prototype.executeSubSelectedArray = function (field, result, execContext) {
|
2864 | var _this = this;
|
2865 | var missing = null;
|
2866 | function handleMissing(childResult) {
|
2867 | if (childResult.missing) {
|
2868 | missing = missing || [];
|
2869 | missing.push.apply(missing, childResult.missing);
|
2870 | }
|
2871 | return childResult.result;
|
2872 | }
|
2873 | result = result.map(function (item) {
|
2874 | if (item === null) {
|
2875 | return null;
|
2876 | }
|
2877 | if (Array.isArray(item)) {
|
2878 | return handleMissing(_this.executeSubSelectedArray(field, item, execContext));
|
2879 | }
|
2880 | if (field.selectionSet) {
|
2881 | return handleMissing(_this.executeSelectionSet({
|
2882 | selectionSet: field.selectionSet,
|
2883 | rootValue: item,
|
2884 | execContext: execContext,
|
2885 | }));
|
2886 | }
|
2887 | assertSelectionSetForIdValue(field, item);
|
2888 | return item;
|
2889 | });
|
2890 | return { result: result, missing: missing };
|
2891 | };
|
2892 | return StoreReader;
|
2893 | }());
|
2894 | function assertSelectionSetForIdValue(field, value) {
|
2895 | if (!field.selectionSet && apolloUtilities.isIdValue(value)) {
|
2896 | throw new Error("Missing selection set for object of type " + value.typename + " returned for query field " + field.name.value);
|
2897 | }
|
2898 | }
|
2899 | function defaultFragmentMatcher() {
|
2900 | return true;
|
2901 | }
|
2902 | function assertIdValue(idValue) {
|
2903 | if (!apolloUtilities.isIdValue(idValue)) {
|
2904 | throw new Error("Encountered a sub-selection on the query, but the store doesn't have an object reference. This should never happen during normal use unless you have custom code that is directly manipulating the store; please file an issue.");
|
2905 | }
|
2906 | }
|
2907 | function readStoreResolver(object, typename, fieldName, args, context, _a) {
|
2908 | var resultKey = _a.resultKey, directives = _a.directives;
|
2909 | var storeKeyName = fieldName;
|
2910 | if (args || directives) {
|
2911 | storeKeyName = apolloUtilities.getStoreKeyName(storeKeyName, args, directives);
|
2912 | }
|
2913 | var fieldValue = void 0;
|
2914 | if (object) {
|
2915 | fieldValue = object[storeKeyName];
|
2916 | if (typeof fieldValue === 'undefined' &&
|
2917 | context.cacheRedirects &&
|
2918 | typeof typename === 'string') {
|
2919 | var type = context.cacheRedirects[typename];
|
2920 | if (type) {
|
2921 | var resolver = type[fieldName];
|
2922 | if (resolver) {
|
2923 | fieldValue = resolver(object, args, {
|
2924 | getCacheKey: function (storeObj) {
|
2925 | return apolloUtilities.toIdValue({
|
2926 | id: context.dataIdFromObject(storeObj),
|
2927 | typename: storeObj.__typename,
|
2928 | });
|
2929 | },
|
2930 | });
|
2931 | }
|
2932 | }
|
2933 | }
|
2934 | }
|
2935 | if (typeof fieldValue === 'undefined') {
|
2936 | return {
|
2937 | result: fieldValue,
|
2938 | missing: [{
|
2939 | object: object,
|
2940 | fieldName: storeKeyName,
|
2941 | tolerable: false,
|
2942 | }],
|
2943 | };
|
2944 | }
|
2945 | if (apolloUtilities.isJsonValue(fieldValue)) {
|
2946 | fieldValue = fieldValue.json;
|
2947 | }
|
2948 | return {
|
2949 | result: fieldValue,
|
2950 | };
|
2951 | }
|
2952 | var hasOwn$1 = Object.prototype.hasOwnProperty;
|
2953 | function merge(target, sources) {
|
2954 | var pastCopies = [];
|
2955 | sources.forEach(function (source) {
|
2956 | mergeHelper(target, source, pastCopies);
|
2957 | });
|
2958 | return target;
|
2959 | }
|
2960 | function mergeHelper(target, source, pastCopies) {
|
2961 | if (source !== null && typeof source === 'object') {
|
2962 | if (Object.isExtensible && !Object.isExtensible(target)) {
|
2963 | target = shallowCopyForMerge(target, pastCopies);
|
2964 | }
|
2965 | Object.keys(source).forEach(function (sourceKey) {
|
2966 | var sourceValue = source[sourceKey];
|
2967 | if (hasOwn$1.call(target, sourceKey)) {
|
2968 | var targetValue = target[sourceKey];
|
2969 | if (sourceValue !== targetValue) {
|
2970 | target[sourceKey] = mergeHelper(shallowCopyForMerge(targetValue, pastCopies), sourceValue, pastCopies);
|
2971 | }
|
2972 | }
|
2973 | else {
|
2974 | target[sourceKey] = sourceValue;
|
2975 | }
|
2976 | });
|
2977 | }
|
2978 | return target;
|
2979 | }
|
2980 | function shallowCopyForMerge(value, pastCopies) {
|
2981 | if (value !== null &&
|
2982 | typeof value === 'object' &&
|
2983 | pastCopies.indexOf(value) < 0) {
|
2984 | if (Array.isArray(value)) {
|
2985 | value = value.slice(0);
|
2986 | }
|
2987 | else {
|
2988 | value = __assign({}, value);
|
2989 | }
|
2990 | pastCopies.push(value);
|
2991 | }
|
2992 | return value;
|
2993 | }
|
2994 |
|
2995 | var ObjectCache = (function () {
|
2996 | function ObjectCache(data) {
|
2997 | if (data === void 0) { data = Object.create(null); }
|
2998 | this.data = data;
|
2999 | }
|
3000 | ObjectCache.prototype.toObject = function () {
|
3001 | return this.data;
|
3002 | };
|
3003 | ObjectCache.prototype.get = function (dataId) {
|
3004 | return this.data[dataId];
|
3005 | };
|
3006 | ObjectCache.prototype.set = function (dataId, value) {
|
3007 | this.data[dataId] = value;
|
3008 | };
|
3009 | ObjectCache.prototype.delete = function (dataId) {
|
3010 | this.data[dataId] = void 0;
|
3011 | };
|
3012 | ObjectCache.prototype.clear = function () {
|
3013 | this.data = Object.create(null);
|
3014 | };
|
3015 | ObjectCache.prototype.replace = function (newData) {
|
3016 | this.data = newData || Object.create(null);
|
3017 | };
|
3018 | return ObjectCache;
|
3019 | }());
|
3020 | function defaultNormalizedCacheFactory$1(seed) {
|
3021 | return new ObjectCache(seed);
|
3022 | }
|
3023 |
|
3024 | var WriteError = (function (_super) {
|
3025 | __extends(WriteError, _super);
|
3026 | function WriteError() {
|
3027 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
3028 | _this.type = 'WriteError';
|
3029 | return _this;
|
3030 | }
|
3031 | return WriteError;
|
3032 | }(Error));
|
3033 | function enhanceErrorWithDocument(error, document) {
|
3034 | var enhancedError = new WriteError("Error writing result to store for query:\n " + JSON.stringify(document));
|
3035 | enhancedError.message += '\n' + error.message;
|
3036 | enhancedError.stack = error.stack;
|
3037 | return enhancedError;
|
3038 | }
|
3039 | var StoreWriter = (function () {
|
3040 | function StoreWriter() {
|
3041 | }
|
3042 | StoreWriter.prototype.writeQueryToStore = function (_a) {
|
3043 | var query = _a.query, result = _a.result, _b = _a.store, store = _b === void 0 ? defaultNormalizedCacheFactory() : _b, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, fragmentMatcherFunction = _a.fragmentMatcherFunction;
|
3044 | return this.writeResultToStore({
|
3045 | dataId: 'ROOT_QUERY',
|
3046 | result: result,
|
3047 | document: query,
|
3048 | store: store,
|
3049 | variables: variables,
|
3050 | dataIdFromObject: dataIdFromObject,
|
3051 | fragmentMatcherFunction: fragmentMatcherFunction,
|
3052 | });
|
3053 | };
|
3054 | StoreWriter.prototype.writeResultToStore = function (_a) {
|
3055 | var dataId = _a.dataId, result = _a.result, document = _a.document, _b = _a.store, store = _b === void 0 ? defaultNormalizedCacheFactory() : _b, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, fragmentMatcherFunction = _a.fragmentMatcherFunction;
|
3056 | var operationDefinition = apolloUtilities.getOperationDefinition(document);
|
3057 | try {
|
3058 | return this.writeSelectionSetToStore({
|
3059 | result: result,
|
3060 | dataId: dataId,
|
3061 | selectionSet: operationDefinition.selectionSet,
|
3062 | context: {
|
3063 | store: store,
|
3064 | processedData: {},
|
3065 | variables: apolloUtilities.assign({}, apolloUtilities.getDefaultValues(operationDefinition), variables),
|
3066 | dataIdFromObject: dataIdFromObject,
|
3067 | fragmentMap: apolloUtilities.createFragmentMap(apolloUtilities.getFragmentDefinitions(document)),
|
3068 | fragmentMatcherFunction: fragmentMatcherFunction,
|
3069 | },
|
3070 | });
|
3071 | }
|
3072 | catch (e) {
|
3073 | throw enhanceErrorWithDocument(e, document);
|
3074 | }
|
3075 | };
|
3076 | StoreWriter.prototype.writeSelectionSetToStore = function (_a) {
|
3077 | var _this = this;
|
3078 | var result = _a.result, dataId = _a.dataId, selectionSet = _a.selectionSet, context = _a.context;
|
3079 | var variables = context.variables, store = context.store, fragmentMap = context.fragmentMap;
|
3080 | selectionSet.selections.forEach(function (selection) {
|
3081 | if (!apolloUtilities.shouldInclude(selection, variables)) {
|
3082 | return;
|
3083 | }
|
3084 | if (apolloUtilities.isField(selection)) {
|
3085 | var resultFieldKey = apolloUtilities.resultKeyNameFromField(selection);
|
3086 | var value = result[resultFieldKey];
|
3087 | if (typeof value !== 'undefined') {
|
3088 | _this.writeFieldToStore({
|
3089 | dataId: dataId,
|
3090 | value: value,
|
3091 | field: selection,
|
3092 | context: context,
|
3093 | });
|
3094 | }
|
3095 | else {
|
3096 | var isDefered = selection.directives &&
|
3097 | selection.directives.length &&
|
3098 | selection.directives.some(function (directive) { return directive.name && directive.name.value === 'defer'; });
|
3099 | if (!isDefered && context.fragmentMatcherFunction) {
|
3100 | if (!apolloUtilities.isProduction()) {
|
3101 | console.warn("Missing field " + resultFieldKey + " in " + JSON.stringify(result, null, 2).substring(0, 100));
|
3102 | }
|
3103 | }
|
3104 | }
|
3105 | }
|
3106 | else {
|
3107 | var fragment = void 0;
|
3108 | if (apolloUtilities.isInlineFragment(selection)) {
|
3109 | fragment = selection;
|
3110 | }
|
3111 | else {
|
3112 | fragment = (fragmentMap || {})[selection.name.value];
|
3113 | if (!fragment) {
|
3114 | throw new Error("No fragment named " + selection.name.value + ".");
|
3115 | }
|
3116 | }
|
3117 | var matches = true;
|
3118 | if (context.fragmentMatcherFunction && fragment.typeCondition) {
|
3119 | var idValue = apolloUtilities.toIdValue({ id: 'self', typename: undefined });
|
3120 | var fakeContext = {
|
3121 | store: new ObjectCache({ self: result }),
|
3122 | cacheRedirects: {},
|
3123 | };
|
3124 | var match = context.fragmentMatcherFunction(idValue, fragment.typeCondition.name.value, fakeContext);
|
3125 | if (!apolloUtilities.isProduction() && match === 'heuristic') {
|
3126 | console.error('WARNING: heuristic fragment matching going on!');
|
3127 | }
|
3128 | matches = !!match;
|
3129 | }
|
3130 | if (matches) {
|
3131 | _this.writeSelectionSetToStore({
|
3132 | result: result,
|
3133 | selectionSet: fragment.selectionSet,
|
3134 | dataId: dataId,
|
3135 | context: context,
|
3136 | });
|
3137 | }
|
3138 | }
|
3139 | });
|
3140 | return store;
|
3141 | };
|
3142 | StoreWriter.prototype.writeFieldToStore = function (_a) {
|
3143 | var field = _a.field, value = _a.value, dataId = _a.dataId, context = _a.context;
|
3144 | var _b;
|
3145 | var variables = context.variables, dataIdFromObject = context.dataIdFromObject, store = context.store;
|
3146 | var storeValue;
|
3147 | var storeObject;
|
3148 | var storeFieldName = apolloUtilities.storeKeyNameFromField(field, variables);
|
3149 | if (!field.selectionSet || value === null) {
|
3150 | storeValue =
|
3151 | value != null && typeof value === 'object'
|
3152 | ?
|
3153 | { type: 'json', json: value }
|
3154 | :
|
3155 | value;
|
3156 | }
|
3157 | else if (Array.isArray(value)) {
|
3158 | var generatedId = dataId + "." + storeFieldName;
|
3159 | storeValue = this.processArrayValue(value, generatedId, field.selectionSet, context);
|
3160 | }
|
3161 | else {
|
3162 | var valueDataId = dataId + "." + storeFieldName;
|
3163 | var generated = true;
|
3164 | if (!isGeneratedId(valueDataId)) {
|
3165 | valueDataId = '$' + valueDataId;
|
3166 | }
|
3167 | if (dataIdFromObject) {
|
3168 | var semanticId = dataIdFromObject(value);
|
3169 | if (semanticId && isGeneratedId(semanticId)) {
|
3170 | throw new Error('IDs returned by dataIdFromObject cannot begin with the "$" character.');
|
3171 | }
|
3172 | if (semanticId ||
|
3173 | (typeof semanticId === 'number' && semanticId === 0)) {
|
3174 | valueDataId = semanticId;
|
3175 | generated = false;
|
3176 | }
|
3177 | }
|
3178 | if (!isDataProcessed(valueDataId, field, context.processedData)) {
|
3179 | this.writeSelectionSetToStore({
|
3180 | dataId: valueDataId,
|
3181 | result: value,
|
3182 | selectionSet: field.selectionSet,
|
3183 | context: context,
|
3184 | });
|
3185 | }
|
3186 | var typename = value.__typename;
|
3187 | storeValue = apolloUtilities.toIdValue({ id: valueDataId, typename: typename }, generated);
|
3188 | storeObject = store.get(dataId);
|
3189 | var escapedId = storeObject && storeObject[storeFieldName];
|
3190 | if (escapedId !== storeValue && apolloUtilities.isIdValue(escapedId)) {
|
3191 | var hadTypename = escapedId.typename !== undefined;
|
3192 | var hasTypename = typename !== undefined;
|
3193 | var typenameChanged = hadTypename && hasTypename && escapedId.typename !== typename;
|
3194 | if (generated && !escapedId.generated && !typenameChanged) {
|
3195 | throw new Error("Store error: the application attempted to write an object with no provided id" +
|
3196 | (" but the store already contains an id of " + escapedId.id + " for this object. The selectionSet") +
|
3197 | " that was trying to be written is:\n" +
|
3198 | JSON.stringify(field));
|
3199 | }
|
3200 | if (hadTypename && !hasTypename) {
|
3201 | throw new Error("Store error: the application attempted to write an object with no provided typename" +
|
3202 | (" but the store already contains an object with typename of " + escapedId.typename + " for the object of id " + escapedId.id + ". The selectionSet") +
|
3203 | " that was trying to be written is:\n" +
|
3204 | JSON.stringify(field));
|
3205 | }
|
3206 | if (escapedId.generated) {
|
3207 | if (typenameChanged) {
|
3208 | if (!generated) {
|
3209 | store.delete(escapedId.id);
|
3210 | }
|
3211 | }
|
3212 | else {
|
3213 | mergeWithGenerated(escapedId.id, storeValue.id, store);
|
3214 | }
|
3215 | }
|
3216 | }
|
3217 | }
|
3218 | storeObject = store.get(dataId);
|
3219 | if (!storeObject || !apolloUtilities.isEqual(storeValue, storeObject[storeFieldName])) {
|
3220 | store.set(dataId, __assign({}, storeObject, (_b = {}, _b[storeFieldName] = storeValue, _b)));
|
3221 | }
|
3222 | };
|
3223 | StoreWriter.prototype.processArrayValue = function (value, generatedId, selectionSet, context) {
|
3224 | var _this = this;
|
3225 | return value.map(function (item, index) {
|
3226 | if (item === null) {
|
3227 | return null;
|
3228 | }
|
3229 | var itemDataId = generatedId + "." + index;
|
3230 | if (Array.isArray(item)) {
|
3231 | return _this.processArrayValue(item, itemDataId, selectionSet, context);
|
3232 | }
|
3233 | var generated = true;
|
3234 | if (context.dataIdFromObject) {
|
3235 | var semanticId = context.dataIdFromObject(item);
|
3236 | if (semanticId) {
|
3237 | itemDataId = semanticId;
|
3238 | generated = false;
|
3239 | }
|
3240 | }
|
3241 | if (!isDataProcessed(itemDataId, selectionSet, context.processedData)) {
|
3242 | _this.writeSelectionSetToStore({
|
3243 | dataId: itemDataId,
|
3244 | result: item,
|
3245 | selectionSet: selectionSet,
|
3246 | context: context,
|
3247 | });
|
3248 | }
|
3249 | return apolloUtilities.toIdValue({ id: itemDataId, typename: item.__typename }, generated);
|
3250 | });
|
3251 | };
|
3252 | return StoreWriter;
|
3253 | }());
|
3254 | function isGeneratedId(id) {
|
3255 | return id[0] === '$';
|
3256 | }
|
3257 | function mergeWithGenerated(generatedKey, realKey, cache) {
|
3258 | if (generatedKey === realKey) {
|
3259 | return false;
|
3260 | }
|
3261 | var generated = cache.get(generatedKey);
|
3262 | var real = cache.get(realKey);
|
3263 | var madeChanges = false;
|
3264 | Object.keys(generated).forEach(function (key) {
|
3265 | var value = generated[key];
|
3266 | var realValue = real[key];
|
3267 | if (apolloUtilities.isIdValue(value) &&
|
3268 | isGeneratedId(value.id) &&
|
3269 | apolloUtilities.isIdValue(realValue) &&
|
3270 | !apolloUtilities.isEqual(value, realValue) &&
|
3271 | mergeWithGenerated(value.id, realValue.id, cache)) {
|
3272 | madeChanges = true;
|
3273 | }
|
3274 | });
|
3275 | cache.delete(generatedKey);
|
3276 | var newRealValue = __assign({}, generated, real);
|
3277 | if (apolloUtilities.isEqual(newRealValue, real)) {
|
3278 | return madeChanges;
|
3279 | }
|
3280 | cache.set(realKey, newRealValue);
|
3281 | return true;
|
3282 | }
|
3283 | function isDataProcessed(dataId, field, processedData) {
|
3284 | if (!processedData) {
|
3285 | return false;
|
3286 | }
|
3287 | if (processedData[dataId]) {
|
3288 | if (processedData[dataId].indexOf(field) >= 0) {
|
3289 | return true;
|
3290 | }
|
3291 | else {
|
3292 | processedData[dataId].push(field);
|
3293 | }
|
3294 | }
|
3295 | else {
|
3296 | processedData[dataId] = [field];
|
3297 | }
|
3298 | return false;
|
3299 | }
|
3300 |
|
3301 | var defaultConfig = {
|
3302 | fragmentMatcher: new HeuristicFragmentMatcher(),
|
3303 | dataIdFromObject: defaultDataIdFromObject,
|
3304 | addTypename: true,
|
3305 | resultCaching: true,
|
3306 | };
|
3307 | function defaultDataIdFromObject(result) {
|
3308 | if (result.__typename) {
|
3309 | if (result.id !== undefined) {
|
3310 | return result.__typename + ":" + result.id;
|
3311 | }
|
3312 | if (result._id !== undefined) {
|
3313 | return result.__typename + ":" + result._id;
|
3314 | }
|
3315 | }
|
3316 | return null;
|
3317 | }
|
3318 | var hasOwn$2 = Object.prototype.hasOwnProperty;
|
3319 | var OptimisticCacheLayer = (function (_super) {
|
3320 | __extends(OptimisticCacheLayer, _super);
|
3321 | function OptimisticCacheLayer(optimisticId, parent, transaction) {
|
3322 | var _this = _super.call(this, Object.create(null)) || this;
|
3323 | _this.optimisticId = optimisticId;
|
3324 | _this.parent = parent;
|
3325 | _this.transaction = transaction;
|
3326 | return _this;
|
3327 | }
|
3328 | OptimisticCacheLayer.prototype.toObject = function () {
|
3329 | return __assign({}, this.parent.toObject(), this.data);
|
3330 | };
|
3331 | OptimisticCacheLayer.prototype.get = function (dataId) {
|
3332 | return hasOwn$2.call(this.data, dataId)
|
3333 | ? this.data[dataId]
|
3334 | : this.parent.get(dataId);
|
3335 | };
|
3336 | return OptimisticCacheLayer;
|
3337 | }(ObjectCache));
|
3338 | var InMemoryCache = (function (_super) {
|
3339 | __extends(InMemoryCache, _super);
|
3340 | function InMemoryCache(config) {
|
3341 | if (config === void 0) { config = {}; }
|
3342 | var _this = _super.call(this) || this;
|
3343 | _this.watches = new Set();
|
3344 | _this.typenameDocumentCache = new Map();
|
3345 | _this.cacheKeyRoot = new CacheKeyNode();
|
3346 | _this.silenceBroadcast = false;
|
3347 | _this.config = __assign({}, defaultConfig, config);
|
3348 | if (_this.config.customResolvers) {
|
3349 | console.warn('customResolvers have been renamed to cacheRedirects. Please update your config as we will be deprecating customResolvers in the next major version.');
|
3350 | _this.config.cacheRedirects = _this.config.customResolvers;
|
3351 | }
|
3352 | if (_this.config.cacheResolvers) {
|
3353 | console.warn('cacheResolvers have been renamed to cacheRedirects. Please update your config as we will be deprecating cacheResolvers in the next major version.');
|
3354 | _this.config.cacheRedirects = _this.config.cacheResolvers;
|
3355 | }
|
3356 | _this.addTypename = _this.config.addTypename;
|
3357 | _this.data = _this.config.resultCaching
|
3358 | ? new DepTrackingCache()
|
3359 | : new ObjectCache();
|
3360 | _this.optimisticData = _this.data;
|
3361 | _this.storeReader = new StoreReader(_this.cacheKeyRoot);
|
3362 | _this.storeWriter = new StoreWriter();
|
3363 | var cache = _this;
|
3364 | var maybeBroadcastWatch = cache.maybeBroadcastWatch;
|
3365 | _this.maybeBroadcastWatch = optimism.wrap(function (c) {
|
3366 | return maybeBroadcastWatch.call(_this, c);
|
3367 | }, {
|
3368 | makeCacheKey: function (c) {
|
3369 | if (c.optimistic) {
|
3370 | return;
|
3371 | }
|
3372 | if (c.previousResult) {
|
3373 | return;
|
3374 | }
|
3375 | if (cache.data instanceof DepTrackingCache) {
|
3376 | return cache.cacheKeyRoot.lookup(c.query, JSON.stringify(c.variables));
|
3377 | }
|
3378 | }
|
3379 | });
|
3380 | return _this;
|
3381 | }
|
3382 | InMemoryCache.prototype.restore = function (data) {
|
3383 | if (data)
|
3384 | this.data.replace(data);
|
3385 | return this;
|
3386 | };
|
3387 | InMemoryCache.prototype.extract = function (optimistic) {
|
3388 | if (optimistic === void 0) { optimistic = false; }
|
3389 | return (optimistic ? this.optimisticData : this.data).toObject();
|
3390 | };
|
3391 | InMemoryCache.prototype.read = function (options) {
|
3392 | if (typeof options.rootId === 'string' &&
|
3393 | typeof this.data.get(options.rootId) === 'undefined') {
|
3394 | return null;
|
3395 | }
|
3396 | return this.storeReader.readQueryFromStore({
|
3397 | store: options.optimistic ? this.optimisticData : this.data,
|
3398 | query: this.transformDocument(options.query),
|
3399 | variables: options.variables,
|
3400 | rootId: options.rootId,
|
3401 | fragmentMatcherFunction: this.config.fragmentMatcher.match,
|
3402 | previousResult: options.previousResult,
|
3403 | config: this.config,
|
3404 | });
|
3405 | };
|
3406 | InMemoryCache.prototype.write = function (write) {
|
3407 | this.storeWriter.writeResultToStore({
|
3408 | dataId: write.dataId,
|
3409 | result: write.result,
|
3410 | variables: write.variables,
|
3411 | document: this.transformDocument(write.query),
|
3412 | store: this.data,
|
3413 | dataIdFromObject: this.config.dataIdFromObject,
|
3414 | fragmentMatcherFunction: this.config.fragmentMatcher.match,
|
3415 | });
|
3416 | this.broadcastWatches();
|
3417 | };
|
3418 | InMemoryCache.prototype.diff = function (query) {
|
3419 | return this.storeReader.diffQueryAgainstStore({
|
3420 | store: query.optimistic ? this.optimisticData : this.data,
|
3421 | query: this.transformDocument(query.query),
|
3422 | variables: query.variables,
|
3423 | returnPartialData: query.returnPartialData,
|
3424 | previousResult: query.previousResult,
|
3425 | fragmentMatcherFunction: this.config.fragmentMatcher.match,
|
3426 | config: this.config,
|
3427 | });
|
3428 | };
|
3429 | InMemoryCache.prototype.watch = function (watch) {
|
3430 | var _this = this;
|
3431 | this.watches.add(watch);
|
3432 | return function () {
|
3433 | _this.watches.delete(watch);
|
3434 | };
|
3435 | };
|
3436 | InMemoryCache.prototype.evict = function (query) {
|
3437 | throw new Error("eviction is not implemented on InMemory Cache");
|
3438 | };
|
3439 | InMemoryCache.prototype.reset = function () {
|
3440 | this.data.clear();
|
3441 | this.broadcastWatches();
|
3442 | return Promise.resolve();
|
3443 | };
|
3444 | InMemoryCache.prototype.removeOptimistic = function (idToRemove) {
|
3445 | var toReapply = [];
|
3446 | var removedCount = 0;
|
3447 | var layer = this.optimisticData;
|
3448 | while (layer instanceof OptimisticCacheLayer) {
|
3449 | if (layer.optimisticId === idToRemove) {
|
3450 | ++removedCount;
|
3451 | }
|
3452 | else {
|
3453 | toReapply.push(layer);
|
3454 | }
|
3455 | layer = layer.parent;
|
3456 | }
|
3457 | if (removedCount > 0) {
|
3458 | this.optimisticData = layer;
|
3459 | while (toReapply.length > 0) {
|
3460 | var layer_1 = toReapply.pop();
|
3461 | this.performTransaction(layer_1.transaction, layer_1.optimisticId);
|
3462 | }
|
3463 | this.broadcastWatches();
|
3464 | }
|
3465 | };
|
3466 | InMemoryCache.prototype.performTransaction = function (transaction, optimisticId) {
|
3467 | var _a = this, data = _a.data, silenceBroadcast = _a.silenceBroadcast;
|
3468 | this.silenceBroadcast = true;
|
3469 | if (typeof optimisticId === 'string') {
|
3470 | this.data = this.optimisticData = new OptimisticCacheLayer(optimisticId, this.optimisticData, transaction);
|
3471 | }
|
3472 | try {
|
3473 | transaction(this);
|
3474 | }
|
3475 | finally {
|
3476 | this.silenceBroadcast = silenceBroadcast;
|
3477 | this.data = data;
|
3478 | }
|
3479 | this.broadcastWatches();
|
3480 | };
|
3481 | InMemoryCache.prototype.recordOptimisticTransaction = function (transaction, id) {
|
3482 | return this.performTransaction(transaction, id);
|
3483 | };
|
3484 | InMemoryCache.prototype.transformDocument = function (document) {
|
3485 | if (this.addTypename) {
|
3486 | var result = this.typenameDocumentCache.get(document);
|
3487 | if (!result) {
|
3488 | result = apolloUtilities.addTypenameToDocument(document);
|
3489 | this.typenameDocumentCache.set(document, result);
|
3490 | this.typenameDocumentCache.set(result, result);
|
3491 | }
|
3492 | return result;
|
3493 | }
|
3494 | return document;
|
3495 | };
|
3496 | InMemoryCache.prototype.broadcastWatches = function () {
|
3497 | var _this = this;
|
3498 | if (!this.silenceBroadcast) {
|
3499 | this.watches.forEach(function (c) { return _this.maybeBroadcastWatch(c); });
|
3500 | }
|
3501 | };
|
3502 | InMemoryCache.prototype.maybeBroadcastWatch = function (c) {
|
3503 | c.callback(this.diff({
|
3504 | query: c.query,
|
3505 | variables: c.variables,
|
3506 | previousResult: c.previousResult && c.previousResult(),
|
3507 | optimistic: c.optimistic,
|
3508 | }));
|
3509 | };
|
3510 | return InMemoryCache;
|
3511 | }(ApolloCache));
|
3512 |
|
3513 | var __assign$3 = (undefined && undefined.__assign) || function () {
|
3514 | __assign$3 = Object.assign || function(t) {
|
3515 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
3516 | s = arguments[i];
|
3517 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
3518 | t[p] = s[p];
|
3519 | }
|
3520 | return t;
|
3521 | };
|
3522 | return __assign$3.apply(this, arguments);
|
3523 | };
|
3524 | var defaultHttpOptions = {
|
3525 | includeQuery: true,
|
3526 | includeExtensions: false,
|
3527 | };
|
3528 | var defaultHeaders = {
|
3529 |
|
3530 | accept: '*/*',
|
3531 | 'content-type': 'application/json',
|
3532 | };
|
3533 | var defaultOptions = {
|
3534 | method: 'POST',
|
3535 | };
|
3536 | var fallbackHttpConfig = {
|
3537 | http: defaultHttpOptions,
|
3538 | headers: defaultHeaders,
|
3539 | options: defaultOptions,
|
3540 | };
|
3541 | var throwServerError = function (response, result, message) {
|
3542 | var error = new Error(message);
|
3543 | error.response = response;
|
3544 | error.statusCode = response.status;
|
3545 | error.result = result;
|
3546 | throw error;
|
3547 | };
|
3548 |
|
3549 | var parseAndCheckHttpResponse = function (operations) { return function (response) {
|
3550 | return (response
|
3551 | .text()
|
3552 | .then(function (bodyText) {
|
3553 | try {
|
3554 | return JSON.parse(bodyText);
|
3555 | }
|
3556 | catch (err) {
|
3557 | var parseError = err;
|
3558 | parseError.response = response;
|
3559 | parseError.statusCode = response.status;
|
3560 | parseError.bodyText = bodyText;
|
3561 | return Promise.reject(parseError);
|
3562 | }
|
3563 | })
|
3564 |
|
3565 | .then(function (result) {
|
3566 | if (response.status >= 300) {
|
3567 |
|
3568 | throwServerError(response, result, "Response not successful: Received status code " + response.status);
|
3569 | }
|
3570 |
|
3571 |
|
3572 | if (!Array.isArray(result) &&
|
3573 | !result.hasOwnProperty('data') &&
|
3574 | !result.hasOwnProperty('errors')) {
|
3575 |
|
3576 | throwServerError(response, result, "Server response was missing for query '" + (Array.isArray(operations)
|
3577 | ? operations.map(function (op) { return op.operationName; })
|
3578 | : operations.operationName) + "'.");
|
3579 | }
|
3580 | return result;
|
3581 | }));
|
3582 | }; };
|
3583 | var checkFetcher = function (fetcher) {
|
3584 | if (!fetcher && typeof fetch === 'undefined') {
|
3585 | var library = 'unfetch';
|
3586 | if (typeof window === 'undefined')
|
3587 | library = 'node-fetch';
|
3588 | throw new Error("\nfetch is not found globally and no fetcher passed, to fix pass a fetch for\nyour environment like https://www.npmjs.com/package/" + library + ".\n\nFor example:\nimport fetch from '" + library + "';\nimport { createHttpLink } from 'apollo-link-http';\n\nconst link = createHttpLink({ uri: '/graphql', fetch: fetch });");
|
3589 | }
|
3590 | };
|
3591 | var createSignalIfSupported = function () {
|
3592 | if (typeof AbortController === 'undefined')
|
3593 | return { controller: false, signal: false };
|
3594 | var controller = new AbortController();
|
3595 | var signal = controller.signal;
|
3596 | return { controller: controller, signal: signal };
|
3597 | };
|
3598 | var selectHttpOptionsAndBody = function (operation, fallbackConfig) {
|
3599 | var configs = [];
|
3600 | for (var _i = 2; _i < arguments.length; _i++) {
|
3601 | configs[_i - 2] = arguments[_i];
|
3602 | }
|
3603 | var options = __assign$3({}, fallbackConfig.options, { headers: fallbackConfig.headers, credentials: fallbackConfig.credentials });
|
3604 | var http = fallbackConfig.http;
|
3605 | |
3606 |
|
3607 |
|
3608 |
|
3609 | configs.forEach(function (config) {
|
3610 | options = __assign$3({}, options, config.options, { headers: __assign$3({}, options.headers, config.headers) });
|
3611 | if (config.credentials)
|
3612 | options.credentials = config.credentials;
|
3613 | http = __assign$3({}, http, config.http);
|
3614 | });
|
3615 |
|
3616 | var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
|
3617 | var body = { operationName: operationName, variables: variables };
|
3618 | if (http.includeExtensions)
|
3619 | body.extensions = extensions;
|
3620 |
|
3621 | if (http.includeQuery)
|
3622 | body.query = printer.print(query);
|
3623 | return {
|
3624 | options: options,
|
3625 | body: body,
|
3626 | };
|
3627 | };
|
3628 | var serializeFetchParameter = function (p, label) {
|
3629 | var serialized;
|
3630 | try {
|
3631 | serialized = JSON.stringify(p);
|
3632 | }
|
3633 | catch (e) {
|
3634 | var parseError = new Error("Network request failed. " + label + " is not serializable: " + e.message);
|
3635 | parseError.parseError = e;
|
3636 | throw parseError;
|
3637 | }
|
3638 | return serialized;
|
3639 | };
|
3640 |
|
3641 | var selectURI = function (operation, fallbackURI) {
|
3642 | var context = operation.getContext();
|
3643 | var contextURI = context.uri;
|
3644 | if (contextURI) {
|
3645 | return contextURI;
|
3646 | }
|
3647 | else if (typeof fallbackURI === 'function') {
|
3648 | return fallbackURI(operation);
|
3649 | }
|
3650 | else {
|
3651 | return fallbackURI || '/graphql';
|
3652 | }
|
3653 | };
|
3654 |
|
3655 |
|
3656 | var __extends$4 = (undefined && undefined.__extends) || (function () {
|
3657 | var extendStatics = function (d, b) {
|
3658 | extendStatics = Object.setPrototypeOf ||
|
3659 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
3660 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
3661 | return extendStatics(d, b);
|
3662 | };
|
3663 | return function (d, b) {
|
3664 | extendStatics(d, b);
|
3665 | function __() { this.constructor = d; }
|
3666 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
3667 | };
|
3668 | })();
|
3669 | var __rest$1 = (undefined && undefined.__rest) || function (s, e) {
|
3670 | var t = {};
|
3671 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
3672 | t[p] = s[p];
|
3673 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
3674 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
3675 | t[p[i]] = s[p[i]];
|
3676 | return t;
|
3677 | };
|
3678 | var createHttpLink = function (linkOptions) {
|
3679 | if (linkOptions === void 0) { linkOptions = {}; }
|
3680 | var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a,
|
3681 |
|
3682 | fetcher = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, requestOptions = __rest$1(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries"]);
|
3683 |
|
3684 | checkFetcher(fetcher);
|
3685 |
|
3686 |
|
3687 |
|
3688 | if (!fetcher) {
|
3689 | fetcher = fetch;
|
3690 | }
|
3691 | var linkConfig = {
|
3692 | http: { includeExtensions: includeExtensions },
|
3693 | options: requestOptions.fetchOptions,
|
3694 | credentials: requestOptions.credentials,
|
3695 | headers: requestOptions.headers,
|
3696 | };
|
3697 | return new ApolloLink$1(function (operation) {
|
3698 | var chosenURI = selectURI(operation, uri);
|
3699 | var context = operation.getContext();
|
3700 | var contextConfig = {
|
3701 | http: context.http,
|
3702 | options: context.fetchOptions,
|
3703 | credentials: context.credentials,
|
3704 | headers: context.headers,
|
3705 | };
|
3706 |
|
3707 | var _a = selectHttpOptionsAndBody(operation, fallbackHttpConfig, linkConfig, contextConfig), options = _a.options, body = _a.body;
|
3708 | var controller;
|
3709 | if (!options.signal) {
|
3710 | var _b = createSignalIfSupported(), _controller = _b.controller, signal = _b.signal;
|
3711 | controller = _controller;
|
3712 | if (controller)
|
3713 | options.signal = signal;
|
3714 | }
|
3715 |
|
3716 | var definitionIsMutation = function (d) {
|
3717 | return d.kind === 'OperationDefinition' && d.operation === 'mutation';
|
3718 | };
|
3719 | if (useGETForQueries &&
|
3720 | !operation.query.definitions.some(definitionIsMutation)) {
|
3721 | options.method = 'GET';
|
3722 | }
|
3723 | if (options.method === 'GET') {
|
3724 | var _c = rewriteURIForGET(chosenURI, body), newURI = _c.newURI, parseError = _c.parseError;
|
3725 | if (parseError) {
|
3726 | return fromError$1(parseError);
|
3727 | }
|
3728 | chosenURI = newURI;
|
3729 | }
|
3730 | else {
|
3731 | try {
|
3732 | options.body = serializeFetchParameter(body, 'Payload');
|
3733 | }
|
3734 | catch (parseError) {
|
3735 | return fromError$1(parseError);
|
3736 | }
|
3737 | }
|
3738 | return new Observable$2(function (observer) {
|
3739 | fetcher(chosenURI, options)
|
3740 | .then(function (response) {
|
3741 | operation.setContext({ response: response });
|
3742 | return response;
|
3743 | })
|
3744 | .then(parseAndCheckHttpResponse(operation))
|
3745 | .then(function (result) {
|
3746 |
|
3747 | observer.next(result);
|
3748 | observer.complete();
|
3749 | return result;
|
3750 | })
|
3751 | .catch(function (err) {
|
3752 |
|
3753 | if (err.name === 'AbortError')
|
3754 | return;
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 |
|
3760 |
|
3761 | if (err.result && err.result.errors && err.result.data) {
|
3762 |
|
3763 |
|
3764 |
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 |
|
3775 |
|
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 | observer.next(err.result);
|
3789 | }
|
3790 | observer.error(err);
|
3791 | });
|
3792 | return function () {
|
3793 |
|
3794 |
|
3795 | if (controller)
|
3796 | controller.abort();
|
3797 | };
|
3798 | });
|
3799 | });
|
3800 | };
|
3801 |
|
3802 |
|
3803 | function rewriteURIForGET(chosenURI, body) {
|
3804 |
|
3805 |
|
3806 | var queryParams = [];
|
3807 | var addQueryParam = function (key, value) {
|
3808 | queryParams.push(key + "=" + encodeURIComponent(value));
|
3809 | };
|
3810 | if ('query' in body) {
|
3811 | addQueryParam('query', body.query);
|
3812 | }
|
3813 | if (body.operationName) {
|
3814 | addQueryParam('operationName', body.operationName);
|
3815 | }
|
3816 | if (body.variables) {
|
3817 | var serializedVariables = void 0;
|
3818 | try {
|
3819 | serializedVariables = serializeFetchParameter(body.variables, 'Variables map');
|
3820 | }
|
3821 | catch (parseError) {
|
3822 | return { parseError: parseError };
|
3823 | }
|
3824 | addQueryParam('variables', serializedVariables);
|
3825 | }
|
3826 | if (body.extensions) {
|
3827 | var serializedExtensions = void 0;
|
3828 | try {
|
3829 | serializedExtensions = serializeFetchParameter(body.extensions, 'Extensions map');
|
3830 | }
|
3831 | catch (parseError) {
|
3832 | return { parseError: parseError };
|
3833 | }
|
3834 | addQueryParam('extensions', serializedExtensions);
|
3835 | }
|
3836 |
|
3837 |
|
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 | var fragment = '', preFragment = chosenURI;
|
3843 | var fragmentStart = chosenURI.indexOf('#');
|
3844 | if (fragmentStart !== -1) {
|
3845 | fragment = chosenURI.substr(fragmentStart);
|
3846 | preFragment = chosenURI.substr(0, fragmentStart);
|
3847 | }
|
3848 | var queryParamsPrefix = preFragment.indexOf('?') === -1 ? '?' : '&';
|
3849 | var newURI = preFragment + queryParamsPrefix + queryParams.join('&') + fragment;
|
3850 | return { newURI: newURI };
|
3851 | }
|
3852 | var HttpLink = (function (_super) {
|
3853 | __extends$4(HttpLink, _super);
|
3854 | function HttpLink(opts) {
|
3855 | return _super.call(this, createHttpLink(opts).request) || this;
|
3856 | }
|
3857 | return HttpLink;
|
3858 | }(ApolloLink$1));
|
3859 |
|
3860 | |
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 | |
3870 |
|
3871 |
|
3872 |
|
3873 | function applyToJSON(classObject) {
|
3874 | classObject.prototype.toJSON = classObject.prototype.inspect = classObject.prototype.toString;
|
3875 | }
|
3876 |
|
3877 | |
3878 |
|
3879 |
|
3880 |
|
3881 |
|
3882 |
|
3883 |
|
3884 |
|
3885 |
|
3886 | |
3887 |
|
3888 |
|
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 | function applyToStringTag(classObject) {
|
3900 | if (typeof Symbol === 'function' && Symbol.toStringTag) {
|
3901 | Object.defineProperty(classObject.prototype, Symbol.toStringTag, {
|
3902 | get: function get() {
|
3903 | return this.constructor.name;
|
3904 | }
|
3905 | });
|
3906 | }
|
3907 | }
|
3908 |
|
3909 | |
3910 |
|
3911 |
|
3912 |
|
3913 |
|
3914 |
|
3915 |
|
3916 |
|
3917 |
|
3918 | |
3919 |
|
3920 |
|
3921 |
|
3922 |
|
3923 |
|
3924 | var instanceOf = process.env.NODE_ENV === 'production' ?
|
3925 | function instanceOf(value, constructor) {
|
3926 | return value instanceof constructor;
|
3927 | } : // eslint-disable-next-line no-shadow
|
3928 | function instanceOf(value, constructor) {
|
3929 | if (value instanceof constructor) {
|
3930 | return true;
|
3931 | }
|
3932 |
|
3933 | if (value) {
|
3934 | var valueClass = value.constructor;
|
3935 | var className = constructor.name;
|
3936 |
|
3937 | if (className && valueClass && valueClass.name === className) {
|
3938 | throw new Error("Cannot use ".concat(className, " \"").concat(value, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
|
3939 | }
|
3940 | }
|
3941 |
|
3942 | return false;
|
3943 | };
|
3944 |
|
3945 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
3946 |
|
3947 | |
3948 |
|
3949 |
|
3950 |
|
3951 |
|
3952 |
|
3953 |
|
3954 |
|
3955 |
|
3956 | |
3957 |
|
3958 |
|
3959 | function inspect(value) {
|
3960 | switch (_typeof(value)) {
|
3961 | case 'string':
|
3962 | return JSON.stringify(value);
|
3963 |
|
3964 | case 'function':
|
3965 | return value.name ? "[function ".concat(value.name, "]") : '[function]';
|
3966 |
|
3967 | case 'object':
|
3968 | if (value) {
|
3969 | if (typeof value.inspect === 'function') {
|
3970 | return value.inspect();
|
3971 | } else if (Array.isArray(value)) {
|
3972 | return '[' + value.map(inspect).join(', ') + ']';
|
3973 | }
|
3974 |
|
3975 | var properties = Object.keys(value).map(function (k) {
|
3976 | return "".concat(k, ": ").concat(inspect(value[k]));
|
3977 | }).join(', ');
|
3978 | return properties ? '{ ' + properties + ' }' : '{}';
|
3979 | }
|
3980 |
|
3981 | return String(value);
|
3982 |
|
3983 | default:
|
3984 | return String(value);
|
3985 | }
|
3986 | }
|
3987 |
|
3988 | |
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 |
|
3994 |
|
3995 |
|
3996 | function invariant(condition, message) {
|
3997 |
|
3998 | if (!condition) {
|
3999 | throw new Error(message);
|
4000 | }
|
4001 | }
|
4002 |
|
4003 | |
4004 |
|
4005 |
|
4006 |
|
4007 |
|
4008 |
|
4009 |
|
4010 |
|
4011 |
|
4012 | |
4013 |
|
4014 |
|
4015 |
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 |
|
4024 |
|
4025 |
|
4026 |
|
4027 |
|
4028 |
|
4029 |
|
4030 |
|
4031 |
|
4032 |
|
4033 |
|
4034 |
|
4035 | function keyMap(list, keyFn) {
|
4036 | return list.reduce(function (map, item) {
|
4037 | return map[keyFn(item)] = item, map;
|
4038 | }, Object.create(null));
|
4039 | }
|
4040 |
|
4041 | |
4042 |
|
4043 |
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 |
|
4049 |
|
4050 | |
4051 |
|
4052 |
|
4053 | var Kind = Object.freeze({
|
4054 |
|
4055 | NAME: 'Name',
|
4056 |
|
4057 | DOCUMENT: 'Document',
|
4058 | OPERATION_DEFINITION: 'OperationDefinition',
|
4059 | VARIABLE_DEFINITION: 'VariableDefinition',
|
4060 | SELECTION_SET: 'SelectionSet',
|
4061 | FIELD: 'Field',
|
4062 | ARGUMENT: 'Argument',
|
4063 |
|
4064 | FRAGMENT_SPREAD: 'FragmentSpread',
|
4065 | INLINE_FRAGMENT: 'InlineFragment',
|
4066 | FRAGMENT_DEFINITION: 'FragmentDefinition',
|
4067 |
|
4068 | VARIABLE: 'Variable',
|
4069 | INT: 'IntValue',
|
4070 | FLOAT: 'FloatValue',
|
4071 | STRING: 'StringValue',
|
4072 | BOOLEAN: 'BooleanValue',
|
4073 | NULL: 'NullValue',
|
4074 | ENUM: 'EnumValue',
|
4075 | LIST: 'ListValue',
|
4076 | OBJECT: 'ObjectValue',
|
4077 | OBJECT_FIELD: 'ObjectField',
|
4078 |
|
4079 | DIRECTIVE: 'Directive',
|
4080 |
|
4081 | NAMED_TYPE: 'NamedType',
|
4082 | LIST_TYPE: 'ListType',
|
4083 | NON_NULL_TYPE: 'NonNullType',
|
4084 |
|
4085 | SCHEMA_DEFINITION: 'SchemaDefinition',
|
4086 | OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition',
|
4087 |
|
4088 | SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition',
|
4089 | OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition',
|
4090 | FIELD_DEFINITION: 'FieldDefinition',
|
4091 | INPUT_VALUE_DEFINITION: 'InputValueDefinition',
|
4092 | INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition',
|
4093 | UNION_TYPE_DEFINITION: 'UnionTypeDefinition',
|
4094 | ENUM_TYPE_DEFINITION: 'EnumTypeDefinition',
|
4095 | ENUM_VALUE_DEFINITION: 'EnumValueDefinition',
|
4096 | INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition',
|
4097 |
|
4098 | DIRECTIVE_DEFINITION: 'DirectiveDefinition',
|
4099 |
|
4100 | SCHEMA_EXTENSION: 'SchemaExtension',
|
4101 |
|
4102 | SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension',
|
4103 | OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension',
|
4104 | INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension',
|
4105 | UNION_TYPE_EXTENSION: 'UnionTypeExtension',
|
4106 | ENUM_TYPE_EXTENSION: 'EnumTypeExtension',
|
4107 | INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension'
|
4108 | });
|
4109 | |
4110 |
|
4111 |
|
4112 |
|
4113 | |
4114 |
|
4115 |
|
4116 |
|
4117 |
|
4118 |
|
4119 |
|
4120 |
|
4121 |
|
4122 | |
4123 |
|
4124 |
|
4125 |
|
4126 |
|
4127 |
|
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 |
|
4134 |
|
4135 |
|
4136 |
|
4137 |
|
4138 |
|
4139 | function keyValMap(list, keyFn, valFn) {
|
4140 | return list.reduce(function (map, item) {
|
4141 | return map[keyFn(item)] = valFn(item), map;
|
4142 | }, Object.create(null));
|
4143 | }
|
4144 |
|
4145 | |
4146 |
|
4147 |
|
4148 |
|
4149 |
|
4150 |
|
4151 |
|
4152 |
|
4153 |
|
4154 | |
4155 |
|
4156 |
|
4157 | function isInvalid(value) {
|
4158 | return value === undefined || value !== value;
|
4159 | }
|
4160 |
|
4161 | |
4162 |
|
4163 |
|
4164 |
|
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 | |
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 |
|
4176 |
|
4177 |
|
4178 |
|
4179 |
|
4180 |
|
4181 |
|
4182 |
|
4183 |
|
4184 |
|
4185 |
|
4186 | function valueFromASTUntyped(valueNode, variables) {
|
4187 | switch (valueNode.kind) {
|
4188 | case Kind.NULL:
|
4189 | return null;
|
4190 |
|
4191 | case Kind.INT:
|
4192 | return parseInt(valueNode.value, 10);
|
4193 |
|
4194 | case Kind.FLOAT:
|
4195 | return parseFloat(valueNode.value);
|
4196 |
|
4197 | case Kind.STRING:
|
4198 | case Kind.ENUM:
|
4199 | case Kind.BOOLEAN:
|
4200 | return valueNode.value;
|
4201 |
|
4202 | case Kind.LIST:
|
4203 | return valueNode.values.map(function (node) {
|
4204 | return valueFromASTUntyped(node, variables);
|
4205 | });
|
4206 |
|
4207 | case Kind.OBJECT:
|
4208 | return keyValMap(valueNode.fields, function (field) {
|
4209 | return field.name.value;
|
4210 | }, function (field) {
|
4211 | return valueFromASTUntyped(field.value, variables);
|
4212 | });
|
4213 |
|
4214 | case Kind.VARIABLE:
|
4215 | var variableName = valueNode.name.value;
|
4216 | return variables && !isInvalid(variables[variableName]) ? variables[variableName] : undefined;
|
4217 | }
|
4218 |
|
4219 |
|
4220 |
|
4221 | throw new Error('Unexpected value kind: ' + valueNode.kind);
|
4222 | }
|
4223 |
|
4224 | function _typeof$1(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
|
4225 |
|
4226 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
4227 |
|
4228 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
4229 | function isType(type) {
|
4230 | return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isInputObjectType(type) || isListType(type) || isNonNullType(type);
|
4231 | }
|
4232 | function assertType(type) {
|
4233 | !isType(type) ? invariant(0, "Expected ".concat(inspect(type), " to be a GraphQL type.")) : void 0;
|
4234 | return type;
|
4235 | }
|
4236 | |
4237 |
|
4238 |
|
4239 |
|
4240 |
|
4241 | function isScalarType(type) {
|
4242 | return instanceOf(type, GraphQLScalarType);
|
4243 | }
|
4244 |
|
4245 | function isObjectType(type) {
|
4246 | return instanceOf(type, GraphQLObjectType);
|
4247 | }
|
4248 |
|
4249 | function isInterfaceType(type) {
|
4250 | return instanceOf(type, GraphQLInterfaceType);
|
4251 | }
|
4252 |
|
4253 | function isUnionType(type) {
|
4254 | return instanceOf(type, GraphQLUnionType);
|
4255 | }
|
4256 |
|
4257 | function isEnumType(type) {
|
4258 | return instanceOf(type, GraphQLEnumType);
|
4259 | }
|
4260 |
|
4261 | function isInputObjectType(type) {
|
4262 | return instanceOf(type, GraphQLInputObjectType);
|
4263 | }
|
4264 |
|
4265 | function isListType(type) {
|
4266 | return instanceOf(type, GraphQLList);
|
4267 | }
|
4268 |
|
4269 | function isNonNullType(type) {
|
4270 | return instanceOf(type, GraphQLNonNull);
|
4271 | }
|
4272 | |
4273 |
|
4274 |
|
4275 |
|
4276 | function isInputType(type) {
|
4277 | return isScalarType(type) || isEnumType(type) || isInputObjectType(type) || isWrappingType(type) && isInputType(type.ofType);
|
4278 | }
|
4279 | |
4280 |
|
4281 |
|
4282 |
|
4283 | function isOutputType(type) {
|
4284 | return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isWrappingType(type) && isOutputType(type.ofType);
|
4285 | }
|
4286 | |
4287 |
|
4288 |
|
4289 |
|
4290 | function isCompositeType(type) {
|
4291 | return isObjectType(type) || isInterfaceType(type) || isUnionType(type);
|
4292 | }
|
4293 | |
4294 |
|
4295 |
|
4296 |
|
4297 | function isAbstractType(type) {
|
4298 | return isInterfaceType(type) || isUnionType(type);
|
4299 | }
|
4300 | |
4301 |
|
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 |
|
4310 |
|
4311 |
|
4312 |
|
4313 |
|
4314 |
|
4315 |
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 | function GraphQLList(ofType) {
|
4321 | if (this instanceof GraphQLList) {
|
4322 | this.ofType = assertType(ofType);
|
4323 | } else {
|
4324 | return new GraphQLList(ofType);
|
4325 | }
|
4326 | }
|
4327 |
|
4328 | GraphQLList.prototype.toString = function toString() {
|
4329 | return '[' + String(this.ofType) + ']';
|
4330 | };
|
4331 |
|
4332 | applyToJSON(GraphQLList);
|
4333 | |
4334 |
|
4335 |
|
4336 |
|
4337 |
|
4338 |
|
4339 |
|
4340 |
|
4341 |
|
4342 |
|
4343 |
|
4344 |
|
4345 |
|
4346 |
|
4347 |
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 | function GraphQLNonNull(ofType) {
|
4356 | if (this instanceof GraphQLNonNull) {
|
4357 | this.ofType = assertNullableType(ofType);
|
4358 | } else {
|
4359 | return new GraphQLNonNull(ofType);
|
4360 | }
|
4361 | }
|
4362 |
|
4363 | GraphQLNonNull.prototype.toString = function toString() {
|
4364 | return String(this.ofType) + '!';
|
4365 | };
|
4366 |
|
4367 | applyToJSON(GraphQLNonNull);
|
4368 | |
4369 |
|
4370 |
|
4371 |
|
4372 | function isWrappingType(type) {
|
4373 | return isListType(type) || isNonNullType(type);
|
4374 | }
|
4375 | |
4376 |
|
4377 |
|
4378 |
|
4379 | function isNullableType(type) {
|
4380 | return isType(type) && !isNonNullType(type);
|
4381 | }
|
4382 | function assertNullableType(type) {
|
4383 | !isNullableType(type) ? invariant(0, "Expected ".concat(inspect(type), " to be a GraphQL nullable type.")) : void 0;
|
4384 | return type;
|
4385 | }
|
4386 |
|
4387 |
|
4388 | function getNullableType(type) {
|
4389 |
|
4390 | if (type) {
|
4391 | return isNonNullType(type) ? type.ofType : type;
|
4392 | }
|
4393 | }
|
4394 |
|
4395 |
|
4396 | function getNamedType(type) {
|
4397 |
|
4398 | if (type) {
|
4399 | var unwrappedType = type;
|
4400 |
|
4401 | while (isWrappingType(unwrappedType)) {
|
4402 | unwrappedType = unwrappedType.ofType;
|
4403 | }
|
4404 |
|
4405 | return unwrappedType;
|
4406 | }
|
4407 | }
|
4408 | |
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 | function resolveThunk(thunk) {
|
4414 | return typeof thunk === 'function' ? thunk() : thunk;
|
4415 | }
|
4416 | |
4417 |
|
4418 |
|
4419 |
|
4420 |
|
4421 |
|
4422 |
|
4423 |
|
4424 |
|
4425 |
|
4426 |
|
4427 |
|
4428 |
|
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 |
|
4434 |
|
4435 |
|
4436 |
|
4437 |
|
4438 |
|
4439 |
|
4440 |
|
4441 |
|
4442 | var GraphQLScalarType =
|
4443 |
|
4444 | function () {
|
4445 | function GraphQLScalarType(config) {
|
4446 | _defineProperty(this, "name", void 0);
|
4447 |
|
4448 | _defineProperty(this, "description", void 0);
|
4449 |
|
4450 | _defineProperty(this, "serialize", void 0);
|
4451 |
|
4452 | _defineProperty(this, "parseValue", void 0);
|
4453 |
|
4454 | _defineProperty(this, "parseLiteral", void 0);
|
4455 |
|
4456 | _defineProperty(this, "astNode", void 0);
|
4457 |
|
4458 | _defineProperty(this, "extensionASTNodes", void 0);
|
4459 |
|
4460 | this.name = config.name;
|
4461 | this.description = config.description;
|
4462 | this.serialize = config.serialize;
|
4463 |
|
4464 | this.parseValue = config.parseValue || function (value) {
|
4465 | return value;
|
4466 | };
|
4467 |
|
4468 | this.parseLiteral = config.parseLiteral || valueFromASTUntyped;
|
4469 | this.astNode = config.astNode;
|
4470 | this.extensionASTNodes = config.extensionASTNodes;
|
4471 | !(typeof config.name === 'string') ? invariant(0, 'Must provide name.') : void 0;
|
4472 | !(typeof config.serialize === 'function') ? invariant(0, "".concat(this.name, " must provide \"serialize\" function. If this custom Scalar ") + 'is also used as an input type, ensure "parseValue" and "parseLiteral" ' + 'functions are also provided.') : void 0;
|
4473 |
|
4474 | if (config.parseValue || config.parseLiteral) {
|
4475 | !(typeof config.parseValue === 'function' && typeof config.parseLiteral === 'function') ? invariant(0, "".concat(this.name, " must provide both \"parseValue\" and \"parseLiteral\" ") + 'functions.') : void 0;
|
4476 | }
|
4477 | }
|
4478 |
|
4479 | var _proto = GraphQLScalarType.prototype;
|
4480 |
|
4481 | _proto.toString = function toString() {
|
4482 | return this.name;
|
4483 | };
|
4484 |
|
4485 | return GraphQLScalarType;
|
4486 | }();
|
4487 |
|
4488 | applyToStringTag(GraphQLScalarType);
|
4489 | applyToJSON(GraphQLScalarType);
|
4490 |
|
4491 | |
4492 |
|
4493 |
|
4494 |
|
4495 |
|
4496 |
|
4497 |
|
4498 |
|
4499 |
|
4500 |
|
4501 |
|
4502 |
|
4503 |
|
4504 |
|
4505 |
|
4506 |
|
4507 |
|
4508 |
|
4509 |
|
4510 |
|
4511 |
|
4512 |
|
4513 |
|
4514 |
|
4515 |
|
4516 |
|
4517 |
|
4518 |
|
4519 |
|
4520 |
|
4521 |
|
4522 |
|
4523 |
|
4524 |
|
4525 |
|
4526 |
|
4527 |
|
4528 | var GraphQLObjectType =
|
4529 |
|
4530 | function () {
|
4531 | function GraphQLObjectType(config) {
|
4532 | _defineProperty(this, "name", void 0);
|
4533 |
|
4534 | _defineProperty(this, "description", void 0);
|
4535 |
|
4536 | _defineProperty(this, "astNode", void 0);
|
4537 |
|
4538 | _defineProperty(this, "extensionASTNodes", void 0);
|
4539 |
|
4540 | _defineProperty(this, "isTypeOf", void 0);
|
4541 |
|
4542 | _defineProperty(this, "_fields", void 0);
|
4543 |
|
4544 | _defineProperty(this, "_interfaces", void 0);
|
4545 |
|
4546 | this.name = config.name;
|
4547 | this.description = config.description;
|
4548 | this.astNode = config.astNode;
|
4549 | this.extensionASTNodes = config.extensionASTNodes;
|
4550 | this.isTypeOf = config.isTypeOf;
|
4551 | this._fields = defineFieldMap.bind(undefined, config);
|
4552 | this._interfaces = defineInterfaces.bind(undefined, config);
|
4553 | !(typeof config.name === 'string') ? invariant(0, 'Must provide name.') : void 0;
|
4554 | !(config.isTypeOf == null || typeof config.isTypeOf === 'function') ? invariant(0, "".concat(this.name, " must provide \"isTypeOf\" as a function, ") + "but got: ".concat(inspect(config.isTypeOf), ".")) : void 0;
|
4555 | }
|
4556 |
|
4557 | var _proto2 = GraphQLObjectType.prototype;
|
4558 |
|
4559 | _proto2.getFields = function getFields() {
|
4560 | if (typeof this._fields === 'function') {
|
4561 | this._fields = this._fields();
|
4562 | }
|
4563 |
|
4564 | return this._fields;
|
4565 | };
|
4566 |
|
4567 | _proto2.getInterfaces = function getInterfaces() {
|
4568 | if (typeof this._interfaces === 'function') {
|
4569 | this._interfaces = this._interfaces();
|
4570 | }
|
4571 |
|
4572 | return this._interfaces;
|
4573 | };
|
4574 |
|
4575 | _proto2.toString = function toString() {
|
4576 | return this.name;
|
4577 | };
|
4578 |
|
4579 | return GraphQLObjectType;
|
4580 | }();
|
4581 |
|
4582 | applyToStringTag(GraphQLObjectType);
|
4583 | applyToJSON(GraphQLObjectType);
|
4584 |
|
4585 | function defineInterfaces(config) {
|
4586 | var interfaces = resolveThunk(config.interfaces) || [];
|
4587 | !Array.isArray(interfaces) ? invariant(0, "".concat(config.name, " interfaces must be an Array or a function which returns ") + 'an Array.') : void 0;
|
4588 | return interfaces;
|
4589 | }
|
4590 |
|
4591 | function defineFieldMap(config) {
|
4592 | var fieldMap = resolveThunk(config.fields) || {};
|
4593 | !isPlainObj(fieldMap) ? invariant(0, "".concat(config.name, " fields must be an object with field names as keys or a ") + 'function which returns such an object.') : void 0;
|
4594 | var resultFieldMap = Object.create(null);
|
4595 |
|
4596 | var _arr = Object.keys(fieldMap);
|
4597 |
|
4598 | var _loop = function _loop() {
|
4599 | var fieldName = _arr[_i];
|
4600 | var fieldConfig = fieldMap[fieldName];
|
4601 | !isPlainObj(fieldConfig) ? invariant(0, "".concat(config.name, ".").concat(fieldName, " field config must be an object")) : void 0;
|
4602 | !!fieldConfig.hasOwnProperty('isDeprecated') ? invariant(0, "".concat(config.name, ".").concat(fieldName, " should provide \"deprecationReason\" ") + 'instead of "isDeprecated".') : void 0;
|
4603 |
|
4604 | var field = _objectSpread({}, fieldConfig, {
|
4605 | isDeprecated: Boolean(fieldConfig.deprecationReason),
|
4606 | name: fieldName
|
4607 | });
|
4608 |
|
4609 | !(field.resolve == null || typeof field.resolve === 'function') ? invariant(0, "".concat(config.name, ".").concat(fieldName, " field resolver must be a function if ") + "provided, but got: ".concat(inspect(field.resolve), ".")) : void 0;
|
4610 | var argsConfig = fieldConfig.args;
|
4611 |
|
4612 | if (!argsConfig) {
|
4613 | field.args = [];
|
4614 | } else {
|
4615 | !isPlainObj(argsConfig) ? invariant(0, "".concat(config.name, ".").concat(fieldName, " args must be an object with argument ") + 'names as keys.') : void 0;
|
4616 | field.args = Object.keys(argsConfig).map(function (argName) {
|
4617 | var arg = argsConfig[argName];
|
4618 | return {
|
4619 | name: argName,
|
4620 | description: arg.description === undefined ? null : arg.description,
|
4621 | type: arg.type,
|
4622 | defaultValue: arg.defaultValue,
|
4623 | astNode: arg.astNode
|
4624 | };
|
4625 | });
|
4626 | }
|
4627 |
|
4628 | resultFieldMap[fieldName] = field;
|
4629 | };
|
4630 |
|
4631 | for (var _i = 0; _i < _arr.length; _i++) {
|
4632 | _loop();
|
4633 | }
|
4634 |
|
4635 | return resultFieldMap;
|
4636 | }
|
4637 |
|
4638 | function isPlainObj(obj) {
|
4639 | return obj && _typeof$1(obj) === 'object' && !Array.isArray(obj);
|
4640 | }
|
4641 |
|
4642 | |
4643 |
|
4644 |
|
4645 |
|
4646 |
|
4647 |
|
4648 |
|
4649 |
|
4650 |
|
4651 |
|
4652 |
|
4653 |
|
4654 |
|
4655 |
|
4656 |
|
4657 |
|
4658 |
|
4659 |
|
4660 | var GraphQLInterfaceType =
|
4661 |
|
4662 | function () {
|
4663 | function GraphQLInterfaceType(config) {
|
4664 | _defineProperty(this, "name", void 0);
|
4665 |
|
4666 | _defineProperty(this, "description", void 0);
|
4667 |
|
4668 | _defineProperty(this, "astNode", void 0);
|
4669 |
|
4670 | _defineProperty(this, "extensionASTNodes", void 0);
|
4671 |
|
4672 | _defineProperty(this, "resolveType", void 0);
|
4673 |
|
4674 | _defineProperty(this, "_fields", void 0);
|
4675 |
|
4676 | this.name = config.name;
|
4677 | this.description = config.description;
|
4678 | this.astNode = config.astNode;
|
4679 | this.extensionASTNodes = config.extensionASTNodes;
|
4680 | this.resolveType = config.resolveType;
|
4681 | this._fields = defineFieldMap.bind(undefined, config);
|
4682 | !(typeof config.name === 'string') ? invariant(0, 'Must provide name.') : void 0;
|
4683 | !(config.resolveType == null || typeof config.resolveType === 'function') ? invariant(0, "".concat(this.name, " must provide \"resolveType\" as a function, ") + "but got: ".concat(inspect(config.resolveType), ".")) : void 0;
|
4684 | }
|
4685 |
|
4686 | var _proto3 = GraphQLInterfaceType.prototype;
|
4687 |
|
4688 | _proto3.getFields = function getFields() {
|
4689 | if (typeof this._fields === 'function') {
|
4690 | this._fields = this._fields();
|
4691 | }
|
4692 |
|
4693 | return this._fields;
|
4694 | };
|
4695 |
|
4696 | _proto3.toString = function toString() {
|
4697 | return this.name;
|
4698 | };
|
4699 |
|
4700 | return GraphQLInterfaceType;
|
4701 | }();
|
4702 |
|
4703 | applyToStringTag(GraphQLInterfaceType);
|
4704 | applyToJSON(GraphQLInterfaceType);
|
4705 |
|
4706 | |
4707 |
|
4708 |
|
4709 |
|
4710 |
|
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 |
|
4726 |
|
4727 |
|
4728 |
|
4729 | var GraphQLUnionType =
|
4730 |
|
4731 | function () {
|
4732 | function GraphQLUnionType(config) {
|
4733 | _defineProperty(this, "name", void 0);
|
4734 |
|
4735 | _defineProperty(this, "description", void 0);
|
4736 |
|
4737 | _defineProperty(this, "astNode", void 0);
|
4738 |
|
4739 | _defineProperty(this, "extensionASTNodes", void 0);
|
4740 |
|
4741 | _defineProperty(this, "resolveType", void 0);
|
4742 |
|
4743 | _defineProperty(this, "_types", void 0);
|
4744 |
|
4745 | this.name = config.name;
|
4746 | this.description = config.description;
|
4747 | this.astNode = config.astNode;
|
4748 | this.extensionASTNodes = config.extensionASTNodes;
|
4749 | this.resolveType = config.resolveType;
|
4750 | this._types = defineTypes.bind(undefined, config);
|
4751 | !(typeof config.name === 'string') ? invariant(0, 'Must provide name.') : void 0;
|
4752 | !(config.resolveType == null || typeof config.resolveType === 'function') ? invariant(0, "".concat(this.name, " must provide \"resolveType\" as a function, ") + "but got: ".concat(inspect(config.resolveType), ".")) : void 0;
|
4753 | }
|
4754 |
|
4755 | var _proto4 = GraphQLUnionType.prototype;
|
4756 |
|
4757 | _proto4.getTypes = function getTypes() {
|
4758 | if (typeof this._types === 'function') {
|
4759 | this._types = this._types();
|
4760 | }
|
4761 |
|
4762 | return this._types;
|
4763 | };
|
4764 |
|
4765 | _proto4.toString = function toString() {
|
4766 | return this.name;
|
4767 | };
|
4768 |
|
4769 | return GraphQLUnionType;
|
4770 | }();
|
4771 |
|
4772 | applyToStringTag(GraphQLUnionType);
|
4773 | applyToJSON(GraphQLUnionType);
|
4774 |
|
4775 | function defineTypes(config) {
|
4776 | var types = resolveThunk(config.types) || [];
|
4777 | !Array.isArray(types) ? invariant(0, 'Must provide Array of types or a function which returns ' + "such an array for Union ".concat(config.name, ".")) : void 0;
|
4778 | return types;
|
4779 | }
|
4780 |
|
4781 | |
4782 |
|
4783 |
|
4784 |
|
4785 |
|
4786 |
|
4787 |
|
4788 |
|
4789 |
|
4790 |
|
4791 |
|
4792 |
|
4793 |
|
4794 |
|
4795 |
|
4796 |
|
4797 |
|
4798 |
|
4799 |
|
4800 |
|
4801 |
|
4802 | var GraphQLEnumType
|
4803 |
|
4804 | =
|
4805 |
|
4806 | function () {
|
4807 | function GraphQLEnumType(config
|
4808 | /* <T> */
|
4809 | ) {
|
4810 | _defineProperty(this, "name", void 0);
|
4811 |
|
4812 | _defineProperty(this, "description", void 0);
|
4813 |
|
4814 | _defineProperty(this, "astNode", void 0);
|
4815 |
|
4816 | _defineProperty(this, "extensionASTNodes", void 0);
|
4817 |
|
4818 | _defineProperty(this, "_values", void 0);
|
4819 |
|
4820 | _defineProperty(this, "_valueLookup", void 0);
|
4821 |
|
4822 | _defineProperty(this, "_nameLookup", void 0);
|
4823 |
|
4824 | this.name = config.name;
|
4825 | this.description = config.description;
|
4826 | this.astNode = config.astNode;
|
4827 | this.extensionASTNodes = config.extensionASTNodes;
|
4828 | this._values = defineEnumValues(this, config.values);
|
4829 | this._valueLookup = new Map(this._values.map(function (enumValue) {
|
4830 | return [enumValue.value, enumValue];
|
4831 | }));
|
4832 | this._nameLookup = keyMap(this._values, function (value) {
|
4833 | return value.name;
|
4834 | });
|
4835 | !(typeof config.name === 'string') ? invariant(0, 'Must provide name.') : void 0;
|
4836 | }
|
4837 |
|
4838 | var _proto5 = GraphQLEnumType.prototype;
|
4839 |
|
4840 | _proto5.getValues = function getValues() {
|
4841 | return this._values;
|
4842 | };
|
4843 |
|
4844 | _proto5.getValue = function getValue(name) {
|
4845 | return this._nameLookup[name];
|
4846 | };
|
4847 |
|
4848 | _proto5.serialize = function serialize(value
|
4849 | /* T */
|
4850 | ) {
|
4851 | var enumValue = this._valueLookup.get(value);
|
4852 |
|
4853 | if (enumValue) {
|
4854 | return enumValue.name;
|
4855 | }
|
4856 | };
|
4857 |
|
4858 | _proto5.parseValue = function parseValue(value)
|
4859 | /* T */
|
4860 | {
|
4861 | if (typeof value === 'string') {
|
4862 | var enumValue = this.getValue(value);
|
4863 |
|
4864 | if (enumValue) {
|
4865 | return enumValue.value;
|
4866 | }
|
4867 | }
|
4868 | };
|
4869 |
|
4870 | _proto5.parseLiteral = function parseLiteral(valueNode, _variables)
|
4871 | /* T */
|
4872 | {
|
4873 |
|
4874 | if (valueNode.kind === Kind.ENUM) {
|
4875 | var enumValue = this.getValue(valueNode.value);
|
4876 |
|
4877 | if (enumValue) {
|
4878 | return enumValue.value;
|
4879 | }
|
4880 | }
|
4881 | };
|
4882 |
|
4883 | _proto5.toString = function toString() {
|
4884 | return this.name;
|
4885 | };
|
4886 |
|
4887 | return GraphQLEnumType;
|
4888 | }();
|
4889 |
|
4890 | applyToStringTag(GraphQLEnumType);
|
4891 | applyToJSON(GraphQLEnumType);
|
4892 |
|
4893 | function defineEnumValues(type, valueMap
|
4894 | /* <T> */
|
4895 | ) {
|
4896 | !isPlainObj(valueMap) ? invariant(0, "".concat(type.name, " values must be an object with value names as keys.")) : void 0;
|
4897 | return Object.keys(valueMap).map(function (valueName) {
|
4898 | var value = valueMap[valueName];
|
4899 | !isPlainObj(value) ? invariant(0, "".concat(type.name, ".").concat(valueName, " must refer to an object with a \"value\" key ") + "representing an internal value but got: ".concat(inspect(value), ".")) : void 0;
|
4900 | !!value.hasOwnProperty('isDeprecated') ? invariant(0, "".concat(type.name, ".").concat(valueName, " should provide \"deprecationReason\" instead ") + 'of "isDeprecated".') : void 0;
|
4901 | return {
|
4902 | name: valueName,
|
4903 | description: value.description,
|
4904 | isDeprecated: Boolean(value.deprecationReason),
|
4905 | deprecationReason: value.deprecationReason,
|
4906 | astNode: value.astNode,
|
4907 | value: value.hasOwnProperty('value') ? value.value : valueName
|
4908 | };
|
4909 | });
|
4910 | }
|
4911 |
|
4912 | |
4913 |
|
4914 |
|
4915 |
|
4916 |
|
4917 |
|
4918 |
|
4919 |
|
4920 |
|
4921 |
|
4922 |
|
4923 |
|
4924 |
|
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 | var GraphQLInputObjectType =
|
4933 |
|
4934 | function () {
|
4935 | function GraphQLInputObjectType(config) {
|
4936 | _defineProperty(this, "name", void 0);
|
4937 |
|
4938 | _defineProperty(this, "description", void 0);
|
4939 |
|
4940 | _defineProperty(this, "astNode", void 0);
|
4941 |
|
4942 | _defineProperty(this, "extensionASTNodes", void 0);
|
4943 |
|
4944 | _defineProperty(this, "_fields", void 0);
|
4945 |
|
4946 | this.name = config.name;
|
4947 | this.description = config.description;
|
4948 | this.astNode = config.astNode;
|
4949 | this.extensionASTNodes = config.extensionASTNodes;
|
4950 | this._fields = defineInputFieldMap.bind(undefined, config);
|
4951 | !(typeof config.name === 'string') ? invariant(0, 'Must provide name.') : void 0;
|
4952 | }
|
4953 |
|
4954 | var _proto6 = GraphQLInputObjectType.prototype;
|
4955 |
|
4956 | _proto6.getFields = function getFields() {
|
4957 | if (typeof this._fields === 'function') {
|
4958 | this._fields = this._fields();
|
4959 | }
|
4960 |
|
4961 | return this._fields;
|
4962 | };
|
4963 |
|
4964 | _proto6.toString = function toString() {
|
4965 | return this.name;
|
4966 | };
|
4967 |
|
4968 | return GraphQLInputObjectType;
|
4969 | }();
|
4970 |
|
4971 | applyToStringTag(GraphQLInputObjectType);
|
4972 | applyToJSON(GraphQLInputObjectType);
|
4973 |
|
4974 | function defineInputFieldMap(config) {
|
4975 | var fieldMap = resolveThunk(config.fields) || {};
|
4976 | !isPlainObj(fieldMap) ? invariant(0, "".concat(config.name, " fields must be an object with field names as keys or a ") + 'function which returns such an object.') : void 0;
|
4977 | var resultFieldMap = Object.create(null);
|
4978 |
|
4979 | var _arr2 = Object.keys(fieldMap);
|
4980 |
|
4981 | for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
|
4982 | var fieldName = _arr2[_i2];
|
4983 |
|
4984 | var field = _objectSpread({}, fieldMap[fieldName], {
|
4985 | name: fieldName
|
4986 | });
|
4987 |
|
4988 | !!field.hasOwnProperty('resolve') ? invariant(0, "".concat(config.name, ".").concat(fieldName, " field has a resolve property, but ") + 'Input Types cannot define resolvers.') : void 0;
|
4989 | resultFieldMap[fieldName] = field;
|
4990 | }
|
4991 |
|
4992 | return resultFieldMap;
|
4993 | }
|
4994 |
|
4995 | |
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 |
|
5003 |
|
5004 |
|
5005 |
|
5006 | var isFinite$1 = Number.isFinite || function (value) {
|
5007 | return typeof value === 'number' && isFinite$1(value);
|
5008 | };
|
5009 |
|
5010 | |
5011 |
|
5012 |
|
5013 |
|
5014 |
|
5015 |
|
5016 |
|
5017 |
|
5018 |
|
5019 |
|
5020 |
|
5021 | var isInteger = Number.isInteger || function (value) {
|
5022 | return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
|
5023 | };
|
5024 |
|
5025 | |
5026 |
|
5027 |
|
5028 |
|
5029 |
|
5030 |
|
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 | var MAX_INT = 2147483647;
|
5039 | var MIN_INT = -2147483648;
|
5040 |
|
5041 | function serializeInt(value) {
|
5042 | if (typeof value === 'boolean') {
|
5043 | return value ? 1 : 0;
|
5044 | }
|
5045 |
|
5046 | var num = value;
|
5047 |
|
5048 | if (typeof value === 'string' && value !== '') {
|
5049 | num = Number(value);
|
5050 | }
|
5051 |
|
5052 | if (!isInteger(num)) {
|
5053 | throw new TypeError("Int cannot represent non-integer value: ".concat(inspect(value)));
|
5054 | }
|
5055 |
|
5056 | if (num > MAX_INT || num < MIN_INT) {
|
5057 | throw new TypeError("Int cannot represent non 32-bit signed integer value: ".concat(inspect(value)));
|
5058 | }
|
5059 |
|
5060 | return num;
|
5061 | }
|
5062 |
|
5063 | function coerceInt(value) {
|
5064 | if (!isInteger(value)) {
|
5065 | throw new TypeError("Int cannot represent non-integer value: ".concat(inspect(value)));
|
5066 | }
|
5067 |
|
5068 | if (value > MAX_INT || value < MIN_INT) {
|
5069 | throw new TypeError("Int cannot represent non 32-bit signed integer value: ".concat(inspect(value)));
|
5070 | }
|
5071 |
|
5072 | return value;
|
5073 | }
|
5074 |
|
5075 | var GraphQLInt = new GraphQLScalarType({
|
5076 | name: 'Int',
|
5077 | description: 'The `Int` scalar type represents non-fractional signed whole numeric ' + 'values. Int can represent values between -(2^31) and 2^31 - 1. ',
|
5078 | serialize: serializeInt,
|
5079 | parseValue: coerceInt,
|
5080 | parseLiteral: function parseLiteral(ast) {
|
5081 | if (ast.kind === Kind.INT) {
|
5082 | var num = parseInt(ast.value, 10);
|
5083 |
|
5084 | if (num <= MAX_INT && num >= MIN_INT) {
|
5085 | return num;
|
5086 | }
|
5087 | }
|
5088 |
|
5089 | return undefined;
|
5090 | }
|
5091 | });
|
5092 |
|
5093 | function serializeFloat(value) {
|
5094 | if (typeof value === 'boolean') {
|
5095 | return value ? 1 : 0;
|
5096 | }
|
5097 |
|
5098 | var num = value;
|
5099 |
|
5100 | if (typeof value === 'string' && value !== '') {
|
5101 | num = Number(value);
|
5102 | }
|
5103 |
|
5104 | if (!isFinite$1(num)) {
|
5105 | throw new TypeError("Float cannot represent non numeric value: ".concat(inspect(value)));
|
5106 | }
|
5107 |
|
5108 | return num;
|
5109 | }
|
5110 |
|
5111 | function coerceFloat(value) {
|
5112 | if (!isFinite$1(value)) {
|
5113 | throw new TypeError("Float cannot represent non numeric value: ".concat(inspect(value)));
|
5114 | }
|
5115 |
|
5116 | return value;
|
5117 | }
|
5118 |
|
5119 | var GraphQLFloat = new GraphQLScalarType({
|
5120 | name: 'Float',
|
5121 | description: 'The `Float` scalar type represents signed double-precision fractional ' + 'values as specified by ' + '[IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). ',
|
5122 | serialize: serializeFloat,
|
5123 | parseValue: coerceFloat,
|
5124 | parseLiteral: function parseLiteral(ast) {
|
5125 | return ast.kind === Kind.FLOAT || ast.kind === Kind.INT ? parseFloat(ast.value) : undefined;
|
5126 | }
|
5127 | });
|
5128 |
|
5129 | function serializeString(value) {
|
5130 |
|
5131 |
|
5132 |
|
5133 | var result = value && typeof value.valueOf === 'function' ? value.valueOf() : value;
|
5134 |
|
5135 |
|
5136 | if (typeof result === 'string') {
|
5137 | return result;
|
5138 | }
|
5139 |
|
5140 | if (typeof result === 'boolean') {
|
5141 | return result ? 'true' : 'false';
|
5142 | }
|
5143 |
|
5144 | if (isFinite$1(result)) {
|
5145 | return result.toString();
|
5146 | }
|
5147 |
|
5148 | throw new TypeError("String cannot represent value: ".concat(inspect(value)));
|
5149 | }
|
5150 |
|
5151 | function coerceString(value) {
|
5152 | if (typeof value !== 'string') {
|
5153 | throw new TypeError("String cannot represent a non string value: ".concat(inspect(value)));
|
5154 | }
|
5155 |
|
5156 | return value;
|
5157 | }
|
5158 |
|
5159 | var GraphQLString = new GraphQLScalarType({
|
5160 | name: 'String',
|
5161 | description: 'The `String` scalar type represents textual data, represented as UTF-8 ' + 'character sequences. The String type is most often used by GraphQL to ' + 'represent free-form human-readable text.',
|
5162 | serialize: serializeString,
|
5163 | parseValue: coerceString,
|
5164 | parseLiteral: function parseLiteral(ast) {
|
5165 | return ast.kind === Kind.STRING ? ast.value : undefined;
|
5166 | }
|
5167 | });
|
5168 |
|
5169 | function serializeBoolean(value) {
|
5170 | if (typeof value === 'boolean') {
|
5171 | return value;
|
5172 | }
|
5173 |
|
5174 | if (isFinite$1(value)) {
|
5175 | return value !== 0;
|
5176 | }
|
5177 |
|
5178 | throw new TypeError("Boolean cannot represent a non boolean value: ".concat(inspect(value)));
|
5179 | }
|
5180 |
|
5181 | function coerceBoolean(value) {
|
5182 | if (typeof value !== 'boolean') {
|
5183 | throw new TypeError("Boolean cannot represent a non boolean value: ".concat(inspect(value)));
|
5184 | }
|
5185 |
|
5186 | return value;
|
5187 | }
|
5188 |
|
5189 | var GraphQLBoolean = new GraphQLScalarType({
|
5190 | name: 'Boolean',
|
5191 | description: 'The `Boolean` scalar type represents `true` or `false`.',
|
5192 | serialize: serializeBoolean,
|
5193 | parseValue: coerceBoolean,
|
5194 | parseLiteral: function parseLiteral(ast) {
|
5195 | return ast.kind === Kind.BOOLEAN ? ast.value : undefined;
|
5196 | }
|
5197 | });
|
5198 |
|
5199 | function serializeID(value) {
|
5200 |
|
5201 |
|
5202 | var result = value && typeof value.valueOf === 'function' ? value.valueOf() : value;
|
5203 |
|
5204 | if (typeof result === 'string') {
|
5205 | return result;
|
5206 | }
|
5207 |
|
5208 | if (isInteger(result)) {
|
5209 | return String(result);
|
5210 | }
|
5211 |
|
5212 | throw new TypeError("ID cannot represent value: ".concat(inspect(value)));
|
5213 | }
|
5214 |
|
5215 | function coerceID(value) {
|
5216 | if (typeof value === 'string') {
|
5217 | return value;
|
5218 | }
|
5219 |
|
5220 | if (isInteger(value)) {
|
5221 | return value.toString();
|
5222 | }
|
5223 |
|
5224 | throw new TypeError("ID cannot represent value: ".concat(inspect(value)));
|
5225 | }
|
5226 |
|
5227 | var GraphQLID = new GraphQLScalarType({
|
5228 | name: 'ID',
|
5229 | description: 'The `ID` scalar type represents a unique identifier, often used to ' + 'refetch an object or as key for a cache. The ID type appears in a JSON ' + 'response as a String; however, it is not intended to be human-readable. ' + 'When expected as an input type, any string (such as `"4"`) or integer ' + '(such as `4`) input value will be accepted as an ID.',
|
5230 | serialize: serializeID,
|
5231 | parseValue: coerceID,
|
5232 | parseLiteral: function parseLiteral(ast) {
|
5233 | return ast.kind === Kind.STRING || ast.kind === Kind.INT ? ast.value : undefined;
|
5234 | }
|
5235 | });
|
5236 |
|
5237 | |
5238 |
|
5239 |
|
5240 |
|
5241 |
|
5242 |
|
5243 |
|
5244 |
|
5245 |
|
5246 | |
5247 |
|
5248 |
|
5249 | var DirectiveLocation = Object.freeze({
|
5250 |
|
5251 | QUERY: 'QUERY',
|
5252 | MUTATION: 'MUTATION',
|
5253 | SUBSCRIPTION: 'SUBSCRIPTION',
|
5254 | FIELD: 'FIELD',
|
5255 | FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION',
|
5256 | FRAGMENT_SPREAD: 'FRAGMENT_SPREAD',
|
5257 | INLINE_FRAGMENT: 'INLINE_FRAGMENT',
|
5258 | VARIABLE_DEFINITION: 'VARIABLE_DEFINITION',
|
5259 |
|
5260 | SCHEMA: 'SCHEMA',
|
5261 | SCALAR: 'SCALAR',
|
5262 | OBJECT: 'OBJECT',
|
5263 | FIELD_DEFINITION: 'FIELD_DEFINITION',
|
5264 | ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION',
|
5265 | INTERFACE: 'INTERFACE',
|
5266 | UNION: 'UNION',
|
5267 | ENUM: 'ENUM',
|
5268 | ENUM_VALUE: 'ENUM_VALUE',
|
5269 | INPUT_OBJECT: 'INPUT_OBJECT',
|
5270 | INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION'
|
5271 | });
|
5272 | |
5273 |
|
5274 |
|
5275 |
|
5276 | function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
5277 | |
5278 |
|
5279 |
|
5280 |
|
5281 |
|
5282 | function isDirective(directive) {
|
5283 | return instanceOf(directive, GraphQLDirective);
|
5284 | }
|
5285 | |
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 | var GraphQLDirective =
|
5291 |
|
5292 | function () {
|
5293 | function GraphQLDirective(config) {
|
5294 | _defineProperty$1(this, "name", void 0);
|
5295 |
|
5296 | _defineProperty$1(this, "description", void 0);
|
5297 |
|
5298 | _defineProperty$1(this, "locations", void 0);
|
5299 |
|
5300 | _defineProperty$1(this, "args", void 0);
|
5301 |
|
5302 | _defineProperty$1(this, "astNode", void 0);
|
5303 |
|
5304 | this.name = config.name;
|
5305 | this.description = config.description;
|
5306 | this.locations = config.locations;
|
5307 | this.astNode = config.astNode;
|
5308 | !config.name ? invariant(0, 'Directive must be named.') : void 0;
|
5309 | !Array.isArray(config.locations) ? invariant(0, 'Must provide locations for directive.') : void 0;
|
5310 | var args = config.args;
|
5311 |
|
5312 | if (!args) {
|
5313 | this.args = [];
|
5314 | } else {
|
5315 | !!Array.isArray(args) ? invariant(0, "@".concat(config.name, " args must be an object with argument names as keys.")) : void 0;
|
5316 | this.args = Object.keys(args).map(function (argName) {
|
5317 | var arg = args[argName];
|
5318 | return {
|
5319 | name: argName,
|
5320 | description: arg.description === undefined ? null : arg.description,
|
5321 | type: arg.type,
|
5322 | defaultValue: arg.defaultValue,
|
5323 | astNode: arg.astNode
|
5324 | };
|
5325 | });
|
5326 | }
|
5327 | }
|
5328 |
|
5329 | var _proto = GraphQLDirective.prototype;
|
5330 |
|
5331 | _proto.toString = function toString() {
|
5332 | return '@' + this.name;
|
5333 | };
|
5334 |
|
5335 | return GraphQLDirective;
|
5336 | }();
|
5337 |
|
5338 | applyToStringTag(GraphQLDirective);
|
5339 | applyToJSON(GraphQLDirective);
|
5340 |
|
5341 | |
5342 |
|
5343 |
|
5344 | var GraphQLIncludeDirective = new GraphQLDirective({
|
5345 | name: 'include',
|
5346 | description: 'Directs the executor to include this field or fragment only when ' + 'the `if` argument is true.',
|
5347 | locations: [DirectiveLocation.FIELD, DirectiveLocation.FRAGMENT_SPREAD, DirectiveLocation.INLINE_FRAGMENT],
|
5348 | args: {
|
5349 | if: {
|
5350 | type: GraphQLNonNull(GraphQLBoolean),
|
5351 | description: 'Included when true.'
|
5352 | }
|
5353 | }
|
5354 | });
|
5355 | |
5356 |
|
5357 |
|
5358 |
|
5359 | var GraphQLSkipDirective = new GraphQLDirective({
|
5360 | name: 'skip',
|
5361 | description: 'Directs the executor to skip this field or fragment when the `if` ' + 'argument is true.',
|
5362 | locations: [DirectiveLocation.FIELD, DirectiveLocation.FRAGMENT_SPREAD, DirectiveLocation.INLINE_FRAGMENT],
|
5363 | args: {
|
5364 | if: {
|
5365 | type: GraphQLNonNull(GraphQLBoolean),
|
5366 | description: 'Skipped when true.'
|
5367 | }
|
5368 | }
|
5369 | });
|
5370 | |
5371 |
|
5372 |
|
5373 |
|
5374 | var DEFAULT_DEPRECATION_REASON = 'No longer supported';
|
5375 | |
5376 |
|
5377 |
|
5378 |
|
5379 | var GraphQLDeprecatedDirective = new GraphQLDirective({
|
5380 | name: 'deprecated',
|
5381 | description: 'Marks an element of a GraphQL schema as no longer supported.',
|
5382 | locations: [DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.ENUM_VALUE],
|
5383 | args: {
|
5384 | reason: {
|
5385 | type: GraphQLString,
|
5386 | description: 'Explains why this element was deprecated, usually also including a ' + 'suggestion for how to access supported similar data. Formatted using ' + 'the Markdown syntax (as specified by [CommonMark](https://commonmark.org/).',
|
5387 | defaultValue: DEFAULT_DEPRECATION_REASON
|
5388 | }
|
5389 | }
|
5390 | });
|
5391 | |
5392 |
|
5393 |
|
5394 |
|
5395 | var specifiedDirectives = [GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDeprecatedDirective];
|
5396 |
|
5397 | |
5398 |
|
5399 |
|
5400 |
|
5401 |
|
5402 |
|
5403 |
|
5404 |
|
5405 |
|
5406 |
|
5407 |
|
5408 | var objectValues = Object.values || function (obj) {
|
5409 | return Object.keys(obj).map(function (key) {
|
5410 | return obj[key];
|
5411 | });
|
5412 | };
|
5413 |
|
5414 | |
5415 |
|
5416 |
|
5417 |
|
5418 |
|
5419 |
|
5420 |
|
5421 |
|
5422 |
|
5423 |
|
5424 |
|
5425 | |
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 |
|
5432 |
|
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 | |
5438 |
|
5439 |
|
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 |
|
5448 |
|
5449 |
|
5450 |
|
5451 |
|
5452 |
|
5453 | var SYMBOL = typeof Symbol === 'function' ? Symbol : void 0;
|
5454 |
|
5455 |
|
5456 | var SYMBOL_ITERATOR = SYMBOL && SYMBOL.iterator;
|
5457 |
|
5458 | |
5459 |
|
5460 |
|
5461 |
|
5462 |
|
5463 |
|
5464 |
|
5465 |
|
5466 |
|
5467 |
|
5468 |
|
5469 |
|
5470 |
|
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 |
|
5476 | function isIterable(obj) {
|
5477 | return !!getIteratorMethod(obj)
|
5478 | }
|
5479 |
|
5480 | |
5481 |
|
5482 |
|
5483 |
|
5484 |
|
5485 |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 |
|
5494 |
|
5495 |
|
5496 |
|
5497 |
|
5498 | function isArrayLike(obj) {
|
5499 | var length = obj != null && obj.length;
|
5500 | return typeof length === 'number' && length >= 0 && length % 1 === 0
|
5501 | }
|
5502 |
|
5503 | |
5504 |
|
5505 |
|
5506 |
|
5507 |
|
5508 |
|
5509 |
|
5510 |
|
5511 |
|
5512 |
|
5513 |
|
5514 |
|
5515 |
|
5516 |
|
5517 |
|
5518 |
|
5519 |
|
5520 |
|
5521 |
|
5522 |
|
5523 |
|
5524 |
|
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 | function isCollection(obj) {
|
5536 | return Object(obj) === obj && (isArrayLike(obj) || isIterable(obj))
|
5537 | }
|
5538 |
|
5539 | |
5540 |
|
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 |
|
5548 |
|
5549 |
|
5550 |
|
5551 |
|
5552 |
|
5553 |
|
5554 |
|
5555 |
|
5556 |
|
5557 | |
5558 |
|
5559 |
|
5560 | function getIterator(iterable) {
|
5561 | var method = getIteratorMethod(iterable);
|
5562 | if (method) {
|
5563 | return method.call(iterable)
|
5564 | }
|
5565 | }
|
5566 |
|
5567 | |
5568 |
|
5569 |
|
5570 |
|
5571 |
|
5572 |
|
5573 |
|
5574 |
|
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 |
|
5587 |
|
5588 | |
5589 |
|
5590 |
|
5591 | function getIteratorMethod(iterable) {
|
5592 | if (iterable != null) {
|
5593 | var method =
|
5594 | (SYMBOL_ITERATOR && iterable[SYMBOL_ITERATOR]) || iterable['@@iterator'];
|
5595 | if (typeof method === 'function') {
|
5596 | return method
|
5597 | }
|
5598 | }
|
5599 | }
|
5600 |
|
5601 | |
5602 |
|
5603 |
|
5604 |
|
5605 |
|
5606 |
|
5607 |
|
5608 |
|
5609 |
|
5610 |
|
5611 |
|
5612 |
|
5613 |
|
5614 |
|
5615 |
|
5616 |
|
5617 |
|
5618 |
|
5619 |
|
5620 |
|
5621 |
|
5622 |
|
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 |
|
5628 |
|
5629 |
|
5630 |
|
5631 |
|
5632 |
|
5633 |
|
5634 |
|
5635 |
|
5636 |
|
5637 |
|
5638 |
|
5639 |
|
5640 |
|
5641 |
|
5642 |
|
5643 |
|
5644 |
|
5645 |
|
5646 | |
5647 |
|
5648 |
|
5649 |
|
5650 |
|
5651 |
|
5652 |
|
5653 |
|
5654 |
|
5655 |
|
5656 |
|
5657 | function forEach(collection, callback, thisArg) {
|
5658 | if (collection != null) {
|
5659 | if (typeof collection.forEach === 'function') {
|
5660 | return collection.forEach(callback, thisArg)
|
5661 | }
|
5662 | var i = 0;
|
5663 | var iterator = getIterator(collection);
|
5664 | if (iterator) {
|
5665 | var step;
|
5666 | while (!(step = iterator.next()).done) {
|
5667 | callback.call(thisArg, step.value, i++, collection);
|
5668 |
|
5669 |
|
5670 |
|
5671 | if (i > 9999999) {
|
5672 | throw new TypeError('Near-infinite iteration.')
|
5673 | }
|
5674 | }
|
5675 | } else if (isArrayLike(collection)) {
|
5676 | for (; i < collection.length; i++) {
|
5677 | if (collection.hasOwnProperty(i)) {
|
5678 | callback.call(thisArg, collection[i], i, collection);
|
5679 | }
|
5680 | }
|
5681 | }
|
5682 | }
|
5683 | }
|
5684 |
|
5685 |
|
5686 |
|
5687 |
|
5688 |
|
5689 |
|
5690 |
|
5691 | |
5692 |
|
5693 |
|
5694 |
|
5695 |
|
5696 |
|
5697 |
|
5698 |
|
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 | |
5709 |
|
5710 |
|
5711 |
|
5712 |
|
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 | var SYMBOL_ASYNC_ITERATOR = SYMBOL && SYMBOL.asyncIterator;
|
5727 |
|
5728 | |
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 |
|
5734 |
|
5735 |
|
5736 |
|
5737 | |
5738 |
|
5739 |
|
5740 | function isNullish(value) {
|
5741 | return value === null || value === undefined || value !== value;
|
5742 | }
|
5743 |
|
5744 | function _typeof$2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
|
5745 | |
5746 |
|
5747 |
|
5748 |
|
5749 |
|
5750 |
|
5751 |
|
5752 |
|
5753 |
|
5754 |
|
5755 |
|
5756 |
|
5757 |
|
5758 |
|
5759 |
|
5760 |
|
5761 |
|
5762 |
|
5763 | function astFromValue(value, type) {
|
5764 | if (isNonNullType(type)) {
|
5765 | var astValue = astFromValue(value, type.ofType);
|
5766 |
|
5767 | if (astValue && astValue.kind === Kind.NULL) {
|
5768 | return null;
|
5769 | }
|
5770 |
|
5771 | return astValue;
|
5772 | }
|
5773 |
|
5774 |
|
5775 | if (value === null) {
|
5776 | return {
|
5777 | kind: Kind.NULL
|
5778 | };
|
5779 | }
|
5780 |
|
5781 |
|
5782 | if (isInvalid(value)) {
|
5783 | return null;
|
5784 | }
|
5785 |
|
5786 |
|
5787 |
|
5788 | if (isListType(type)) {
|
5789 | var itemType = type.ofType;
|
5790 |
|
5791 | if (isCollection(value)) {
|
5792 | var valuesNodes = [];
|
5793 | forEach(value, function (item) {
|
5794 | var itemNode = astFromValue(item, itemType);
|
5795 |
|
5796 | if (itemNode) {
|
5797 | valuesNodes.push(itemNode);
|
5798 | }
|
5799 | });
|
5800 | return {
|
5801 | kind: Kind.LIST,
|
5802 | values: valuesNodes
|
5803 | };
|
5804 | }
|
5805 |
|
5806 | return astFromValue(value, itemType);
|
5807 | }
|
5808 |
|
5809 |
|
5810 |
|
5811 | if (isInputObjectType(type)) {
|
5812 | if (value === null || _typeof$2(value) !== 'object') {
|
5813 | return null;
|
5814 | }
|
5815 |
|
5816 | var fields = objectValues(type.getFields());
|
5817 | var fieldNodes = [];
|
5818 | var _iteratorNormalCompletion = true;
|
5819 | var _didIteratorError = false;
|
5820 | var _iteratorError = undefined;
|
5821 |
|
5822 | try {
|
5823 | for (var _iterator = fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
5824 | var field = _step.value;
|
5825 | var fieldValue = astFromValue(value[field.name], field.type);
|
5826 |
|
5827 | if (fieldValue) {
|
5828 | fieldNodes.push({
|
5829 | kind: Kind.OBJECT_FIELD,
|
5830 | name: {
|
5831 | kind: Kind.NAME,
|
5832 | value: field.name
|
5833 | },
|
5834 | value: fieldValue
|
5835 | });
|
5836 | }
|
5837 | }
|
5838 | } catch (err) {
|
5839 | _didIteratorError = true;
|
5840 | _iteratorError = err;
|
5841 | } finally {
|
5842 | try {
|
5843 | if (!_iteratorNormalCompletion && _iterator.return != null) {
|
5844 | _iterator.return();
|
5845 | }
|
5846 | } finally {
|
5847 | if (_didIteratorError) {
|
5848 | throw _iteratorError;
|
5849 | }
|
5850 | }
|
5851 | }
|
5852 |
|
5853 | return {
|
5854 | kind: Kind.OBJECT,
|
5855 | fields: fieldNodes
|
5856 | };
|
5857 | }
|
5858 |
|
5859 | if (isScalarType(type) || isEnumType(type)) {
|
5860 |
|
5861 |
|
5862 | var serialized = type.serialize(value);
|
5863 |
|
5864 | if (isNullish(serialized)) {
|
5865 | return null;
|
5866 | }
|
5867 |
|
5868 |
|
5869 | if (typeof serialized === 'boolean') {
|
5870 | return {
|
5871 | kind: Kind.BOOLEAN,
|
5872 | value: serialized
|
5873 | };
|
5874 | }
|
5875 |
|
5876 |
|
5877 | if (typeof serialized === 'number') {
|
5878 | var stringNum = String(serialized);
|
5879 | return integerStringRegExp.test(stringNum) ? {
|
5880 | kind: Kind.INT,
|
5881 | value: stringNum
|
5882 | } : {
|
5883 | kind: Kind.FLOAT,
|
5884 | value: stringNum
|
5885 | };
|
5886 | }
|
5887 |
|
5888 | if (typeof serialized === 'string') {
|
5889 |
|
5890 | if (isEnumType(type)) {
|
5891 | return {
|
5892 | kind: Kind.ENUM,
|
5893 | value: serialized
|
5894 | };
|
5895 | }
|
5896 |
|
5897 |
|
5898 | if (type === GraphQLID && integerStringRegExp.test(serialized)) {
|
5899 | return {
|
5900 | kind: Kind.INT,
|
5901 | value: serialized
|
5902 | };
|
5903 | }
|
5904 |
|
5905 | return {
|
5906 | kind: Kind.STRING,
|
5907 | value: serialized
|
5908 | };
|
5909 | }
|
5910 |
|
5911 | throw new TypeError("Cannot convert value to AST: ".concat(inspect(serialized)));
|
5912 | }
|
5913 |
|
5914 |
|
5915 |
|
5916 | throw new Error("Unknown type: ".concat(type, "."));
|
5917 | }
|
5918 | |
5919 |
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 | var integerStringRegExp = /^-?(0|[1-9][0-9]*)$/;
|
5925 |
|
5926 | |
5927 |
|
5928 |
|
5929 |
|
5930 |
|
5931 |
|
5932 |
|
5933 |
|
5934 | var QueryDocumentKeys = {
|
5935 | Name: [],
|
5936 | Document: ['definitions'],
|
5937 | OperationDefinition: ['name', 'variableDefinitions', 'directives', 'selectionSet'],
|
5938 | VariableDefinition: ['variable', 'type', 'defaultValue', 'directives'],
|
5939 | Variable: ['name'],
|
5940 | SelectionSet: ['selections'],
|
5941 | Field: ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
|
5942 | Argument: ['name', 'value'],
|
5943 | FragmentSpread: ['name', 'directives'],
|
5944 | InlineFragment: ['typeCondition', 'directives', 'selectionSet'],
|
5945 | FragmentDefinition: ['name',
|
5946 |
|
5947 | 'variableDefinitions', 'typeCondition', 'directives', 'selectionSet'],
|
5948 | IntValue: [],
|
5949 | FloatValue: [],
|
5950 | StringValue: [],
|
5951 | BooleanValue: [],
|
5952 | NullValue: [],
|
5953 | EnumValue: [],
|
5954 | ListValue: ['values'],
|
5955 | ObjectValue: ['fields'],
|
5956 | ObjectField: ['name', 'value'],
|
5957 | Directive: ['name', 'arguments'],
|
5958 | NamedType: ['name'],
|
5959 | ListType: ['type'],
|
5960 | NonNullType: ['type'],
|
5961 | SchemaDefinition: ['directives', 'operationTypes'],
|
5962 | OperationTypeDefinition: ['type'],
|
5963 | ScalarTypeDefinition: ['description', 'name', 'directives'],
|
5964 | ObjectTypeDefinition: ['description', 'name', 'interfaces', 'directives', 'fields'],
|
5965 | FieldDefinition: ['description', 'name', 'arguments', 'type', 'directives'],
|
5966 | InputValueDefinition: ['description', 'name', 'type', 'defaultValue', 'directives'],
|
5967 | InterfaceTypeDefinition: ['description', 'name', 'directives', 'fields'],
|
5968 | UnionTypeDefinition: ['description', 'name', 'directives', 'types'],
|
5969 | EnumTypeDefinition: ['description', 'name', 'directives', 'values'],
|
5970 | EnumValueDefinition: ['description', 'name', 'directives'],
|
5971 | InputObjectTypeDefinition: ['description', 'name', 'directives', 'fields'],
|
5972 | DirectiveDefinition: ['description', 'name', 'arguments', 'locations'],
|
5973 | SchemaExtension: ['directives', 'operationTypes'],
|
5974 | ScalarTypeExtension: ['name', 'directives'],
|
5975 | ObjectTypeExtension: ['name', 'interfaces', 'directives', 'fields'],
|
5976 | InterfaceTypeExtension: ['name', 'directives', 'fields'],
|
5977 | UnionTypeExtension: ['name', 'directives', 'types'],
|
5978 | EnumTypeExtension: ['name', 'directives', 'values'],
|
5979 | InputObjectTypeExtension: ['name', 'directives', 'fields']
|
5980 | };
|
5981 | var BREAK = {};
|
5982 | |
5983 |
|
5984 |
|
5985 |
|
5986 |
|
5987 |
|
5988 |
|
5989 |
|
5990 |
|
5991 |
|
5992 |
|
5993 |
|
5994 |
|
5995 |
|
5996 |
|
5997 |
|
5998 |
|
5999 |
|
6000 |
|
6001 |
|
6002 |
|
6003 |
|
6004 |
|
6005 |
|
6006 |
|
6007 |
|
6008 |
|
6009 |
|
6010 |
|
6011 |
|
6012 |
|
6013 |
|
6014 |
|
6015 |
|
6016 |
|
6017 |
|
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 |
|
6027 |
|
6028 |
|
6029 |
|
6030 |
|
6031 |
|
6032 |
|
6033 |
|
6034 |
|
6035 |
|
6036 |
|
6037 |
|
6038 |
|
6039 |
|
6040 |
|
6041 |
|
6042 |
|
6043 |
|
6044 |
|
6045 |
|
6046 |
|
6047 |
|
6048 |
|
6049 |
|
6050 |
|
6051 |
|
6052 |
|
6053 |
|
6054 |
|
6055 |
|
6056 |
|
6057 |
|
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 |
|
6067 |
|
6068 |
|
6069 | function visit(root, visitor) {
|
6070 | var visitorKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : QueryDocumentKeys;
|
6071 |
|
6072 |
|
6073 | var stack = undefined;
|
6074 | var inArray = Array.isArray(root);
|
6075 | var keys = [root];
|
6076 | var index = -1;
|
6077 | var edits = [];
|
6078 | var node = undefined;
|
6079 | var key = undefined;
|
6080 | var parent = undefined;
|
6081 | var path = [];
|
6082 | var ancestors = [];
|
6083 | var newRoot = root;
|
6084 |
|
6085 |
|
6086 | do {
|
6087 | index++;
|
6088 | var isLeaving = index === keys.length;
|
6089 | var isEdited = isLeaving && edits.length !== 0;
|
6090 |
|
6091 | if (isLeaving) {
|
6092 | key = ancestors.length === 0 ? undefined : path[path.length - 1];
|
6093 | node = parent;
|
6094 | parent = ancestors.pop();
|
6095 |
|
6096 | if (isEdited) {
|
6097 | if (inArray) {
|
6098 | node = node.slice();
|
6099 | } else {
|
6100 | var clone = {};
|
6101 |
|
6102 | for (var k in node) {
|
6103 | if (node.hasOwnProperty(k)) {
|
6104 | clone[k] = node[k];
|
6105 | }
|
6106 | }
|
6107 |
|
6108 | node = clone;
|
6109 | }
|
6110 |
|
6111 | var editOffset = 0;
|
6112 |
|
6113 | for (var ii = 0; ii < edits.length; ii++) {
|
6114 | var editKey = edits[ii][0];
|
6115 | var editValue = edits[ii][1];
|
6116 |
|
6117 | if (inArray) {
|
6118 | editKey -= editOffset;
|
6119 | }
|
6120 |
|
6121 | if (inArray && editValue === null) {
|
6122 | node.splice(editKey, 1);
|
6123 | editOffset++;
|
6124 | } else {
|
6125 | node[editKey] = editValue;
|
6126 | }
|
6127 | }
|
6128 | }
|
6129 |
|
6130 | index = stack.index;
|
6131 | keys = stack.keys;
|
6132 | edits = stack.edits;
|
6133 | inArray = stack.inArray;
|
6134 | stack = stack.prev;
|
6135 | } else {
|
6136 | key = parent ? inArray ? index : keys[index] : undefined;
|
6137 | node = parent ? parent[key] : newRoot;
|
6138 |
|
6139 | if (node === null || node === undefined) {
|
6140 | continue;
|
6141 | }
|
6142 |
|
6143 | if (parent) {
|
6144 | path.push(key);
|
6145 | }
|
6146 | }
|
6147 |
|
6148 | var result = void 0;
|
6149 |
|
6150 | if (!Array.isArray(node)) {
|
6151 | if (!isNode(node)) {
|
6152 | throw new Error('Invalid AST Node: ' + inspect(node));
|
6153 | }
|
6154 |
|
6155 | var visitFn = getVisitFn(visitor, node.kind, isLeaving);
|
6156 |
|
6157 | if (visitFn) {
|
6158 | result = visitFn.call(visitor, node, key, parent, path, ancestors);
|
6159 |
|
6160 | if (result === BREAK) {
|
6161 | break;
|
6162 | }
|
6163 |
|
6164 | if (result === false) {
|
6165 | if (!isLeaving) {
|
6166 | path.pop();
|
6167 | continue;
|
6168 | }
|
6169 | } else if (result !== undefined) {
|
6170 | edits.push([key, result]);
|
6171 |
|
6172 | if (!isLeaving) {
|
6173 | if (isNode(result)) {
|
6174 | node = result;
|
6175 | } else {
|
6176 | path.pop();
|
6177 | continue;
|
6178 | }
|
6179 | }
|
6180 | }
|
6181 | }
|
6182 | }
|
6183 |
|
6184 | if (result === undefined && isEdited) {
|
6185 | edits.push([key, node]);
|
6186 | }
|
6187 |
|
6188 | if (isLeaving) {
|
6189 | path.pop();
|
6190 | } else {
|
6191 | stack = {
|
6192 | inArray: inArray,
|
6193 | index: index,
|
6194 | keys: keys,
|
6195 | edits: edits,
|
6196 | prev: stack
|
6197 | };
|
6198 | inArray = Array.isArray(node);
|
6199 | keys = inArray ? node : visitorKeys[node.kind] || [];
|
6200 | index = -1;
|
6201 | edits = [];
|
6202 |
|
6203 | if (parent) {
|
6204 | ancestors.push(parent);
|
6205 | }
|
6206 |
|
6207 | parent = node;
|
6208 | }
|
6209 | } while (stack !== undefined);
|
6210 |
|
6211 | if (edits.length !== 0) {
|
6212 | newRoot = edits[edits.length - 1][1];
|
6213 | }
|
6214 |
|
6215 | return newRoot;
|
6216 | }
|
6217 |
|
6218 | function isNode(maybeNode) {
|
6219 | return Boolean(maybeNode && typeof maybeNode.kind === 'string');
|
6220 | }
|
6221 | |
6222 |
|
6223 |
|
6224 |
|
6225 |
|
6226 | function visitWithTypeInfo(typeInfo, visitor) {
|
6227 | return {
|
6228 | enter: function enter(node) {
|
6229 | typeInfo.enter(node);
|
6230 | var fn = getVisitFn(visitor, node.kind,
|
6231 |
|
6232 | false);
|
6233 |
|
6234 | if (fn) {
|
6235 | var result = fn.apply(visitor, arguments);
|
6236 |
|
6237 | if (result !== undefined) {
|
6238 | typeInfo.leave(node);
|
6239 |
|
6240 | if (isNode(result)) {
|
6241 | typeInfo.enter(result);
|
6242 | }
|
6243 | }
|
6244 |
|
6245 | return result;
|
6246 | }
|
6247 | },
|
6248 | leave: function leave(node) {
|
6249 | var fn = getVisitFn(visitor, node.kind,
|
6250 |
|
6251 | true);
|
6252 | var result;
|
6253 |
|
6254 | if (fn) {
|
6255 | result = fn.apply(visitor, arguments);
|
6256 | }
|
6257 |
|
6258 | typeInfo.leave(node);
|
6259 | return result;
|
6260 | }
|
6261 | };
|
6262 | }
|
6263 | |
6264 |
|
6265 |
|
6266 |
|
6267 |
|
6268 | function getVisitFn(visitor, kind, isLeaving) {
|
6269 | var kindVisitor = visitor[kind];
|
6270 |
|
6271 | if (kindVisitor) {
|
6272 | if (!isLeaving && typeof kindVisitor === 'function') {
|
6273 |
|
6274 | return kindVisitor;
|
6275 | }
|
6276 |
|
6277 | var kindSpecificVisitor = isLeaving ? kindVisitor.leave : kindVisitor.enter;
|
6278 |
|
6279 | if (typeof kindSpecificVisitor === 'function') {
|
6280 |
|
6281 | return kindSpecificVisitor;
|
6282 | }
|
6283 | } else {
|
6284 | var specificVisitor = isLeaving ? visitor.leave : visitor.enter;
|
6285 |
|
6286 | if (specificVisitor) {
|
6287 | if (typeof specificVisitor === 'function') {
|
6288 |
|
6289 | return specificVisitor;
|
6290 | }
|
6291 |
|
6292 | var specificKindVisitor = specificVisitor[kind];
|
6293 |
|
6294 | if (typeof specificKindVisitor === 'function') {
|
6295 |
|
6296 | return specificKindVisitor;
|
6297 | }
|
6298 | }
|
6299 | }
|
6300 | }
|
6301 |
|
6302 | |
6303 |
|
6304 |
|
6305 |
|
6306 |
|
6307 |
|
6308 | |
6309 |
|
6310 |
|
6311 |
|
6312 |
|
6313 | function print(ast) {
|
6314 | return visit(ast, {
|
6315 | leave: printDocASTReducer
|
6316 | });
|
6317 | }
|
6318 | var printDocASTReducer = {
|
6319 | Name: function Name(node) {
|
6320 | return node.value;
|
6321 | },
|
6322 | Variable: function Variable(node) {
|
6323 | return '$' + node.name;
|
6324 | },
|
6325 |
|
6326 | Document: function Document(node) {
|
6327 | return join(node.definitions, '\n\n') + '\n';
|
6328 | },
|
6329 | OperationDefinition: function OperationDefinition(node) {
|
6330 | var op = node.operation;
|
6331 | var name = node.name;
|
6332 | var varDefs = wrap$1('(', join(node.variableDefinitions, ', '), ')');
|
6333 | var directives = join(node.directives, ' ');
|
6334 | var selectionSet = node.selectionSet;
|
6335 |
|
6336 |
|
6337 | return !name && !directives && !varDefs && op === 'query' ? selectionSet : join([op, join([name, varDefs]), directives, selectionSet], ' ');
|
6338 | },
|
6339 | VariableDefinition: function VariableDefinition(_ref) {
|
6340 | var variable = _ref.variable,
|
6341 | type = _ref.type,
|
6342 | defaultValue = _ref.defaultValue,
|
6343 | directives = _ref.directives;
|
6344 | return variable + ': ' + type + wrap$1(' = ', defaultValue) + wrap$1(' ', join(directives, ' '));
|
6345 | },
|
6346 | SelectionSet: function SelectionSet(_ref2) {
|
6347 | var selections = _ref2.selections;
|
6348 | return block(selections);
|
6349 | },
|
6350 | Field: function Field(_ref3) {
|
6351 | var alias = _ref3.alias,
|
6352 | name = _ref3.name,
|
6353 | args = _ref3.arguments,
|
6354 | directives = _ref3.directives,
|
6355 | selectionSet = _ref3.selectionSet;
|
6356 | return join([wrap$1('', alias, ': ') + name + wrap$1('(', join(args, ', '), ')'), join(directives, ' '), selectionSet], ' ');
|
6357 | },
|
6358 | Argument: function Argument(_ref4) {
|
6359 | var name = _ref4.name,
|
6360 | value = _ref4.value;
|
6361 | return name + ': ' + value;
|
6362 | },
|
6363 |
|
6364 | FragmentSpread: function FragmentSpread(_ref5) {
|
6365 | var name = _ref5.name,
|
6366 | directives = _ref5.directives;
|
6367 | return '...' + name + wrap$1(' ', join(directives, ' '));
|
6368 | },
|
6369 | InlineFragment: function InlineFragment(_ref6) {
|
6370 | var typeCondition = _ref6.typeCondition,
|
6371 | directives = _ref6.directives,
|
6372 | selectionSet = _ref6.selectionSet;
|
6373 | return join(['...', wrap$1('on ', typeCondition), join(directives, ' '), selectionSet], ' ');
|
6374 | },
|
6375 | FragmentDefinition: function FragmentDefinition(_ref7) {
|
6376 | var name = _ref7.name,
|
6377 | typeCondition = _ref7.typeCondition,
|
6378 | variableDefinitions = _ref7.variableDefinitions,
|
6379 | directives = _ref7.directives,
|
6380 | selectionSet = _ref7.selectionSet;
|
6381 | return (
|
6382 |
|
6383 | "fragment ".concat(name).concat(wrap$1('(', join(variableDefinitions, ', '), ')'), " ") + "on ".concat(typeCondition, " ").concat(wrap$1('', join(directives, ' '), ' ')) + selectionSet
|
6384 | );
|
6385 | },
|
6386 |
|
6387 | IntValue: function IntValue(_ref8) {
|
6388 | var value = _ref8.value;
|
6389 | return value;
|
6390 | },
|
6391 | FloatValue: function FloatValue(_ref9) {
|
6392 | var value = _ref9.value;
|
6393 | return value;
|
6394 | },
|
6395 | StringValue: function StringValue(_ref10, key) {
|
6396 | var value = _ref10.value,
|
6397 | isBlockString = _ref10.block;
|
6398 | return isBlockString ? printBlockString(value, key === 'description') : JSON.stringify(value);
|
6399 | },
|
6400 | BooleanValue: function BooleanValue(_ref11) {
|
6401 | var value = _ref11.value;
|
6402 | return value ? 'true' : 'false';
|
6403 | },
|
6404 | NullValue: function NullValue() {
|
6405 | return 'null';
|
6406 | },
|
6407 | EnumValue: function EnumValue(_ref12) {
|
6408 | var value = _ref12.value;
|
6409 | return value;
|
6410 | },
|
6411 | ListValue: function ListValue(_ref13) {
|
6412 | var values = _ref13.values;
|
6413 | return '[' + join(values, ', ') + ']';
|
6414 | },
|
6415 | ObjectValue: function ObjectValue(_ref14) {
|
6416 | var fields = _ref14.fields;
|
6417 | return '{' + join(fields, ', ') + '}';
|
6418 | },
|
6419 | ObjectField: function ObjectField(_ref15) {
|
6420 | var name = _ref15.name,
|
6421 | value = _ref15.value;
|
6422 | return name + ': ' + value;
|
6423 | },
|
6424 |
|
6425 | Directive: function Directive(_ref16) {
|
6426 | var name = _ref16.name,
|
6427 | args = _ref16.arguments;
|
6428 | return '@' + name + wrap$1('(', join(args, ', '), ')');
|
6429 | },
|
6430 |
|
6431 | NamedType: function NamedType(_ref17) {
|
6432 | var name = _ref17.name;
|
6433 | return name;
|
6434 | },
|
6435 | ListType: function ListType(_ref18) {
|
6436 | var type = _ref18.type;
|
6437 | return '[' + type + ']';
|
6438 | },
|
6439 | NonNullType: function NonNullType(_ref19) {
|
6440 | var type = _ref19.type;
|
6441 | return type + '!';
|
6442 | },
|
6443 |
|
6444 | SchemaDefinition: function SchemaDefinition(_ref20) {
|
6445 | var directives = _ref20.directives,
|
6446 | operationTypes = _ref20.operationTypes;
|
6447 | return join(['schema', join(directives, ' '), block(operationTypes)], ' ');
|
6448 | },
|
6449 | OperationTypeDefinition: function OperationTypeDefinition(_ref21) {
|
6450 | var operation = _ref21.operation,
|
6451 | type = _ref21.type;
|
6452 | return operation + ': ' + type;
|
6453 | },
|
6454 | ScalarTypeDefinition: addDescription(function (_ref22) {
|
6455 | var name = _ref22.name,
|
6456 | directives = _ref22.directives;
|
6457 | return join(['scalar', name, join(directives, ' ')], ' ');
|
6458 | }),
|
6459 | ObjectTypeDefinition: addDescription(function (_ref23) {
|
6460 | var name = _ref23.name,
|
6461 | interfaces = _ref23.interfaces,
|
6462 | directives = _ref23.directives,
|
6463 | fields = _ref23.fields;
|
6464 | return join(['type', name, wrap$1('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
|
6465 | }),
|
6466 | FieldDefinition: addDescription(function (_ref24) {
|
6467 | var name = _ref24.name,
|
6468 | args = _ref24.arguments,
|
6469 | type = _ref24.type,
|
6470 | directives = _ref24.directives;
|
6471 | return name + (args.every(function (arg) {
|
6472 | return arg.indexOf('\n') === -1;
|
6473 | }) ? wrap$1('(', join(args, ', '), ')') : wrap$1('(\n', indent(join(args, '\n')), '\n)')) + ': ' + type + wrap$1(' ', join(directives, ' '));
|
6474 | }),
|
6475 | InputValueDefinition: addDescription(function (_ref25) {
|
6476 | var name = _ref25.name,
|
6477 | type = _ref25.type,
|
6478 | defaultValue = _ref25.defaultValue,
|
6479 | directives = _ref25.directives;
|
6480 | return join([name + ': ' + type, wrap$1('= ', defaultValue), join(directives, ' ')], ' ');
|
6481 | }),
|
6482 | InterfaceTypeDefinition: addDescription(function (_ref26) {
|
6483 | var name = _ref26.name,
|
6484 | directives = _ref26.directives,
|
6485 | fields = _ref26.fields;
|
6486 | return join(['interface', name, join(directives, ' '), block(fields)], ' ');
|
6487 | }),
|
6488 | UnionTypeDefinition: addDescription(function (_ref27) {
|
6489 | var name = _ref27.name,
|
6490 | directives = _ref27.directives,
|
6491 | types = _ref27.types;
|
6492 | return join(['union', name, join(directives, ' '), types && types.length !== 0 ? '= ' + join(types, ' | ') : ''], ' ');
|
6493 | }),
|
6494 | EnumTypeDefinition: addDescription(function (_ref28) {
|
6495 | var name = _ref28.name,
|
6496 | directives = _ref28.directives,
|
6497 | values = _ref28.values;
|
6498 | return join(['enum', name, join(directives, ' '), block(values)], ' ');
|
6499 | }),
|
6500 | EnumValueDefinition: addDescription(function (_ref29) {
|
6501 | var name = _ref29.name,
|
6502 | directives = _ref29.directives;
|
6503 | return join([name, join(directives, ' ')], ' ');
|
6504 | }),
|
6505 | InputObjectTypeDefinition: addDescription(function (_ref30) {
|
6506 | var name = _ref30.name,
|
6507 | directives = _ref30.directives,
|
6508 | fields = _ref30.fields;
|
6509 | return join(['input', name, join(directives, ' '), block(fields)], ' ');
|
6510 | }),
|
6511 | DirectiveDefinition: addDescription(function (_ref31) {
|
6512 | var name = _ref31.name,
|
6513 | args = _ref31.arguments,
|
6514 | locations = _ref31.locations;
|
6515 | return 'directive @' + name + (args.every(function (arg) {
|
6516 | return arg.indexOf('\n') === -1;
|
6517 | }) ? wrap$1('(', join(args, ', '), ')') : wrap$1('(\n', indent(join(args, '\n')), '\n)')) + ' on ' + join(locations, ' | ');
|
6518 | }),
|
6519 | SchemaExtension: function SchemaExtension(_ref32) {
|
6520 | var directives = _ref32.directives,
|
6521 | operationTypes = _ref32.operationTypes;
|
6522 | return join(['extend schema', join(directives, ' '), block(operationTypes)], ' ');
|
6523 | },
|
6524 | ScalarTypeExtension: function ScalarTypeExtension(_ref33) {
|
6525 | var name = _ref33.name,
|
6526 | directives = _ref33.directives;
|
6527 | return join(['extend scalar', name, join(directives, ' ')], ' ');
|
6528 | },
|
6529 | ObjectTypeExtension: function ObjectTypeExtension(_ref34) {
|
6530 | var name = _ref34.name,
|
6531 | interfaces = _ref34.interfaces,
|
6532 | directives = _ref34.directives,
|
6533 | fields = _ref34.fields;
|
6534 | return join(['extend type', name, wrap$1('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
|
6535 | },
|
6536 | InterfaceTypeExtension: function InterfaceTypeExtension(_ref35) {
|
6537 | var name = _ref35.name,
|
6538 | directives = _ref35.directives,
|
6539 | fields = _ref35.fields;
|
6540 | return join(['extend interface', name, join(directives, ' '), block(fields)], ' ');
|
6541 | },
|
6542 | UnionTypeExtension: function UnionTypeExtension(_ref36) {
|
6543 | var name = _ref36.name,
|
6544 | directives = _ref36.directives,
|
6545 | types = _ref36.types;
|
6546 | return join(['extend union', name, join(directives, ' '), types && types.length !== 0 ? '= ' + join(types, ' | ') : ''], ' ');
|
6547 | },
|
6548 | EnumTypeExtension: function EnumTypeExtension(_ref37) {
|
6549 | var name = _ref37.name,
|
6550 | directives = _ref37.directives,
|
6551 | values = _ref37.values;
|
6552 | return join(['extend enum', name, join(directives, ' '), block(values)], ' ');
|
6553 | },
|
6554 | InputObjectTypeExtension: function InputObjectTypeExtension(_ref38) {
|
6555 | var name = _ref38.name,
|
6556 | directives = _ref38.directives,
|
6557 | fields = _ref38.fields;
|
6558 | return join(['extend input', name, join(directives, ' '), block(fields)], ' ');
|
6559 | }
|
6560 | };
|
6561 |
|
6562 | function addDescription(cb) {
|
6563 | return function (node) {
|
6564 | return join([node.description, cb(node)], '\n');
|
6565 | };
|
6566 | }
|
6567 | |
6568 |
|
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 | function join(maybeArray, separator) {
|
6574 | return maybeArray ? maybeArray.filter(function (x) {
|
6575 | return x;
|
6576 | }).join(separator || '') : '';
|
6577 | }
|
6578 | |
6579 |
|
6580 |
|
6581 |
|
6582 |
|
6583 |
|
6584 | function block(array) {
|
6585 | return array && array.length !== 0 ? '{\n' + indent(join(array, '\n')) + '\n}' : '';
|
6586 | }
|
6587 | |
6588 |
|
6589 |
|
6590 |
|
6591 |
|
6592 |
|
6593 | function wrap$1(start, maybeString, end) {
|
6594 | return maybeString ? start + maybeString + (end || '') : '';
|
6595 | }
|
6596 |
|
6597 | function indent(maybeString) {
|
6598 | return maybeString && ' ' + maybeString.replace(/\n/g, '\n ');
|
6599 | }
|
6600 | |
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 |
|
6607 | function printBlockString(value, isDescription) {
|
6608 | var escaped = value.replace(/"""/g, '\\"""');
|
6609 | return (value[0] === ' ' || value[0] === '\t') && value.indexOf('\n') === -1 ? "\"\"\"".concat(escaped.replace(/"$/, '"\n'), "\"\"\"") : "\"\"\"\n".concat(isDescription ? escaped : indent(escaped), "\n\"\"\"");
|
6610 | }
|
6611 |
|
6612 | |
6613 |
|
6614 |
|
6615 |
|
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 | var __Schema = new GraphQLObjectType({
|
6621 | name: '__Schema',
|
6622 | description: 'A GraphQL Schema defines the capabilities of a GraphQL server. It ' + 'exposes all available types and directives on the server, as well as ' + 'the entry points for query, mutation, and subscription operations.',
|
6623 | fields: function fields() {
|
6624 | return {
|
6625 | types: {
|
6626 | description: 'A list of all types supported by this server.',
|
6627 | type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__Type))),
|
6628 | resolve: function resolve(schema) {
|
6629 | return objectValues(schema.getTypeMap());
|
6630 | }
|
6631 | },
|
6632 | queryType: {
|
6633 | description: 'The type that query operations will be rooted at.',
|
6634 | type: GraphQLNonNull(__Type),
|
6635 | resolve: function resolve(schema) {
|
6636 | return schema.getQueryType();
|
6637 | }
|
6638 | },
|
6639 | mutationType: {
|
6640 | description: 'If this server supports mutation, the type that ' + 'mutation operations will be rooted at.',
|
6641 | type: __Type,
|
6642 | resolve: function resolve(schema) {
|
6643 | return schema.getMutationType();
|
6644 | }
|
6645 | },
|
6646 | subscriptionType: {
|
6647 | description: 'If this server support subscription, the type that ' + 'subscription operations will be rooted at.',
|
6648 | type: __Type,
|
6649 | resolve: function resolve(schema) {
|
6650 | return schema.getSubscriptionType();
|
6651 | }
|
6652 | },
|
6653 | directives: {
|
6654 | description: 'A list of all directives supported by this server.',
|
6655 | type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__Directive))),
|
6656 | resolve: function resolve(schema) {
|
6657 | return schema.getDirectives();
|
6658 | }
|
6659 | }
|
6660 | };
|
6661 | }
|
6662 | });
|
6663 | var __Directive = new GraphQLObjectType({
|
6664 | name: '__Directive',
|
6665 | description: 'A Directive provides a way to describe alternate runtime execution and ' + 'type validation behavior in a GraphQL document.' + "\n\nIn some cases, you need to provide options to alter GraphQL's " + 'execution behavior in ways field arguments will not suffice, such as ' + 'conditionally including or skipping a field. Directives provide this by ' + 'describing additional information to the executor.',
|
6666 | fields: function fields() {
|
6667 | return {
|
6668 | name: {
|
6669 | type: GraphQLNonNull(GraphQLString),
|
6670 | resolve: function resolve(obj) {
|
6671 | return obj.name;
|
6672 | }
|
6673 | },
|
6674 | description: {
|
6675 | type: GraphQLString,
|
6676 | resolve: function resolve(obj) {
|
6677 | return obj.description;
|
6678 | }
|
6679 | },
|
6680 | locations: {
|
6681 | type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__DirectiveLocation))),
|
6682 | resolve: function resolve(obj) {
|
6683 | return obj.locations;
|
6684 | }
|
6685 | },
|
6686 | args: {
|
6687 | type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))),
|
6688 | resolve: function resolve(directive) {
|
6689 | return directive.args || [];
|
6690 | }
|
6691 | }
|
6692 | };
|
6693 | }
|
6694 | });
|
6695 | var __DirectiveLocation = new GraphQLEnumType({
|
6696 | name: '__DirectiveLocation',
|
6697 | description: 'A Directive can be adjacent to many parts of the GraphQL language, a ' + '__DirectiveLocation describes one such possible adjacencies.',
|
6698 | values: {
|
6699 | QUERY: {
|
6700 | value: DirectiveLocation.QUERY,
|
6701 | description: 'Location adjacent to a query operation.'
|
6702 | },
|
6703 | MUTATION: {
|
6704 | value: DirectiveLocation.MUTATION,
|
6705 | description: 'Location adjacent to a mutation operation.'
|
6706 | },
|
6707 | SUBSCRIPTION: {
|
6708 | value: DirectiveLocation.SUBSCRIPTION,
|
6709 | description: 'Location adjacent to a subscription operation.'
|
6710 | },
|
6711 | FIELD: {
|
6712 | value: DirectiveLocation.FIELD,
|
6713 | description: 'Location adjacent to a field.'
|
6714 | },
|
6715 | FRAGMENT_DEFINITION: {
|
6716 | value: DirectiveLocation.FRAGMENT_DEFINITION,
|
6717 | description: 'Location adjacent to a fragment definition.'
|
6718 | },
|
6719 | FRAGMENT_SPREAD: {
|
6720 | value: DirectiveLocation.FRAGMENT_SPREAD,
|
6721 | description: 'Location adjacent to a fragment spread.'
|
6722 | },
|
6723 | INLINE_FRAGMENT: {
|
6724 | value: DirectiveLocation.INLINE_FRAGMENT,
|
6725 | description: 'Location adjacent to an inline fragment.'
|
6726 | },
|
6727 | VARIABLE_DEFINITION: {
|
6728 | value: DirectiveLocation.VARIABLE_DEFINITION,
|
6729 | description: 'Location adjacent to a variable definition.'
|
6730 | },
|
6731 | SCHEMA: {
|
6732 | value: DirectiveLocation.SCHEMA,
|
6733 | description: 'Location adjacent to a schema definition.'
|
6734 | },
|
6735 | SCALAR: {
|
6736 | value: DirectiveLocation.SCALAR,
|
6737 | description: 'Location adjacent to a scalar definition.'
|
6738 | },
|
6739 | OBJECT: {
|
6740 | value: DirectiveLocation.OBJECT,
|
6741 | description: 'Location adjacent to an object type definition.'
|
6742 | },
|
6743 | FIELD_DEFINITION: {
|
6744 | value: DirectiveLocation.FIELD_DEFINITION,
|
6745 | description: 'Location adjacent to a field definition.'
|
6746 | },
|
6747 | ARGUMENT_DEFINITION: {
|
6748 | value: DirectiveLocation.ARGUMENT_DEFINITION,
|
6749 | description: 'Location adjacent to an argument definition.'
|
6750 | },
|
6751 | INTERFACE: {
|
6752 | value: DirectiveLocation.INTERFACE,
|
6753 | description: 'Location adjacent to an interface definition.'
|
6754 | },
|
6755 | UNION: {
|
6756 | value: DirectiveLocation.UNION,
|
6757 | description: 'Location adjacent to a union definition.'
|
6758 | },
|
6759 | ENUM: {
|
6760 | value: DirectiveLocation.ENUM,
|
6761 | description: 'Location adjacent to an enum definition.'
|
6762 | },
|
6763 | ENUM_VALUE: {
|
6764 | value: DirectiveLocation.ENUM_VALUE,
|
6765 | description: 'Location adjacent to an enum value definition.'
|
6766 | },
|
6767 | INPUT_OBJECT: {
|
6768 | value: DirectiveLocation.INPUT_OBJECT,
|
6769 | description: 'Location adjacent to an input object type definition.'
|
6770 | },
|
6771 | INPUT_FIELD_DEFINITION: {
|
6772 | value: DirectiveLocation.INPUT_FIELD_DEFINITION,
|
6773 | description: 'Location adjacent to an input object field definition.'
|
6774 | }
|
6775 | }
|
6776 | });
|
6777 | var __Type = new GraphQLObjectType({
|
6778 | name: '__Type',
|
6779 | description: 'The fundamental unit of any GraphQL Schema is the type. There are ' + 'many kinds of types in GraphQL as represented by the `__TypeKind` enum.' + '\n\nDepending on the kind of a type, certain fields describe ' + 'information about that type. Scalar types provide no information ' + 'beyond a name and description, while Enum types provide their values. ' + 'Object and Interface types provide the fields they describe. Abstract ' + 'types, Union and Interface, provide the Object types possible ' + 'at runtime. List and NonNull types compose other types.',
|
6780 | fields: function fields() {
|
6781 | return {
|
6782 | kind: {
|
6783 | type: GraphQLNonNull(__TypeKind),
|
6784 | resolve: function resolve(type) {
|
6785 | if (isScalarType(type)) {
|
6786 | return TypeKind.SCALAR;
|
6787 | } else if (isObjectType(type)) {
|
6788 | return TypeKind.OBJECT;
|
6789 | } else if (isInterfaceType(type)) {
|
6790 | return TypeKind.INTERFACE;
|
6791 | } else if (isUnionType(type)) {
|
6792 | return TypeKind.UNION;
|
6793 | } else if (isEnumType(type)) {
|
6794 | return TypeKind.ENUM;
|
6795 | } else if (isInputObjectType(type)) {
|
6796 | return TypeKind.INPUT_OBJECT;
|
6797 | } else if (isListType(type)) {
|
6798 | return TypeKind.LIST;
|
6799 | } else if (isNonNullType(type)) {
|
6800 | return TypeKind.NON_NULL;
|
6801 | }
|
6802 |
|
6803 | throw new Error('Unknown kind of type: ' + type);
|
6804 | }
|
6805 | },
|
6806 | name: {
|
6807 | type: GraphQLString,
|
6808 | resolve: function resolve(obj) {
|
6809 | return obj.name;
|
6810 | }
|
6811 | },
|
6812 | description: {
|
6813 | type: GraphQLString,
|
6814 | resolve: function resolve(obj) {
|
6815 | return obj.description;
|
6816 | }
|
6817 | },
|
6818 | fields: {
|
6819 | type: GraphQLList(GraphQLNonNull(__Field)),
|
6820 | args: {
|
6821 | includeDeprecated: {
|
6822 | type: GraphQLBoolean,
|
6823 | defaultValue: false
|
6824 | }
|
6825 | },
|
6826 | resolve: function resolve(type, _ref) {
|
6827 | var includeDeprecated = _ref.includeDeprecated;
|
6828 |
|
6829 | if (isObjectType(type) || isInterfaceType(type)) {
|
6830 | var fields = objectValues(type.getFields());
|
6831 |
|
6832 | if (!includeDeprecated) {
|
6833 | fields = fields.filter(function (field) {
|
6834 | return !field.deprecationReason;
|
6835 | });
|
6836 | }
|
6837 |
|
6838 | return fields;
|
6839 | }
|
6840 |
|
6841 | return null;
|
6842 | }
|
6843 | },
|
6844 | interfaces: {
|
6845 | type: GraphQLList(GraphQLNonNull(__Type)),
|
6846 | resolve: function resolve(type) {
|
6847 | if (isObjectType(type)) {
|
6848 | return type.getInterfaces();
|
6849 | }
|
6850 | }
|
6851 | },
|
6852 | possibleTypes: {
|
6853 | type: GraphQLList(GraphQLNonNull(__Type)),
|
6854 | resolve: function resolve(type, args, context, _ref2) {
|
6855 | var schema = _ref2.schema;
|
6856 |
|
6857 | if (isAbstractType(type)) {
|
6858 | return schema.getPossibleTypes(type);
|
6859 | }
|
6860 | }
|
6861 | },
|
6862 | enumValues: {
|
6863 | type: GraphQLList(GraphQLNonNull(__EnumValue)),
|
6864 | args: {
|
6865 | includeDeprecated: {
|
6866 | type: GraphQLBoolean,
|
6867 | defaultValue: false
|
6868 | }
|
6869 | },
|
6870 | resolve: function resolve(type, _ref3) {
|
6871 | var includeDeprecated = _ref3.includeDeprecated;
|
6872 |
|
6873 | if (isEnumType(type)) {
|
6874 | var values = type.getValues();
|
6875 |
|
6876 | if (!includeDeprecated) {
|
6877 | values = values.filter(function (value) {
|
6878 | return !value.deprecationReason;
|
6879 | });
|
6880 | }
|
6881 |
|
6882 | return values;
|
6883 | }
|
6884 | }
|
6885 | },
|
6886 | inputFields: {
|
6887 | type: GraphQLList(GraphQLNonNull(__InputValue)),
|
6888 | resolve: function resolve(type) {
|
6889 | if (isInputObjectType(type)) {
|
6890 | return objectValues(type.getFields());
|
6891 | }
|
6892 | }
|
6893 | },
|
6894 | ofType: {
|
6895 | type: __Type,
|
6896 | resolve: function resolve(obj) {
|
6897 | return obj.ofType;
|
6898 | }
|
6899 | }
|
6900 | };
|
6901 | }
|
6902 | });
|
6903 | var __Field = new GraphQLObjectType({
|
6904 | name: '__Field',
|
6905 | description: 'Object and Interface types are described by a list of Fields, each of ' + 'which has a name, potentially a list of arguments, and a return type.',
|
6906 | fields: function fields() {
|
6907 | return {
|
6908 | name: {
|
6909 | type: GraphQLNonNull(GraphQLString),
|
6910 | resolve: function resolve(obj) {
|
6911 | return obj.name;
|
6912 | }
|
6913 | },
|
6914 | description: {
|
6915 | type: GraphQLString,
|
6916 | resolve: function resolve(obj) {
|
6917 | return obj.description;
|
6918 | }
|
6919 | },
|
6920 | args: {
|
6921 | type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))),
|
6922 | resolve: function resolve(field) {
|
6923 | return field.args || [];
|
6924 | }
|
6925 | },
|
6926 | type: {
|
6927 | type: GraphQLNonNull(__Type),
|
6928 | resolve: function resolve(obj) {
|
6929 | return obj.type;
|
6930 | }
|
6931 | },
|
6932 | isDeprecated: {
|
6933 | type: GraphQLNonNull(GraphQLBoolean),
|
6934 | resolve: function resolve(obj) {
|
6935 | return obj.isDeprecated;
|
6936 | }
|
6937 | },
|
6938 | deprecationReason: {
|
6939 | type: GraphQLString,
|
6940 | resolve: function resolve(obj) {
|
6941 | return obj.deprecationReason;
|
6942 | }
|
6943 | }
|
6944 | };
|
6945 | }
|
6946 | });
|
6947 | var __InputValue = new GraphQLObjectType({
|
6948 | name: '__InputValue',
|
6949 | description: 'Arguments provided to Fields or Directives and the input fields of an ' + 'InputObject are represented as Input Values which describe their type ' + 'and optionally a default value.',
|
6950 | fields: function fields() {
|
6951 | return {
|
6952 | name: {
|
6953 | type: GraphQLNonNull(GraphQLString),
|
6954 | resolve: function resolve(obj) {
|
6955 | return obj.name;
|
6956 | }
|
6957 | },
|
6958 | description: {
|
6959 | type: GraphQLString,
|
6960 | resolve: function resolve(obj) {
|
6961 | return obj.description;
|
6962 | }
|
6963 | },
|
6964 | type: {
|
6965 | type: GraphQLNonNull(__Type),
|
6966 | resolve: function resolve(obj) {
|
6967 | return obj.type;
|
6968 | }
|
6969 | },
|
6970 | defaultValue: {
|
6971 | type: GraphQLString,
|
6972 | description: 'A GraphQL-formatted string representing the default value for this ' + 'input value.',
|
6973 | resolve: function resolve(inputVal) {
|
6974 | return isInvalid(inputVal.defaultValue) ? null : print(astFromValue(inputVal.defaultValue, inputVal.type));
|
6975 | }
|
6976 | }
|
6977 | };
|
6978 | }
|
6979 | });
|
6980 | var __EnumValue = new GraphQLObjectType({
|
6981 | name: '__EnumValue',
|
6982 | description: 'One possible value for a given Enum. Enum values are unique values, not ' + 'a placeholder for a string or numeric value. However an Enum value is ' + 'returned in a JSON response as a string.',
|
6983 | fields: function fields() {
|
6984 | return {
|
6985 | name: {
|
6986 | type: GraphQLNonNull(GraphQLString),
|
6987 | resolve: function resolve(obj) {
|
6988 | return obj.name;
|
6989 | }
|
6990 | },
|
6991 | description: {
|
6992 | type: GraphQLString,
|
6993 | resolve: function resolve(obj) {
|
6994 | return obj.description;
|
6995 | }
|
6996 | },
|
6997 | isDeprecated: {
|
6998 | type: GraphQLNonNull(GraphQLBoolean),
|
6999 | resolve: function resolve(obj) {
|
7000 | return obj.isDeprecated;
|
7001 | }
|
7002 | },
|
7003 | deprecationReason: {
|
7004 | type: GraphQLString,
|
7005 | resolve: function resolve(obj) {
|
7006 | return obj.deprecationReason;
|
7007 | }
|
7008 | }
|
7009 | };
|
7010 | }
|
7011 | });
|
7012 | var TypeKind = {
|
7013 | SCALAR: 'SCALAR',
|
7014 | OBJECT: 'OBJECT',
|
7015 | INTERFACE: 'INTERFACE',
|
7016 | UNION: 'UNION',
|
7017 | ENUM: 'ENUM',
|
7018 | INPUT_OBJECT: 'INPUT_OBJECT',
|
7019 | LIST: 'LIST',
|
7020 | NON_NULL: 'NON_NULL'
|
7021 | };
|
7022 | var __TypeKind = new GraphQLEnumType({
|
7023 | name: '__TypeKind',
|
7024 | description: 'An enum describing what kind of type a given `__Type` is.',
|
7025 | values: {
|
7026 | SCALAR: {
|
7027 | value: TypeKind.SCALAR,
|
7028 | description: 'Indicates this type is a scalar.'
|
7029 | },
|
7030 | OBJECT: {
|
7031 | value: TypeKind.OBJECT,
|
7032 | description: 'Indicates this type is an object. ' + '`fields` and `interfaces` are valid fields.'
|
7033 | },
|
7034 | INTERFACE: {
|
7035 | value: TypeKind.INTERFACE,
|
7036 | description: 'Indicates this type is an interface. ' + '`fields` and `possibleTypes` are valid fields.'
|
7037 | },
|
7038 | UNION: {
|
7039 | value: TypeKind.UNION,
|
7040 | description: 'Indicates this type is a union. `possibleTypes` is a valid field.'
|
7041 | },
|
7042 | ENUM: {
|
7043 | value: TypeKind.ENUM,
|
7044 | description: 'Indicates this type is an enum. `enumValues` is a valid field.'
|
7045 | },
|
7046 | INPUT_OBJECT: {
|
7047 | value: TypeKind.INPUT_OBJECT,
|
7048 | description: 'Indicates this type is an input object. ' + '`inputFields` is a valid field.'
|
7049 | },
|
7050 | LIST: {
|
7051 | value: TypeKind.LIST,
|
7052 | description: 'Indicates this type is a list. `ofType` is a valid field.'
|
7053 | },
|
7054 | NON_NULL: {
|
7055 | value: TypeKind.NON_NULL,
|
7056 | description: 'Indicates this type is a non-null. `ofType` is a valid field.'
|
7057 | }
|
7058 | }
|
7059 | });
|
7060 | |
7061 |
|
7062 |
|
7063 |
|
7064 |
|
7065 | var SchemaMetaFieldDef = {
|
7066 | name: '__schema',
|
7067 | type: GraphQLNonNull(__Schema),
|
7068 | description: 'Access the current type schema of this server.',
|
7069 | args: [],
|
7070 | resolve: function resolve(source, args, context, _ref4) {
|
7071 | var schema = _ref4.schema;
|
7072 | return schema;
|
7073 | }
|
7074 | };
|
7075 | var TypeMetaFieldDef = {
|
7076 | name: '__type',
|
7077 | type: __Type,
|
7078 | description: 'Request the type information of a single type.',
|
7079 | args: [{
|
7080 | name: 'name',
|
7081 | type: GraphQLNonNull(GraphQLString)
|
7082 | }],
|
7083 | resolve: function resolve(source, _ref5, context, _ref6) {
|
7084 | var name = _ref5.name;
|
7085 | var schema = _ref6.schema;
|
7086 | return schema.getType(name);
|
7087 | }
|
7088 | };
|
7089 | var TypeNameMetaFieldDef = {
|
7090 | name: '__typename',
|
7091 | type: GraphQLNonNull(GraphQLString),
|
7092 | description: 'The name of the current Object type at runtime.',
|
7093 | args: [],
|
7094 | resolve: function resolve(source, args, context, _ref7) {
|
7095 | var parentType = _ref7.parentType;
|
7096 | return parentType.name;
|
7097 | }
|
7098 | };
|
7099 |
|
7100 | |
7101 |
|
7102 |
|
7103 |
|
7104 |
|
7105 |
|
7106 |
|
7107 |
|
7108 | function find(list, predicate) {
|
7109 | for (var i = 0; i < list.length; i++) {
|
7110 | if (predicate(list[i])) {
|
7111 | return list[i];
|
7112 | }
|
7113 | }
|
7114 | }
|
7115 |
|
7116 | function _typeof$3(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$3 = function _typeof(obj) { return typeof obj; }; } else { _typeof$3 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$3(obj); }
|
7117 |
|
7118 | function _defineProperty$2(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
7119 | |
7120 |
|
7121 |
|
7122 |
|
7123 |
|
7124 |
|
7125 |
|
7126 |
|
7127 |
|
7128 |
|
7129 |
|
7130 |
|
7131 |
|
7132 |
|
7133 |
|
7134 |
|
7135 |
|
7136 |
|
7137 |
|
7138 |
|
7139 |
|
7140 |
|
7141 |
|
7142 |
|
7143 |
|
7144 |
|
7145 |
|
7146 | var GraphQLSchema =
|
7147 |
|
7148 | function () {
|
7149 |
|
7150 |
|
7151 | function GraphQLSchema(config) {
|
7152 | _defineProperty$2(this, "astNode", void 0);
|
7153 |
|
7154 | _defineProperty$2(this, "extensionASTNodes", void 0);
|
7155 |
|
7156 | _defineProperty$2(this, "_queryType", void 0);
|
7157 |
|
7158 | _defineProperty$2(this, "_mutationType", void 0);
|
7159 |
|
7160 | _defineProperty$2(this, "_subscriptionType", void 0);
|
7161 |
|
7162 | _defineProperty$2(this, "_directives", void 0);
|
7163 |
|
7164 | _defineProperty$2(this, "_typeMap", void 0);
|
7165 |
|
7166 | _defineProperty$2(this, "_implementations", void 0);
|
7167 |
|
7168 | _defineProperty$2(this, "_possibleTypeMap", void 0);
|
7169 |
|
7170 | _defineProperty$2(this, "__validationErrors", void 0);
|
7171 |
|
7172 | _defineProperty$2(this, "__allowedLegacyNames", void 0);
|
7173 |
|
7174 |
|
7175 |
|
7176 | if (config && config.assumeValid) {
|
7177 | this.__validationErrors = [];
|
7178 | } else {
|
7179 |
|
7180 |
|
7181 | !(_typeof$3(config) === 'object') ? invariant(0, 'Must provide configuration object.') : void 0;
|
7182 | !(!config.types || Array.isArray(config.types)) ? invariant(0, "\"types\" must be Array if provided but got: ".concat(inspect(config.types), ".")) : void 0;
|
7183 | !(!config.directives || Array.isArray(config.directives)) ? invariant(0, '"directives" must be Array if provided but got: ' + "".concat(inspect(config.directives), ".")) : void 0;
|
7184 | !(!config.allowedLegacyNames || Array.isArray(config.allowedLegacyNames)) ? invariant(0, '"allowedLegacyNames" must be Array if provided but got: ' + "".concat(inspect(config.allowedLegacyNames), ".")) : void 0;
|
7185 | }
|
7186 |
|
7187 | this.__allowedLegacyNames = config.allowedLegacyNames || [];
|
7188 | this._queryType = config.query;
|
7189 | this._mutationType = config.mutation;
|
7190 | this._subscriptionType = config.subscription;
|
7191 |
|
7192 | this._directives = config.directives || specifiedDirectives;
|
7193 | this.astNode = config.astNode;
|
7194 | this.extensionASTNodes = config.extensionASTNodes;
|
7195 |
|
7196 | var initialTypes = [this.getQueryType(), this.getMutationType(), this.getSubscriptionType(), __Schema];
|
7197 | var types = config.types;
|
7198 |
|
7199 | if (types) {
|
7200 | initialTypes = initialTypes.concat(types);
|
7201 | }
|
7202 |
|
7203 |
|
7204 | var typeMap = Object.create(null);
|
7205 |
|
7206 | typeMap = initialTypes.reduce(typeMapReducer, typeMap);
|
7207 |
|
7208 | typeMap = this._directives.reduce(typeMapDirectiveReducer, typeMap);
|
7209 |
|
7210 | this._typeMap = typeMap;
|
7211 |
|
7212 | this._implementations = Object.create(null);
|
7213 |
|
7214 | var _arr = Object.keys(this._typeMap);
|
7215 |
|
7216 | for (var _i = 0; _i < _arr.length; _i++) {
|
7217 | var typeName = _arr[_i];
|
7218 | var type = this._typeMap[typeName];
|
7219 |
|
7220 | if (isObjectType(type)) {
|
7221 | var _iteratorNormalCompletion = true;
|
7222 | var _didIteratorError = false;
|
7223 | var _iteratorError = undefined;
|
7224 |
|
7225 | try {
|
7226 | for (var _iterator = type.getInterfaces()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
7227 | var iface = _step.value;
|
7228 |
|
7229 | if (isInterfaceType(iface)) {
|
7230 | var impls = this._implementations[iface.name];
|
7231 |
|
7232 | if (impls) {
|
7233 | impls.push(type);
|
7234 | } else {
|
7235 | this._implementations[iface.name] = [type];
|
7236 | }
|
7237 | }
|
7238 | }
|
7239 | } catch (err) {
|
7240 | _didIteratorError = true;
|
7241 | _iteratorError = err;
|
7242 | } finally {
|
7243 | try {
|
7244 | if (!_iteratorNormalCompletion && _iterator.return != null) {
|
7245 | _iterator.return();
|
7246 | }
|
7247 | } finally {
|
7248 | if (_didIteratorError) {
|
7249 | throw _iteratorError;
|
7250 | }
|
7251 | }
|
7252 | }
|
7253 | } else if (isAbstractType(type) && !this._implementations[type.name]) {
|
7254 | this._implementations[type.name] = [];
|
7255 | }
|
7256 | }
|
7257 | }
|
7258 |
|
7259 | var _proto = GraphQLSchema.prototype;
|
7260 |
|
7261 | _proto.getQueryType = function getQueryType() {
|
7262 | return this._queryType;
|
7263 | };
|
7264 |
|
7265 | _proto.getMutationType = function getMutationType() {
|
7266 | return this._mutationType;
|
7267 | };
|
7268 |
|
7269 | _proto.getSubscriptionType = function getSubscriptionType() {
|
7270 | return this._subscriptionType;
|
7271 | };
|
7272 |
|
7273 | _proto.getTypeMap = function getTypeMap() {
|
7274 | return this._typeMap;
|
7275 | };
|
7276 |
|
7277 | _proto.getType = function getType(name) {
|
7278 | return this.getTypeMap()[name];
|
7279 | };
|
7280 |
|
7281 | _proto.getPossibleTypes = function getPossibleTypes(abstractType) {
|
7282 | if (isUnionType(abstractType)) {
|
7283 | return abstractType.getTypes();
|
7284 | }
|
7285 |
|
7286 | return this._implementations[abstractType.name];
|
7287 | };
|
7288 |
|
7289 | _proto.isPossibleType = function isPossibleType(abstractType, possibleType) {
|
7290 | var possibleTypeMap = this._possibleTypeMap;
|
7291 |
|
7292 | if (!possibleTypeMap) {
|
7293 | this._possibleTypeMap = possibleTypeMap = Object.create(null);
|
7294 | }
|
7295 |
|
7296 | if (!possibleTypeMap[abstractType.name]) {
|
7297 | var possibleTypes = this.getPossibleTypes(abstractType);
|
7298 | possibleTypeMap[abstractType.name] = possibleTypes.reduce(function (map, type) {
|
7299 | return map[type.name] = true, map;
|
7300 | }, Object.create(null));
|
7301 | }
|
7302 |
|
7303 | return Boolean(possibleTypeMap[abstractType.name][possibleType.name]);
|
7304 | };
|
7305 |
|
7306 | _proto.getDirectives = function getDirectives() {
|
7307 | return this._directives;
|
7308 | };
|
7309 |
|
7310 | _proto.getDirective = function getDirective(name) {
|
7311 | return find(this.getDirectives(), function (directive) {
|
7312 | return directive.name === name;
|
7313 | });
|
7314 | };
|
7315 |
|
7316 | return GraphQLSchema;
|
7317 | }();
|
7318 |
|
7319 | applyToStringTag(GraphQLSchema);
|
7320 |
|
7321 | function typeMapReducer(map, type) {
|
7322 | if (!type) {
|
7323 | return map;
|
7324 | }
|
7325 |
|
7326 | if (isWrappingType(type)) {
|
7327 | return typeMapReducer(map, type.ofType);
|
7328 | }
|
7329 |
|
7330 | if (map[type.name]) {
|
7331 | !(map[type.name] === type) ? invariant(0, 'Schema must contain unique named types but contains multiple ' + "types named \"".concat(type.name, "\".")) : void 0;
|
7332 | return map;
|
7333 | }
|
7334 |
|
7335 | map[type.name] = type;
|
7336 | var reducedMap = map;
|
7337 |
|
7338 | if (isUnionType(type)) {
|
7339 | reducedMap = type.getTypes().reduce(typeMapReducer, reducedMap);
|
7340 | }
|
7341 |
|
7342 | if (isObjectType(type)) {
|
7343 | reducedMap = type.getInterfaces().reduce(typeMapReducer, reducedMap);
|
7344 | }
|
7345 |
|
7346 | if (isObjectType(type) || isInterfaceType(type)) {
|
7347 | var _iteratorNormalCompletion2 = true;
|
7348 | var _didIteratorError2 = false;
|
7349 | var _iteratorError2 = undefined;
|
7350 |
|
7351 | try {
|
7352 | for (var _iterator2 = objectValues(type.getFields())[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
7353 | var field = _step2.value;
|
7354 |
|
7355 | if (field.args) {
|
7356 | var fieldArgTypes = field.args.map(function (arg) {
|
7357 | return arg.type;
|
7358 | });
|
7359 | reducedMap = fieldArgTypes.reduce(typeMapReducer, reducedMap);
|
7360 | }
|
7361 |
|
7362 | reducedMap = typeMapReducer(reducedMap, field.type);
|
7363 | }
|
7364 | } catch (err) {
|
7365 | _didIteratorError2 = true;
|
7366 | _iteratorError2 = err;
|
7367 | } finally {
|
7368 | try {
|
7369 | if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
7370 | _iterator2.return();
|
7371 | }
|
7372 | } finally {
|
7373 | if (_didIteratorError2) {
|
7374 | throw _iteratorError2;
|
7375 | }
|
7376 | }
|
7377 | }
|
7378 | }
|
7379 |
|
7380 | if (isInputObjectType(type)) {
|
7381 | var _iteratorNormalCompletion3 = true;
|
7382 | var _didIteratorError3 = false;
|
7383 | var _iteratorError3 = undefined;
|
7384 |
|
7385 | try {
|
7386 | for (var _iterator3 = objectValues(type.getFields())[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
7387 | var _field = _step3.value;
|
7388 | reducedMap = typeMapReducer(reducedMap, _field.type);
|
7389 | }
|
7390 | } catch (err) {
|
7391 | _didIteratorError3 = true;
|
7392 | _iteratorError3 = err;
|
7393 | } finally {
|
7394 | try {
|
7395 | if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
7396 | _iterator3.return();
|
7397 | }
|
7398 | } finally {
|
7399 | if (_didIteratorError3) {
|
7400 | throw _iteratorError3;
|
7401 | }
|
7402 | }
|
7403 | }
|
7404 | }
|
7405 |
|
7406 | return reducedMap;
|
7407 | }
|
7408 |
|
7409 | function typeMapDirectiveReducer(map, directive) {
|
7410 |
|
7411 | if (!isDirective(directive)) {
|
7412 | return map;
|
7413 | }
|
7414 |
|
7415 | return directive.args.reduce(function (_map, arg) {
|
7416 | return typeMapReducer(_map, arg.type);
|
7417 | }, map);
|
7418 | }
|
7419 |
|
7420 | |
7421 |
|
7422 |
|
7423 |
|
7424 |
|
7425 |
|
7426 |
|
7427 |
|
7428 |
|
7429 | |
7430 |
|
7431 |
|
7432 |
|
7433 |
|
7434 |
|
7435 |
|
7436 |
|
7437 |
|
7438 | |
7439 |
|
7440 |
|
7441 |
|
7442 |
|
7443 |
|
7444 |
|
7445 |
|
7446 |
|
7447 | |
7448 |
|
7449 |
|
7450 |
|
7451 |
|
7452 |
|
7453 |
|
7454 |
|
7455 |
|
7456 | |
7457 |
|
7458 |
|
7459 |
|
7460 |
|
7461 |
|
7462 |
|
7463 |
|
7464 |
|
7465 | function _defineProperty$4(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
7466 |
|
7467 | |
7468 |
|
7469 |
|
7470 |
|
7471 |
|
7472 |
|
7473 |
|
7474 |
|
7475 | var Source = function Source(body, name, locationOffset) {
|
7476 | _defineProperty$4(this, "body", void 0);
|
7477 |
|
7478 | _defineProperty$4(this, "name", void 0);
|
7479 |
|
7480 | _defineProperty$4(this, "locationOffset", void 0);
|
7481 |
|
7482 | this.body = body;
|
7483 | this.name = name || 'GraphQL request';
|
7484 | this.locationOffset = locationOffset || {
|
7485 | line: 1,
|
7486 | column: 1
|
7487 | };
|
7488 | !(this.locationOffset.line > 0) ? invariant(0, 'line in locationOffset is 1-indexed and must be positive') : void 0;
|
7489 | !(this.locationOffset.column > 0) ? invariant(0, 'column in locationOffset is 1-indexed and must be positive') : void 0;
|
7490 | };
|
7491 |
|
7492 | applyToStringTag(Source);
|
7493 |
|
7494 | |
7495 |
|
7496 |
|
7497 |
|
7498 |
|
7499 |
|
7500 |
|
7501 |
|
7502 |
|
7503 | |
7504 |
|
7505 |
|
7506 |
|
7507 |
|
7508 |
|
7509 |
|
7510 |
|
7511 |
|
7512 | |
7513 |
|
7514 |
|
7515 |
|
7516 |
|
7517 |
|
7518 |
|
7519 |
|
7520 |
|
7521 | |
7522 |
|
7523 |
|
7524 |
|
7525 |
|
7526 |
|
7527 |
|
7528 |
|
7529 |
|
7530 | |
7531 |
|
7532 |
|
7533 |
|
7534 |
|
7535 |
|
7536 |
|
7537 |
|
7538 |
|
7539 | |
7540 |
|
7541 |
|
7542 |
|
7543 |
|
7544 |
|
7545 |
|
7546 |
|
7547 | |
7548 |
|
7549 |
|
7550 |
|
7551 |
|
7552 | |
7553 |
|
7554 |
|
7555 |
|
7556 | var TokenKind = Object.freeze({
|
7557 | SOF: '<SOF>',
|
7558 | EOF: '<EOF>',
|
7559 | BANG: '!',
|
7560 | DOLLAR: '$',
|
7561 | AMP: '&',
|
7562 | PAREN_L: '(',
|
7563 | PAREN_R: ')',
|
7564 | SPREAD: '...',
|
7565 | COLON: ':',
|
7566 | EQUALS: '=',
|
7567 | AT: '@',
|
7568 | BRACKET_L: '[',
|
7569 | BRACKET_R: ']',
|
7570 | BRACE_L: '{',
|
7571 | PIPE: '|',
|
7572 | BRACE_R: '}',
|
7573 | NAME: 'Name',
|
7574 | INT: 'Int',
|
7575 | FLOAT: 'Float',
|
7576 | STRING: 'String',
|
7577 | BLOCK_STRING: 'BlockString',
|
7578 | COMMENT: 'Comment'
|
7579 | });
|
7580 |
|
7581 | |
7582 |
|
7583 |
|
7584 |
|
7585 |
|
7586 |
|
7587 |
|
7588 |
|
7589 |
|
7590 | |
7591 |
|
7592 |
|
7593 |
|
7594 |
|
7595 |
|
7596 |
|
7597 |
|
7598 | function typeFromAST(schema, typeNode) {
|
7599 |
|
7600 | var innerType;
|
7601 |
|
7602 | if (typeNode.kind === Kind.LIST_TYPE) {
|
7603 | innerType = typeFromAST(schema, typeNode.type);
|
7604 | return innerType && GraphQLList(innerType);
|
7605 | }
|
7606 |
|
7607 | if (typeNode.kind === Kind.NON_NULL_TYPE) {
|
7608 | innerType = typeFromAST(schema, typeNode.type);
|
7609 | return innerType && GraphQLNonNull(innerType);
|
7610 | }
|
7611 |
|
7612 | if (typeNode.kind === Kind.NAMED_TYPE) {
|
7613 | return schema.getType(typeNode.name.value);
|
7614 | }
|
7615 |
|
7616 |
|
7617 |
|
7618 | throw new Error("Unexpected type kind: ".concat(typeNode.kind, "."));
|
7619 | }
|
7620 |
|
7621 | function _defineProperty$5(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
7622 | |
7623 |
|
7624 |
|
7625 |
|
7626 |
|
7627 |
|
7628 | var TypeInfo =
|
7629 |
|
7630 | function () {
|
7631 | function TypeInfo(schema, // NOTE: this experimental optional second parameter is only needed in order
|
7632 | // to support non-spec-compliant codebases. You should never need to use it.
|
7633 | getFieldDefFn, // Initial type may be provided in rare cases to facilitate traversals
|
7634 | initialType) {
|
7635 | _defineProperty$5(this, "_schema", void 0);
|
7636 |
|
7637 | _defineProperty$5(this, "_typeStack", void 0);
|
7638 |
|
7639 | _defineProperty$5(this, "_parentTypeStack", void 0);
|
7640 |
|
7641 | _defineProperty$5(this, "_inputTypeStack", void 0);
|
7642 |
|
7643 | _defineProperty$5(this, "_fieldDefStack", void 0);
|
7644 |
|
7645 | _defineProperty$5(this, "_defaultValueStack", void 0);
|
7646 |
|
7647 | _defineProperty$5(this, "_directive", void 0);
|
7648 |
|
7649 | _defineProperty$5(this, "_argument", void 0);
|
7650 |
|
7651 | _defineProperty$5(this, "_enumValue", void 0);
|
7652 |
|
7653 | _defineProperty$5(this, "_getFieldDef", void 0);
|
7654 |
|
7655 | this._schema = schema;
|
7656 | this._typeStack = [];
|
7657 | this._parentTypeStack = [];
|
7658 | this._inputTypeStack = [];
|
7659 | this._fieldDefStack = [];
|
7660 | this._defaultValueStack = [];
|
7661 | this._directive = null;
|
7662 | this._argument = null;
|
7663 | this._enumValue = null;
|
7664 | this._getFieldDef = getFieldDefFn || getFieldDef;
|
7665 |
|
7666 | if (initialType) {
|
7667 | if (isInputType(initialType)) {
|
7668 | this._inputTypeStack.push(initialType);
|
7669 | }
|
7670 |
|
7671 | if (isCompositeType(initialType)) {
|
7672 | this._parentTypeStack.push(initialType);
|
7673 | }
|
7674 |
|
7675 | if (isOutputType(initialType)) {
|
7676 | this._typeStack.push(initialType);
|
7677 | }
|
7678 | }
|
7679 | }
|
7680 |
|
7681 | var _proto = TypeInfo.prototype;
|
7682 |
|
7683 | _proto.getType = function getType() {
|
7684 | if (this._typeStack.length > 0) {
|
7685 | return this._typeStack[this._typeStack.length - 1];
|
7686 | }
|
7687 | };
|
7688 |
|
7689 | _proto.getParentType = function getParentType() {
|
7690 | if (this._parentTypeStack.length > 0) {
|
7691 | return this._parentTypeStack[this._parentTypeStack.length - 1];
|
7692 | }
|
7693 | };
|
7694 |
|
7695 | _proto.getInputType = function getInputType() {
|
7696 | if (this._inputTypeStack.length > 0) {
|
7697 | return this._inputTypeStack[this._inputTypeStack.length - 1];
|
7698 | }
|
7699 | };
|
7700 |
|
7701 | _proto.getParentInputType = function getParentInputType() {
|
7702 | if (this._inputTypeStack.length > 1) {
|
7703 | return this._inputTypeStack[this._inputTypeStack.length - 2];
|
7704 | }
|
7705 | };
|
7706 |
|
7707 | _proto.getFieldDef = function getFieldDef() {
|
7708 | if (this._fieldDefStack.length > 0) {
|
7709 | return this._fieldDefStack[this._fieldDefStack.length - 1];
|
7710 | }
|
7711 | };
|
7712 |
|
7713 | _proto.getDefaultValue = function getDefaultValue() {
|
7714 | if (this._defaultValueStack.length > 0) {
|
7715 | return this._defaultValueStack[this._defaultValueStack.length - 1];
|
7716 | }
|
7717 | };
|
7718 |
|
7719 | _proto.getDirective = function getDirective() {
|
7720 | return this._directive;
|
7721 | };
|
7722 |
|
7723 | _proto.getArgument = function getArgument() {
|
7724 | return this._argument;
|
7725 | };
|
7726 |
|
7727 | _proto.getEnumValue = function getEnumValue() {
|
7728 | return this._enumValue;
|
7729 | };
|
7730 |
|
7731 | _proto.enter = function enter(node) {
|
7732 | var schema = this._schema;
|
7733 |
|
7734 |
|
7735 |
|
7736 |
|
7737 | switch (node.kind) {
|
7738 | case Kind.SELECTION_SET:
|
7739 | var namedType = getNamedType(this.getType());
|
7740 |
|
7741 | this._parentTypeStack.push(isCompositeType(namedType) ? namedType : undefined);
|
7742 |
|
7743 | break;
|
7744 |
|
7745 | case Kind.FIELD:
|
7746 | var parentType = this.getParentType();
|
7747 | var fieldDef;
|
7748 | var fieldType;
|
7749 |
|
7750 | if (parentType) {
|
7751 | fieldDef = this._getFieldDef(schema, parentType, node);
|
7752 |
|
7753 | if (fieldDef) {
|
7754 | fieldType = fieldDef.type;
|
7755 | }
|
7756 | }
|
7757 |
|
7758 | this._fieldDefStack.push(fieldDef);
|
7759 |
|
7760 | this._typeStack.push(isOutputType(fieldType) ? fieldType : undefined);
|
7761 |
|
7762 | break;
|
7763 |
|
7764 | case Kind.DIRECTIVE:
|
7765 | this._directive = schema.getDirective(node.name.value);
|
7766 | break;
|
7767 |
|
7768 | case Kind.OPERATION_DEFINITION:
|
7769 | var type;
|
7770 |
|
7771 | if (node.operation === 'query') {
|
7772 | type = schema.getQueryType();
|
7773 | } else if (node.operation === 'mutation') {
|
7774 | type = schema.getMutationType();
|
7775 | } else if (node.operation === 'subscription') {
|
7776 | type = schema.getSubscriptionType();
|
7777 | }
|
7778 |
|
7779 | this._typeStack.push(isObjectType(type) ? type : undefined);
|
7780 |
|
7781 | break;
|
7782 |
|
7783 | case Kind.INLINE_FRAGMENT:
|
7784 | case Kind.FRAGMENT_DEFINITION:
|
7785 | var typeConditionAST = node.typeCondition;
|
7786 | var outputType = typeConditionAST ? typeFromAST(schema, typeConditionAST) : getNamedType(this.getType());
|
7787 |
|
7788 | this._typeStack.push(isOutputType(outputType) ? outputType : undefined);
|
7789 |
|
7790 | break;
|
7791 |
|
7792 | case Kind.VARIABLE_DEFINITION:
|
7793 | var inputType = typeFromAST(schema, node.type);
|
7794 |
|
7795 | this._inputTypeStack.push(isInputType(inputType) ? inputType : undefined);
|
7796 |
|
7797 | break;
|
7798 |
|
7799 | case Kind.ARGUMENT:
|
7800 | var argDef;
|
7801 | var argType;
|
7802 | var fieldOrDirective = this.getDirective() || this.getFieldDef();
|
7803 |
|
7804 | if (fieldOrDirective) {
|
7805 | argDef = find(fieldOrDirective.args, function (arg) {
|
7806 | return arg.name === node.name.value;
|
7807 | });
|
7808 |
|
7809 | if (argDef) {
|
7810 | argType = argDef.type;
|
7811 | }
|
7812 | }
|
7813 |
|
7814 | this._argument = argDef;
|
7815 |
|
7816 | this._defaultValueStack.push(argDef ? argDef.defaultValue : undefined);
|
7817 |
|
7818 | this._inputTypeStack.push(isInputType(argType) ? argType : undefined);
|
7819 |
|
7820 | break;
|
7821 |
|
7822 | case Kind.LIST:
|
7823 | var listType = getNullableType(this.getInputType());
|
7824 | var itemType = isListType(listType) ? listType.ofType : listType;
|
7825 |
|
7826 | this._defaultValueStack.push(undefined);
|
7827 |
|
7828 | this._inputTypeStack.push(isInputType(itemType) ? itemType : undefined);
|
7829 |
|
7830 | break;
|
7831 |
|
7832 | case Kind.OBJECT_FIELD:
|
7833 | var objectType = getNamedType(this.getInputType());
|
7834 | var inputFieldType;
|
7835 | var inputField;
|
7836 |
|
7837 | if (isInputObjectType(objectType)) {
|
7838 | inputField = objectType.getFields()[node.name.value];
|
7839 |
|
7840 | if (inputField) {
|
7841 | inputFieldType = inputField.type;
|
7842 | }
|
7843 | }
|
7844 |
|
7845 | this._defaultValueStack.push(inputField ? inputField.defaultValue : undefined);
|
7846 |
|
7847 | this._inputTypeStack.push(isInputType(inputFieldType) ? inputFieldType : undefined);
|
7848 |
|
7849 | break;
|
7850 |
|
7851 | case Kind.ENUM:
|
7852 | var enumType = getNamedType(this.getInputType());
|
7853 | var enumValue;
|
7854 |
|
7855 | if (isEnumType(enumType)) {
|
7856 | enumValue = enumType.getValue(node.value);
|
7857 | }
|
7858 |
|
7859 | this._enumValue = enumValue;
|
7860 | break;
|
7861 | }
|
7862 | };
|
7863 |
|
7864 | _proto.leave = function leave(node) {
|
7865 | switch (node.kind) {
|
7866 | case Kind.SELECTION_SET:
|
7867 | this._parentTypeStack.pop();
|
7868 |
|
7869 | break;
|
7870 |
|
7871 | case Kind.FIELD:
|
7872 | this._fieldDefStack.pop();
|
7873 |
|
7874 | this._typeStack.pop();
|
7875 |
|
7876 | break;
|
7877 |
|
7878 | case Kind.DIRECTIVE:
|
7879 | this._directive = null;
|
7880 | break;
|
7881 |
|
7882 | case Kind.OPERATION_DEFINITION:
|
7883 | case Kind.INLINE_FRAGMENT:
|
7884 | case Kind.FRAGMENT_DEFINITION:
|
7885 | this._typeStack.pop();
|
7886 |
|
7887 | break;
|
7888 |
|
7889 | case Kind.VARIABLE_DEFINITION:
|
7890 | this._inputTypeStack.pop();
|
7891 |
|
7892 | break;
|
7893 |
|
7894 | case Kind.ARGUMENT:
|
7895 | this._argument = null;
|
7896 |
|
7897 | this._defaultValueStack.pop();
|
7898 |
|
7899 | this._inputTypeStack.pop();
|
7900 |
|
7901 | break;
|
7902 |
|
7903 | case Kind.LIST:
|
7904 | case Kind.OBJECT_FIELD:
|
7905 | this._defaultValueStack.pop();
|
7906 |
|
7907 | this._inputTypeStack.pop();
|
7908 |
|
7909 | break;
|
7910 |
|
7911 | case Kind.ENUM:
|
7912 | this._enumValue = null;
|
7913 | break;
|
7914 | }
|
7915 | };
|
7916 |
|
7917 | return TypeInfo;
|
7918 | }();
|
7919 | |
7920 |
|
7921 |
|
7922 |
|
7923 |
|
7924 |
|
7925 | function getFieldDef(schema, parentType, fieldNode) {
|
7926 | var name = fieldNode.name.value;
|
7927 |
|
7928 | if (name === SchemaMetaFieldDef.name && schema.getQueryType() === parentType) {
|
7929 | return SchemaMetaFieldDef;
|
7930 | }
|
7931 |
|
7932 | if (name === TypeMetaFieldDef.name && schema.getQueryType() === parentType) {
|
7933 | return TypeMetaFieldDef;
|
7934 | }
|
7935 |
|
7936 | if (name === TypeNameMetaFieldDef.name && isCompositeType(parentType)) {
|
7937 | return TypeNameMetaFieldDef;
|
7938 | }
|
7939 |
|
7940 | if (isObjectType(parentType) || isInterfaceType(parentType)) {
|
7941 | return parentType.getFields()[name];
|
7942 | }
|
7943 | }
|
7944 |
|
7945 | |
7946 |
|
7947 |
|
7948 |
|
7949 |
|
7950 |
|
7951 |
|
7952 |
|
7953 |
|
7954 | |
7955 |
|
7956 |
|
7957 |
|
7958 |
|
7959 |
|
7960 |
|
7961 |
|
7962 |
|
7963 | |
7964 |
|
7965 |
|
7966 |
|
7967 |
|
7968 |
|
7969 |
|
7970 |
|
7971 |
|
7972 | |
7973 |
|
7974 |
|
7975 |
|
7976 |
|
7977 |
|
7978 |
|
7979 |
|
7980 |
|
7981 | |
7982 |
|
7983 |
|
7984 |
|
7985 |
|
7986 |
|
7987 |
|
7988 |
|
7989 |
|
7990 | |
7991 |
|
7992 |
|
7993 |
|
7994 |
|
7995 |
|
7996 |
|
7997 |
|
7998 |
|
7999 | |
8000 |
|
8001 |
|
8002 |
|
8003 |
|
8004 |
|
8005 |
|
8006 |
|
8007 |
|
8008 | |
8009 |
|
8010 |
|
8011 |
|
8012 |
|
8013 |
|
8014 |
|
8015 |
|
8016 |
|
8017 | |
8018 |
|
8019 |
|
8020 |
|
8021 |
|
8022 |
|
8023 |
|
8024 |
|
8025 |
|
8026 | |
8027 |
|
8028 |
|
8029 |
|
8030 |
|
8031 |
|
8032 |
|
8033 |
|
8034 |
|
8035 | |
8036 |
|
8037 |
|
8038 |
|
8039 |
|
8040 |
|
8041 |
|
8042 |
|
8043 |
|
8044 | |
8045 |
|
8046 |
|
8047 |
|
8048 |
|
8049 |
|
8050 |
|
8051 |
|
8052 |
|
8053 | |
8054 |
|
8055 |
|
8056 |
|
8057 |
|
8058 |
|
8059 |
|
8060 |
|
8061 |
|
8062 | |
8063 |
|
8064 |
|
8065 |
|
8066 |
|
8067 |
|
8068 |
|
8069 |
|
8070 |
|
8071 | |
8072 |
|
8073 |
|
8074 |
|
8075 |
|
8076 |
|
8077 |
|
8078 |
|
8079 |
|
8080 | |
8081 |
|
8082 |
|
8083 |
|
8084 |
|
8085 |
|
8086 |
|
8087 |
|
8088 |
|
8089 | |
8090 |
|
8091 |
|
8092 |
|
8093 |
|
8094 |
|
8095 |
|
8096 |
|
8097 |
|
8098 | |
8099 |
|
8100 |
|
8101 |
|
8102 |
|
8103 |
|
8104 |
|
8105 |
|
8106 |
|
8107 | |
8108 |
|
8109 |
|
8110 |
|
8111 |
|
8112 |
|
8113 |
|
8114 |
|
8115 |
|
8116 | |
8117 |
|
8118 |
|
8119 |
|
8120 |
|
8121 |
|
8122 |
|
8123 |
|
8124 |
|
8125 | |
8126 |
|
8127 |
|
8128 |
|
8129 |
|
8130 |
|
8131 |
|
8132 |
|
8133 |
|
8134 | |
8135 |
|
8136 |
|
8137 |
|
8138 |
|
8139 |
|
8140 |
|
8141 |
|
8142 |
|
8143 | |
8144 |
|
8145 |
|
8146 |
|
8147 |
|
8148 |
|
8149 |
|
8150 |
|
8151 |
|
8152 | |
8153 |
|
8154 |
|
8155 |
|
8156 |
|
8157 |
|
8158 |
|
8159 |
|
8160 |
|
8161 | |
8162 |
|
8163 |
|
8164 |
|
8165 |
|
8166 |
|
8167 |
|
8168 |
|
8169 |
|
8170 | |
8171 |
|
8172 |
|
8173 |
|
8174 |
|
8175 |
|
8176 |
|
8177 |
|
8178 |
|
8179 | |
8180 |
|
8181 |
|
8182 |
|
8183 |
|
8184 |
|
8185 |
|
8186 |
|
8187 |
|
8188 | |
8189 |
|
8190 |
|
8191 |
|
8192 |
|
8193 |
|
8194 |
|
8195 |
|
8196 |
|
8197 | |
8198 |
|
8199 |
|
8200 |
|
8201 |
|
8202 |
|
8203 |
|
8204 |
|
8205 |
|
8206 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
8207 |
|
8208 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
8209 |
|
8210 | function _defineProperty$9(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
8211 |
|
8212 | |
8213 |
|
8214 |
|
8215 |
|
8216 |
|
8217 | var ASTValidationContext =
|
8218 |
|
8219 | function () {
|
8220 | function ASTValidationContext(ast) {
|
8221 | _defineProperty$9(this, "_ast", void 0);
|
8222 |
|
8223 | _defineProperty$9(this, "_errors", void 0);
|
8224 |
|
8225 | this._ast = ast;
|
8226 | this._errors = [];
|
8227 | }
|
8228 |
|
8229 | var _proto = ASTValidationContext.prototype;
|
8230 |
|
8231 | _proto.reportError = function reportError(error) {
|
8232 | this._errors.push(error);
|
8233 | };
|
8234 |
|
8235 | _proto.getErrors = function getErrors() {
|
8236 | return this._errors;
|
8237 | };
|
8238 |
|
8239 | _proto.getDocument = function getDocument() {
|
8240 | return this._ast;
|
8241 | };
|
8242 |
|
8243 | return ASTValidationContext;
|
8244 | }();
|
8245 | var SDLValidationContext =
|
8246 |
|
8247 | function (_ASTValidationContext) {
|
8248 | _inheritsLoose(SDLValidationContext, _ASTValidationContext);
|
8249 |
|
8250 | function SDLValidationContext(ast, schema) {
|
8251 | var _this;
|
8252 |
|
8253 | _this = _ASTValidationContext.call(this, ast) || this;
|
8254 |
|
8255 | _defineProperty$9(_assertThisInitialized(_assertThisInitialized(_this)), "_schema", void 0);
|
8256 |
|
8257 | _this._schema = schema;
|
8258 | return _this;
|
8259 | }
|
8260 |
|
8261 | var _proto2 = SDLValidationContext.prototype;
|
8262 |
|
8263 | _proto2.getSchema = function getSchema() {
|
8264 | return this._schema;
|
8265 | };
|
8266 |
|
8267 | return SDLValidationContext;
|
8268 | }(ASTValidationContext);
|
8269 | var ValidationContext =
|
8270 |
|
8271 | function (_ASTValidationContext2) {
|
8272 | _inheritsLoose(ValidationContext, _ASTValidationContext2);
|
8273 |
|
8274 | function ValidationContext(schema, ast, typeInfo) {
|
8275 | var _this2;
|
8276 |
|
8277 | _this2 = _ASTValidationContext2.call(this, ast) || this;
|
8278 |
|
8279 | _defineProperty$9(_assertThisInitialized(_assertThisInitialized(_this2)), "_schema", void 0);
|
8280 |
|
8281 | _defineProperty$9(_assertThisInitialized(_assertThisInitialized(_this2)), "_typeInfo", void 0);
|
8282 |
|
8283 | _defineProperty$9(_assertThisInitialized(_assertThisInitialized(_this2)), "_fragments", void 0);
|
8284 |
|
8285 | _defineProperty$9(_assertThisInitialized(_assertThisInitialized(_this2)), "_fragmentSpreads", void 0);
|
8286 |
|
8287 | _defineProperty$9(_assertThisInitialized(_assertThisInitialized(_this2)), "_recursivelyReferencedFragments", void 0);
|
8288 |
|
8289 | _defineProperty$9(_assertThisInitialized(_assertThisInitialized(_this2)), "_variableUsages", void 0);
|
8290 |
|
8291 | _defineProperty$9(_assertThisInitialized(_assertThisInitialized(_this2)), "_recursiveVariableUsages", void 0);
|
8292 |
|
8293 | _this2._schema = schema;
|
8294 | _this2._typeInfo = typeInfo;
|
8295 | _this2._fragmentSpreads = new Map();
|
8296 | _this2._recursivelyReferencedFragments = new Map();
|
8297 | _this2._variableUsages = new Map();
|
8298 | _this2._recursiveVariableUsages = new Map();
|
8299 | return _this2;
|
8300 | }
|
8301 |
|
8302 | var _proto3 = ValidationContext.prototype;
|
8303 |
|
8304 | _proto3.getSchema = function getSchema() {
|
8305 | return this._schema;
|
8306 | };
|
8307 |
|
8308 | _proto3.getFragment = function getFragment(name) {
|
8309 | var fragments = this._fragments;
|
8310 |
|
8311 | if (!fragments) {
|
8312 | this._fragments = fragments = this.getDocument().definitions.reduce(function (frags, statement) {
|
8313 | if (statement.kind === Kind.FRAGMENT_DEFINITION) {
|
8314 | frags[statement.name.value] = statement;
|
8315 | }
|
8316 |
|
8317 | return frags;
|
8318 | }, Object.create(null));
|
8319 | }
|
8320 |
|
8321 | return fragments[name];
|
8322 | };
|
8323 |
|
8324 | _proto3.getFragmentSpreads = function getFragmentSpreads(node) {
|
8325 | var spreads = this._fragmentSpreads.get(node);
|
8326 |
|
8327 | if (!spreads) {
|
8328 | spreads = [];
|
8329 | var setsToVisit = [node];
|
8330 |
|
8331 | while (setsToVisit.length !== 0) {
|
8332 | var set = setsToVisit.pop();
|
8333 |
|
8334 | for (var i = 0; i < set.selections.length; i++) {
|
8335 | var selection = set.selections[i];
|
8336 |
|
8337 | if (selection.kind === Kind.FRAGMENT_SPREAD) {
|
8338 | spreads.push(selection);
|
8339 | } else if (selection.selectionSet) {
|
8340 | setsToVisit.push(selection.selectionSet);
|
8341 | }
|
8342 | }
|
8343 | }
|
8344 |
|
8345 | this._fragmentSpreads.set(node, spreads);
|
8346 | }
|
8347 |
|
8348 | return spreads;
|
8349 | };
|
8350 |
|
8351 | _proto3.getRecursivelyReferencedFragments = function getRecursivelyReferencedFragments(operation) {
|
8352 | var fragments = this._recursivelyReferencedFragments.get(operation);
|
8353 |
|
8354 | if (!fragments) {
|
8355 | fragments = [];
|
8356 | var collectedNames = Object.create(null);
|
8357 | var nodesToVisit = [operation.selectionSet];
|
8358 |
|
8359 | while (nodesToVisit.length !== 0) {
|
8360 | var node = nodesToVisit.pop();
|
8361 | var spreads = this.getFragmentSpreads(node);
|
8362 |
|
8363 | for (var i = 0; i < spreads.length; i++) {
|
8364 | var fragName = spreads[i].name.value;
|
8365 |
|
8366 | if (collectedNames[fragName] !== true) {
|
8367 | collectedNames[fragName] = true;
|
8368 | var fragment = this.getFragment(fragName);
|
8369 |
|
8370 | if (fragment) {
|
8371 | fragments.push(fragment);
|
8372 | nodesToVisit.push(fragment.selectionSet);
|
8373 | }
|
8374 | }
|
8375 | }
|
8376 | }
|
8377 |
|
8378 | this._recursivelyReferencedFragments.set(operation, fragments);
|
8379 | }
|
8380 |
|
8381 | return fragments;
|
8382 | };
|
8383 |
|
8384 | _proto3.getVariableUsages = function getVariableUsages(node) {
|
8385 | var usages = this._variableUsages.get(node);
|
8386 |
|
8387 | if (!usages) {
|
8388 | var newUsages = [];
|
8389 | var typeInfo = new TypeInfo(this._schema);
|
8390 | visit(node, visitWithTypeInfo(typeInfo, {
|
8391 | VariableDefinition: function VariableDefinition() {
|
8392 | return false;
|
8393 | },
|
8394 | Variable: function Variable(variable) {
|
8395 | newUsages.push({
|
8396 | node: variable,
|
8397 | type: typeInfo.getInputType(),
|
8398 | defaultValue: typeInfo.getDefaultValue()
|
8399 | });
|
8400 | }
|
8401 | }));
|
8402 | usages = newUsages;
|
8403 |
|
8404 | this._variableUsages.set(node, usages);
|
8405 | }
|
8406 |
|
8407 | return usages;
|
8408 | };
|
8409 |
|
8410 | _proto3.getRecursiveVariableUsages = function getRecursiveVariableUsages(operation) {
|
8411 | var usages = this._recursiveVariableUsages.get(operation);
|
8412 |
|
8413 | if (!usages) {
|
8414 | usages = this.getVariableUsages(operation);
|
8415 | var fragments = this.getRecursivelyReferencedFragments(operation);
|
8416 |
|
8417 | for (var i = 0; i < fragments.length; i++) {
|
8418 | Array.prototype.push.apply(usages, this.getVariableUsages(fragments[i]));
|
8419 | }
|
8420 |
|
8421 | this._recursiveVariableUsages.set(operation, usages);
|
8422 | }
|
8423 |
|
8424 | return usages;
|
8425 | };
|
8426 |
|
8427 | _proto3.getType = function getType() {
|
8428 | return this._typeInfo.getType();
|
8429 | };
|
8430 |
|
8431 | _proto3.getParentType = function getParentType() {
|
8432 | return this._typeInfo.getParentType();
|
8433 | };
|
8434 |
|
8435 | _proto3.getInputType = function getInputType() {
|
8436 | return this._typeInfo.getInputType();
|
8437 | };
|
8438 |
|
8439 | _proto3.getParentInputType = function getParentInputType() {
|
8440 | return this._typeInfo.getParentInputType();
|
8441 | };
|
8442 |
|
8443 | _proto3.getFieldDef = function getFieldDef() {
|
8444 | return this._typeInfo.getFieldDef();
|
8445 | };
|
8446 |
|
8447 | _proto3.getDirective = function getDirective() {
|
8448 | return this._typeInfo.getDirective();
|
8449 | };
|
8450 |
|
8451 | _proto3.getArgument = function getArgument() {
|
8452 | return this._typeInfo.getArgument();
|
8453 | };
|
8454 |
|
8455 | return ValidationContext;
|
8456 | }(ASTValidationContext);
|
8457 |
|
8458 | |
8459 |
|
8460 |
|
8461 |
|
8462 |
|
8463 |
|
8464 |
|
8465 |
|
8466 |
|
8467 | |
8468 |
|
8469 |
|
8470 |
|
8471 |
|
8472 |
|
8473 |
|
8474 |
|
8475 |
|
8476 | |
8477 |
|
8478 |
|
8479 |
|
8480 |
|
8481 |
|
8482 |
|
8483 |
|
8484 |
|
8485 | |
8486 |
|
8487 |
|
8488 |
|
8489 |
|
8490 |
|
8491 |
|
8492 |
|
8493 |
|
8494 | |
8495 |
|
8496 |
|
8497 |
|
8498 |
|
8499 |
|
8500 |
|
8501 |
|
8502 |
|
8503 | |
8504 |
|
8505 |
|
8506 |
|
8507 |
|
8508 |
|
8509 |
|
8510 |
|
8511 |
|
8512 | |
8513 |
|
8514 |
|
8515 |
|
8516 |
|
8517 |
|
8518 |
|
8519 |
|
8520 |
|
8521 | |
8522 |
|
8523 |
|
8524 |
|
8525 |
|
8526 |
|
8527 |
|
8528 |
|
8529 |
|
8530 | |
8531 |
|
8532 |
|
8533 |
|
8534 |
|
8535 |
|
8536 |
|
8537 |
|
8538 |
|
8539 | |
8540 |
|
8541 |
|
8542 |
|
8543 |
|
8544 |
|
8545 |
|
8546 |
|
8547 |
|
8548 | |
8549 |
|
8550 |
|
8551 |
|
8552 |
|
8553 |
|
8554 |
|
8555 |
|
8556 |
|
8557 | |
8558 |
|
8559 |
|
8560 |
|
8561 |
|
8562 |
|
8563 |
|
8564 |
|
8565 |
|
8566 | |
8567 |
|
8568 |
|
8569 |
|
8570 |
|
8571 |
|
8572 |
|
8573 |
|
8574 |
|
8575 | |
8576 |
|
8577 |
|
8578 |
|
8579 |
|
8580 |
|
8581 |
|
8582 |
|
8583 |
|
8584 | |
8585 |
|
8586 |
|
8587 |
|
8588 |
|
8589 |
|
8590 |
|
8591 |
|
8592 |
|
8593 | |
8594 |
|
8595 |
|
8596 |
|
8597 |
|
8598 |
|
8599 |
|
8600 |
|
8601 | function getIntrospectionQuery(options) {
|
8602 | var descriptions = !(options && options.descriptions === false);
|
8603 | return "\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n ".concat(descriptions ? 'description' : '', "\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n ").concat(descriptions ? 'description' : '', "\n fields(includeDeprecated: true) {\n name\n ").concat(descriptions ? 'description' : '', "\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n ").concat(descriptions ? 'description' : '', "\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n ").concat(descriptions ? 'description' : '', "\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n ");
|
8604 | }
|
8605 | |
8606 |
|
8607 |
|
8608 |
|
8609 |
|
8610 |
|
8611 | var introspectionQuery = getIntrospectionQuery();
|
8612 |
|
8613 | |
8614 |
|
8615 |
|
8616 |
|
8617 |
|
8618 |
|
8619 |
|
8620 |
|
8621 |
|
8622 | |
8623 |
|
8624 |
|
8625 |
|
8626 |
|
8627 |
|
8628 |
|
8629 |
|
8630 |
|
8631 | |
8632 |
|
8633 |
|
8634 |
|
8635 |
|
8636 |
|
8637 |
|
8638 |
|
8639 |
|
8640 | |
8641 |
|
8642 |
|
8643 |
|
8644 |
|
8645 |
|
8646 |
|
8647 |
|
8648 |
|
8649 | |
8650 |
|
8651 |
|
8652 |
|
8653 |
|
8654 |
|
8655 |
|
8656 |
|
8657 |
|
8658 | |
8659 |
|
8660 |
|
8661 |
|
8662 |
|
8663 |
|
8664 |
|
8665 |
|
8666 |
|
8667 | |
8668 |
|
8669 |
|
8670 |
|
8671 |
|
8672 |
|
8673 |
|
8674 |
|
8675 |
|
8676 | |
8677 |
|
8678 |
|
8679 |
|
8680 |
|
8681 |
|
8682 |
|
8683 |
|
8684 |
|
8685 | |
8686 |
|
8687 |
|
8688 |
|
8689 |
|
8690 |
|
8691 |
|
8692 |
|
8693 |
|
8694 | |
8695 |
|
8696 |
|
8697 |
|
8698 |
|
8699 |
|
8700 |
|
8701 |
|
8702 |
|
8703 | |
8704 |
|
8705 |
|
8706 |
|
8707 |
|
8708 |
|
8709 |
|
8710 |
|
8711 |
|
8712 | |
8713 |
|
8714 |
|
8715 |
|
8716 |
|
8717 |
|
8718 |
|
8719 |
|
8720 |
|
8721 | var connectionRemoveConfig = {
|
8722 | test: function (directive) { return directive.name.value === 'client'; },
|
8723 | remove: true,
|
8724 | };
|
8725 | var removed = new Map();
|
8726 | function removeClientSetsFromDocument(query) {
|
8727 | var cached = removed.get(query);
|
8728 | if (cached)
|
8729 | return cached;
|
8730 | apolloUtilities.checkDocument(query);
|
8731 | var docClone = apolloUtilities.removeDirectivesFromDocument([connectionRemoveConfig], query);
|
8732 | removed.set(query, docClone);
|
8733 | return docClone;
|
8734 | }
|
8735 | function normalizeTypeDefs(typeDefs) {
|
8736 | var defs = Array.isArray(typeDefs) ? typeDefs : [typeDefs];
|
8737 | return defs
|
8738 | .map(function (typeDef) { return (typeof typeDef === 'string' ? typeDef : print(typeDef)); })
|
8739 | .map(function (str) { return str.trim(); })
|
8740 | .join('\n');
|
8741 | }
|
8742 |
|
8743 | var __extends$5 = (undefined && undefined.__extends) || (function () {
|
8744 | var extendStatics = Object.setPrototypeOf ||
|
8745 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
8746 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
8747 | return function (d, b) {
|
8748 | extendStatics(d, b);
|
8749 | function __() { this.constructor = d; }
|
8750 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
8751 | };
|
8752 | })();
|
8753 | var graphql$1 = Async.graphql;
|
8754 | var capitalizeFirstLetter = function (str) { return str.charAt(0).toUpperCase() + str.slice(1); };
|
8755 | var withClientState = function (clientStateConfig) {
|
8756 | if (clientStateConfig === void 0) { clientStateConfig = { resolvers: {}, defaults: {} }; }
|
8757 | var defaults = clientStateConfig.defaults, cache = clientStateConfig.cache, typeDefs = clientStateConfig.typeDefs, fragmentMatcher = clientStateConfig.fragmentMatcher;
|
8758 | if (cache && defaults) {
|
8759 | cache.writeData({ data: defaults });
|
8760 | }
|
8761 | return new (function (_super) {
|
8762 | __extends$5(StateLink, _super);
|
8763 | function StateLink() {
|
8764 | return _super !== null && _super.apply(this, arguments) || this;
|
8765 | }
|
8766 | StateLink.prototype.writeDefaults = function () {
|
8767 | if (cache && defaults) {
|
8768 | cache.writeData({ data: defaults });
|
8769 | }
|
8770 | };
|
8771 | StateLink.prototype.request = function (operation, forward) {
|
8772 | if (forward === void 0) { forward = function () { return Observable$2.of({ data: {} }); }; }
|
8773 | if (typeDefs) {
|
8774 | var directives_1 = 'directive @client on FIELD';
|
8775 | var definition_1 = normalizeTypeDefs(typeDefs);
|
8776 | operation.setContext(function (_a) {
|
8777 | var _b = _a.schemas, schemas = _b === void 0 ? [] : _b;
|
8778 | return ({
|
8779 | schemas: schemas.concat([{ definition: definition_1, directives: directives_1 }]),
|
8780 | });
|
8781 | });
|
8782 | }
|
8783 | var isClient = apolloUtilities.hasDirectives(['client'], operation.query);
|
8784 | if (!isClient)
|
8785 | return forward(operation);
|
8786 | var resolvers = typeof clientStateConfig.resolvers === 'function'
|
8787 | ? clientStateConfig.resolvers()
|
8788 | : clientStateConfig.resolvers;
|
8789 | var server = removeClientSetsFromDocument(operation.query);
|
8790 | var query = operation.query;
|
8791 | var type = capitalizeFirstLetter((apolloUtilities.getMainDefinition(query) || {}).operation) || 'Query';
|
8792 | var resolver = function (fieldName, rootValue, args, context, info) {
|
8793 | if (rootValue === void 0) { rootValue = {}; }
|
8794 | var resultKey = info.resultKey;
|
8795 | var aliasedNode = rootValue[resultKey];
|
8796 | var preAliasingNode = rootValue[fieldName];
|
8797 | var aliasNeeded = resultKey !== fieldName;
|
8798 | if (aliasedNode !== undefined || preAliasingNode !== undefined) {
|
8799 | return aliasedNode || preAliasingNode;
|
8800 | }
|
8801 | var resolverMap = resolvers[rootValue.__typename || type];
|
8802 | if (resolverMap) {
|
8803 | var resolve = resolverMap[fieldName];
|
8804 | if (resolve)
|
8805 | return resolve(rootValue, args, context, info);
|
8806 | }
|
8807 | return ((aliasNeeded ? aliasedNode : preAliasingNode) ||
|
8808 | (defaults || {})[fieldName]);
|
8809 | };
|
8810 | if (server)
|
8811 | operation.query = server;
|
8812 | var obs = server && forward
|
8813 | ? forward(operation)
|
8814 | : Observable$2.of({
|
8815 | data: {},
|
8816 | });
|
8817 | return new Observable$2(function (observer) {
|
8818 | var complete = false;
|
8819 | var handlingNext = false;
|
8820 | obs.subscribe({
|
8821 | next: function (_a) {
|
8822 | var data = _a.data, errors = _a.errors;
|
8823 | var observerErrorHandler = observer.error.bind(observer);
|
8824 | var context = operation.getContext();
|
8825 | handlingNext = true;
|
8826 | graphql$1(resolver, query, data, context, operation.variables, {
|
8827 | fragmentMatcher: fragmentMatcher,
|
8828 | })
|
8829 | .then(function (nextData) {
|
8830 | observer.next({
|
8831 | data: nextData,
|
8832 | errors: errors,
|
8833 | });
|
8834 | if (complete) {
|
8835 | observer.complete();
|
8836 | }
|
8837 | handlingNext = false;
|
8838 | })
|
8839 | .catch(observerErrorHandler);
|
8840 | },
|
8841 | error: observer.error.bind(observer),
|
8842 | complete: function () {
|
8843 | if (!handlingNext) {
|
8844 | observer.complete();
|
8845 | }
|
8846 | complete = true;
|
8847 | },
|
8848 | });
|
8849 | });
|
8850 | };
|
8851 | return StateLink;
|
8852 | }(ApolloLink$1))();
|
8853 | };
|
8854 |
|
8855 |
|
8856 | var __extends$6 = (undefined && undefined.__extends) || (function () {
|
8857 | var extendStatics = function (d, b) {
|
8858 | extendStatics = Object.setPrototypeOf ||
|
8859 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
8860 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
8861 | return extendStatics(d, b);
|
8862 | };
|
8863 | return function (d, b) {
|
8864 | extendStatics(d, b);
|
8865 | function __() { this.constructor = d; }
|
8866 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
8867 | };
|
8868 | })();
|
8869 | var onError = function (errorHandler) {
|
8870 | return new ApolloLink$1(function (operation, forward) {
|
8871 | return new Observable$2(function (observer) {
|
8872 | var sub;
|
8873 | var retriedSub;
|
8874 | var retriedResult;
|
8875 | try {
|
8876 | sub = forward(operation).subscribe({
|
8877 | next: function (result) {
|
8878 | if (result.errors) {
|
8879 | retriedResult = errorHandler({
|
8880 | graphQLErrors: result.errors,
|
8881 | response: result,
|
8882 | operation: operation,
|
8883 | forward: forward,
|
8884 | });
|
8885 | if (retriedResult) {
|
8886 | retriedSub = retriedResult.subscribe({
|
8887 | next: observer.next.bind(observer),
|
8888 | error: observer.error.bind(observer),
|
8889 | complete: observer.complete.bind(observer),
|
8890 | });
|
8891 | return;
|
8892 | }
|
8893 | }
|
8894 | observer.next(result);
|
8895 | },
|
8896 | error: function (networkError) {
|
8897 | retriedResult = errorHandler({
|
8898 | operation: operation,
|
8899 | networkError: networkError,
|
8900 |
|
8901 | graphQLErrors: networkError.result && networkError.result.errors,
|
8902 | forward: forward,
|
8903 | });
|
8904 | if (retriedResult) {
|
8905 | retriedSub = retriedResult.subscribe({
|
8906 | next: observer.next.bind(observer),
|
8907 | error: observer.error.bind(observer),
|
8908 | complete: observer.complete.bind(observer),
|
8909 | });
|
8910 | return;
|
8911 | }
|
8912 | observer.error(networkError);
|
8913 | },
|
8914 | complete: function () {
|
8915 |
|
8916 |
|
8917 | if (!retriedResult) {
|
8918 | observer.complete.bind(observer)();
|
8919 | }
|
8920 | },
|
8921 | });
|
8922 | }
|
8923 | catch (e) {
|
8924 | errorHandler({ networkError: e, operation: operation, forward: forward });
|
8925 | observer.error(e);
|
8926 | }
|
8927 | return function () {
|
8928 | if (sub)
|
8929 | sub.unsubscribe();
|
8930 | if (retriedSub)
|
8931 | sub.unsubscribe();
|
8932 | };
|
8933 | });
|
8934 | });
|
8935 | };
|
8936 | var ErrorLink = (function (_super) {
|
8937 | __extends$6(ErrorLink, _super);
|
8938 | function ErrorLink(errorHandler) {
|
8939 | var _this = _super.call(this) || this;
|
8940 | _this.link = onError(errorHandler);
|
8941 | return _this;
|
8942 | }
|
8943 | ErrorLink.prototype.request = function (operation, forward) {
|
8944 | return this.link.request(operation, forward);
|
8945 | };
|
8946 | return ErrorLink;
|
8947 | }(ApolloLink$1));
|
8948 |
|
8949 | var PRESET_CONFIG_KEYS = [
|
8950 | 'request',
|
8951 | 'uri',
|
8952 | 'credentials',
|
8953 | 'headers',
|
8954 | 'fetch',
|
8955 | 'fetchOptions',
|
8956 | 'clientState',
|
8957 | 'onError',
|
8958 | 'cacheRedirects',
|
8959 | 'cache',
|
8960 | ];
|
8961 | var DefaultClient = (function (_super) {
|
8962 | __extends(DefaultClient, _super);
|
8963 | function DefaultClient(config) {
|
8964 | if (config === void 0) { config = {}; }
|
8965 | var _this = this;
|
8966 | if (config) {
|
8967 | var diff = Object.keys(config).filter(function (key) { return PRESET_CONFIG_KEYS.indexOf(key) === -1; });
|
8968 | if (diff.length > 0) {
|
8969 | console.warn('ApolloBoost was initialized with unsupported options: ' +
|
8970 | ("" + diff.join(' ')));
|
8971 | }
|
8972 | }
|
8973 | var request = config.request, uri = config.uri, credentials = config.credentials, headers = config.headers, fetch = config.fetch, fetchOptions = config.fetchOptions, clientState = config.clientState, cacheRedirects = config.cacheRedirects, errorCallback = config.onError;
|
8974 | var cache = config.cache;
|
8975 | if (cache && cacheRedirects) {
|
8976 | throw new Error('Incompatible cache configuration. If providing `cache` then ' +
|
8977 | 'configure the provided instance with `cacheRedirects` instead.');
|
8978 | }
|
8979 | if (!cache) {
|
8980 | cache = cacheRedirects
|
8981 | ? new InMemoryCache({ cacheRedirects: cacheRedirects })
|
8982 | : new InMemoryCache();
|
8983 | }
|
8984 | var stateLink = clientState
|
8985 | ? withClientState(__assign({}, clientState, { cache: cache }))
|
8986 | : false;
|
8987 | var errorLink = errorCallback
|
8988 | ? onError(errorCallback)
|
8989 | : onError(function (_a) {
|
8990 | var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError;
|
8991 | if (graphQLErrors) {
|
8992 | graphQLErrors.map(function (_a) {
|
8993 | var message = _a.message, locations = _a.locations, path = _a.path;
|
8994 | return console.log("[GraphQL error]: Message: " + message + ", Location: " +
|
8995 | (locations + ", Path: " + path));
|
8996 | });
|
8997 | }
|
8998 | if (networkError) {
|
8999 | console.log("[Network error]: " + networkError);
|
9000 | }
|
9001 | });
|
9002 | var requestHandler = request
|
9003 | ? new ApolloLink$1(function (operation, forward) {
|
9004 | return new Observable$2(function (observer) {
|
9005 | var handle;
|
9006 | Promise.resolve(operation)
|
9007 | .then(function (oper) { return request(oper); })
|
9008 | .then(function () {
|
9009 | handle = forward(operation).subscribe({
|
9010 | next: observer.next.bind(observer),
|
9011 | error: observer.error.bind(observer),
|
9012 | complete: observer.complete.bind(observer),
|
9013 | });
|
9014 | })
|
9015 | .catch(observer.error.bind(observer));
|
9016 | return function () {
|
9017 | if (handle) {
|
9018 | handle.unsubscribe();
|
9019 | }
|
9020 | };
|
9021 | });
|
9022 | })
|
9023 | : false;
|
9024 | var httpLink = new HttpLink({
|
9025 | uri: uri || '/graphql',
|
9026 | fetch: fetch,
|
9027 | fetchOptions: fetchOptions || {},
|
9028 | credentials: credentials || 'same-origin',
|
9029 | headers: headers || {},
|
9030 | });
|
9031 | var link = ApolloLink$1.from([
|
9032 | errorLink,
|
9033 | requestHandler,
|
9034 | stateLink,
|
9035 | httpLink,
|
9036 | ].filter(function (x) { return !!x; }));
|
9037 | _this = _super.call(this, { cache: cache, link: link }) || this;
|
9038 | return _this;
|
9039 | }
|
9040 | return DefaultClient;
|
9041 | }(ApolloClient));
|
9042 |
|
9043 | exports.gql = graphqlTag;
|
9044 | exports.HttpLink = HttpLink;
|
9045 | exports.default = DefaultClient;
|
9046 | exports.ApolloClient = ApolloClient;
|
9047 | exports.ObservableQuery = ObservableQuery;
|
9048 | exports.isApolloError = isApolloError;
|
9049 | exports.ApolloError = ApolloError;
|
9050 | exports.Observable = Observable$2;
|
9051 | exports.createOperation = createOperation$1;
|
9052 | exports.makePromise = makePromise$1;
|
9053 | exports.toPromise = toPromise$1;
|
9054 | exports.fromPromise = fromPromise$1;
|
9055 | exports.fromError = fromError$1;
|
9056 | exports.empty = empty$1;
|
9057 | exports.from = from$1;
|
9058 | exports.split = split$1;
|
9059 | exports.concat = concat$1;
|
9060 | exports.ApolloLink = ApolloLink$1;
|
9061 | exports.execute = execute$1;
|
9062 | exports.InMemoryCache = InMemoryCache;
|
9063 | exports.defaultDataIdFromObject = defaultDataIdFromObject;
|
9064 | exports.StoreReader = StoreReader;
|
9065 | exports.assertIdValue = assertIdValue;
|
9066 | exports.WriteError = WriteError;
|
9067 | exports.enhanceErrorWithDocument = enhanceErrorWithDocument;
|
9068 | exports.StoreWriter = StoreWriter;
|
9069 | exports.HeuristicFragmentMatcher = HeuristicFragmentMatcher;
|
9070 | exports.IntrospectionFragmentMatcher = IntrospectionFragmentMatcher;
|
9071 | exports.ObjectCache = ObjectCache;
|
9072 | exports.defaultNormalizedCacheFactory = defaultNormalizedCacheFactory$1;
|
9073 |
|
9074 | Object.defineProperty(exports, '__esModule', { value: true });
|
9075 |
|
9076 | }));
|
9077 |
|