1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-client'), require('apollo-link'), require('apollo-cache-inmemory'), require('apollo-link-http'), require('apollo-link-state'), require('apollo-link-error'), require('graphql-tag')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', 'apollo-client', 'apollo-link', 'apollo-cache-inmemory', 'apollo-link-http', 'apollo-link-state', 'apollo-link-error', 'graphql-tag'], factory) :
|
4 | (global = global || self, factory((global.apollo = global.apollo || {}, global.apollo.boost = {}), global.apollo.core, global.apolloLink.core, global.apolloCacheInMemory, global.apolloLinkHttp, global.apolloLinkState, global.apolloLinkError, global.graphqlTag));
|
5 | }(this, function (exports, ApolloClient, apolloLink, apolloCacheInmemory, apolloLinkHttp, apolloLinkState, apolloLinkError, graphqlTag) { 'use strict';
|
6 |
|
7 | var ApolloClient__default = 'default' in ApolloClient ? ApolloClient['default'] : ApolloClient;
|
8 | graphqlTag = graphqlTag && graphqlTag.hasOwnProperty('default') ? graphqlTag['default'] : graphqlTag;
|
9 |
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | var extendStatics = function(d, b) {
|
27 | extendStatics = Object.setPrototypeOf ||
|
28 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
29 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
30 | return extendStatics(d, b);
|
31 | };
|
32 |
|
33 | function __extends(d, b) {
|
34 | extendStatics(d, b);
|
35 | function __() { this.constructor = d; }
|
36 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
37 | }
|
38 |
|
39 | var __assign = function() {
|
40 | __assign = Object.assign || function __assign(t) {
|
41 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
42 | s = arguments[i];
|
43 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
44 | }
|
45 | return t;
|
46 | };
|
47 | return __assign.apply(this, arguments);
|
48 | };
|
49 |
|
50 | var PRESET_CONFIG_KEYS = [
|
51 | 'request',
|
52 | 'uri',
|
53 | 'credentials',
|
54 | 'headers',
|
55 | 'fetch',
|
56 | 'fetchOptions',
|
57 | 'clientState',
|
58 | 'onError',
|
59 | 'cacheRedirects',
|
60 | 'cache',
|
61 | ];
|
62 | var DefaultClient = (function (_super) {
|
63 | __extends(DefaultClient, _super);
|
64 | function DefaultClient(config) {
|
65 | if (config === void 0) { config = {}; }
|
66 | var _this = this;
|
67 | if (config) {
|
68 | var diff = Object.keys(config).filter(function (key) { return PRESET_CONFIG_KEYS.indexOf(key) === -1; });
|
69 | if (diff.length > 0) {
|
70 | console.warn('ApolloBoost was initialized with unsupported options: ' +
|
71 | ("" + diff.join(' ')));
|
72 | }
|
73 | }
|
74 | 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;
|
75 | var cache = config.cache;
|
76 | if (cache && cacheRedirects) {
|
77 | throw new Error('Incompatible cache configuration. If providing `cache` then ' +
|
78 | 'configure the provided instance with `cacheRedirects` instead.');
|
79 | }
|
80 | if (!cache) {
|
81 | cache = cacheRedirects
|
82 | ? new apolloCacheInmemory.InMemoryCache({ cacheRedirects: cacheRedirects })
|
83 | : new apolloCacheInmemory.InMemoryCache();
|
84 | }
|
85 | var stateLink = clientState
|
86 | ? apolloLinkState.withClientState(__assign({}, clientState, { cache: cache }))
|
87 | : false;
|
88 | var errorLink = errorCallback
|
89 | ? apolloLinkError.onError(errorCallback)
|
90 | : apolloLinkError.onError(function (_a) {
|
91 | var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError;
|
92 | if (graphQLErrors) {
|
93 | graphQLErrors.map(function (_a) {
|
94 | var message = _a.message, locations = _a.locations, path = _a.path;
|
95 | return console.log("[GraphQL error]: Message: " + message + ", Location: " +
|
96 | (locations + ", Path: " + path));
|
97 | });
|
98 | }
|
99 | if (networkError) {
|
100 | console.log("[Network error]: " + networkError);
|
101 | }
|
102 | });
|
103 | var requestHandler = request
|
104 | ? new apolloLink.ApolloLink(function (operation, forward) {
|
105 | return new apolloLink.Observable(function (observer) {
|
106 | var handle;
|
107 | Promise.resolve(operation)
|
108 | .then(function (oper) { return request(oper); })
|
109 | .then(function () {
|
110 | handle = forward(operation).subscribe({
|
111 | next: observer.next.bind(observer),
|
112 | error: observer.error.bind(observer),
|
113 | complete: observer.complete.bind(observer),
|
114 | });
|
115 | })
|
116 | .catch(observer.error.bind(observer));
|
117 | return function () {
|
118 | if (handle) {
|
119 | handle.unsubscribe();
|
120 | }
|
121 | };
|
122 | });
|
123 | })
|
124 | : false;
|
125 | var httpLink = new apolloLinkHttp.HttpLink({
|
126 | uri: uri || '/graphql',
|
127 | fetch: fetch,
|
128 | fetchOptions: fetchOptions || {},
|
129 | credentials: credentials || 'same-origin',
|
130 | headers: headers || {},
|
131 | });
|
132 | var link = apolloLink.ApolloLink.from([
|
133 | errorLink,
|
134 | requestHandler,
|
135 | stateLink,
|
136 | httpLink,
|
137 | ].filter(function (x) { return !!x; }));
|
138 | _this = _super.call(this, { cache: cache, link: link }) || this;
|
139 | return _this;
|
140 | }
|
141 | return DefaultClient;
|
142 | }(ApolloClient__default));
|
143 |
|
144 | Object.keys(ApolloClient).forEach(function (key) { exports[key] = ApolloClient[key]; });
|
145 | Object.keys(apolloLink).forEach(function (key) { exports[key] = apolloLink[key]; });
|
146 | Object.keys(apolloCacheInmemory).forEach(function (key) { exports[key] = apolloCacheInmemory[key]; });
|
147 | exports.HttpLink = apolloLinkHttp.HttpLink;
|
148 | exports.gql = graphqlTag;
|
149 | exports.default = DefaultClient;
|
150 |
|
151 | Object.defineProperty(exports, '__esModule', { value: true });
|
152 |
|
153 | }));
|
154 |
|