1 | (function (global, factory) {
|
2 | if (typeof define === "function" && define.amd) {
|
3 | define(["exports", "tslib", "apollo-client", "apollo-link", "apollo-cache-inmemory", "apollo-link-http", "apollo-link-error", "graphql-tag", "ts-invariant"], factory);
|
4 | } else if (typeof exports !== "undefined") {
|
5 | factory(exports, require("tslib"), require("apollo-client"), require("apollo-link"), require("apollo-cache-inmemory"), require("apollo-link-http"), require("apollo-link-error"), require("graphql-tag"), require("ts-invariant"));
|
6 | } else {
|
7 | var mod = {
|
8 | exports: {}
|
9 | };
|
10 | factory(mod.exports, global.tslib, global.apolloClient, global.apolloLink, global.apolloCacheInmemory, global.apolloLinkHttp, global.apolloLinkError, global.graphqlTag, global.tsInvariant);
|
11 | global.unknown = mod.exports;
|
12 | }
|
13 | })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _tslib, _apolloClient, _apolloLink, _apolloCacheInmemory, _apolloLinkHttp, _apolloLinkError, _graphqlTag, _tsInvariant) {
|
14 |
|
15 | _exports.__esModule = true;
|
16 | var _exportNames = {
|
17 | gql: true,
|
18 | HttpLink: true
|
19 | };
|
20 | _exports.default = _exports.gql = void 0;
|
21 | _apolloClient = _interopRequireWildcard(_apolloClient);
|
22 | Object.keys(_apolloClient).forEach(function (key) {
|
23 | if (key === "default" || key === "__esModule") return;
|
24 | if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
25 | _exports[key] = _apolloClient[key];
|
26 | });
|
27 | Object.keys(_apolloLink).forEach(function (key) {
|
28 | if (key === "default" || key === "__esModule") return;
|
29 | if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
30 | _exports[key] = _apolloLink[key];
|
31 | });
|
32 | Object.keys(_apolloCacheInmemory).forEach(function (key) {
|
33 | if (key === "default" || key === "__esModule") return;
|
34 | if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
35 | _exports[key] = _apolloCacheInmemory[key];
|
36 | });
|
37 | _exports.HttpLink = _apolloLinkHttp.HttpLink;
|
38 | _graphqlTag = _interopRequireDefault(_graphqlTag);
|
39 | _exports.gql = _graphqlTag.default;
|
40 |
|
41 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
42 |
|
43 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
44 |
|
45 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
46 |
|
47 | var PRESET_CONFIG_KEYS = ['request', 'uri', 'credentials', 'headers', 'fetch', 'fetchOptions', 'clientState', 'onError', 'cacheRedirects', 'cache', 'name', 'version', 'resolvers', 'typeDefs', 'fragmentMatcher'];
|
48 |
|
49 | var DefaultClient = function (_super) {
|
50 | (0, _tslib.__extends)(DefaultClient, _super);
|
51 |
|
52 | function DefaultClient(config) {
|
53 | if (config === void 0) {
|
54 | config = {};
|
55 | }
|
56 |
|
57 | var _this = this;
|
58 |
|
59 | if (config) {
|
60 | var diff = Object.keys(config).filter(function (key) {
|
61 | return PRESET_CONFIG_KEYS.indexOf(key) === -1;
|
62 | });
|
63 |
|
64 | if (diff.length > 0) {
|
65 | process.env.NODE_ENV === "production" || _tsInvariant.invariant.warn('ApolloBoost was initialized with unsupported options: ' + ("" + diff.join(' ')));
|
66 | }
|
67 | }
|
68 |
|
69 | var request = config.request,
|
70 | uri = config.uri,
|
71 | credentials = config.credentials,
|
72 | headers = config.headers,
|
73 | fetch = config.fetch,
|
74 | fetchOptions = config.fetchOptions,
|
75 | clientState = config.clientState,
|
76 | cacheRedirects = config.cacheRedirects,
|
77 | errorCallback = config.onError,
|
78 | name = config.name,
|
79 | version = config.version,
|
80 | resolvers = config.resolvers,
|
81 | typeDefs = config.typeDefs,
|
82 | fragmentMatcher = config.fragmentMatcher;
|
83 | var cache = config.cache;
|
84 | process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(!cache || !cacheRedirects, 1) : (0, _tsInvariant.invariant)(!cache || !cacheRedirects, 'Incompatible cache configuration. When not providing `cache`, ' + 'configure the provided instance with `cacheRedirects` instead.');
|
85 |
|
86 | if (!cache) {
|
87 | cache = cacheRedirects ? new _apolloCacheInmemory.InMemoryCache({
|
88 | cacheRedirects: cacheRedirects
|
89 | }) : new _apolloCacheInmemory.InMemoryCache();
|
90 | }
|
91 |
|
92 | var errorLink = errorCallback ? (0, _apolloLinkError.onError)(errorCallback) : (0, _apolloLinkError.onError)(function (_a) {
|
93 | var graphQLErrors = _a.graphQLErrors,
|
94 | networkError = _a.networkError;
|
95 |
|
96 | if (graphQLErrors) {
|
97 | graphQLErrors.forEach(function (_a) {
|
98 | var message = _a.message,
|
99 | locations = _a.locations,
|
100 | path = _a.path;
|
101 | return process.env.NODE_ENV === "production" || _tsInvariant.invariant.warn("[GraphQL error]: Message: " + message + ", Location: " + (locations + ", Path: " + path));
|
102 | });
|
103 | }
|
104 |
|
105 | if (networkError) {
|
106 | process.env.NODE_ENV === "production" || _tsInvariant.invariant.warn("[Network error]: " + networkError);
|
107 | }
|
108 | });
|
109 | var requestHandler = request ? new _apolloLink.ApolloLink(function (operation, forward) {
|
110 | return new _apolloLink.Observable(function (observer) {
|
111 | var handle;
|
112 | Promise.resolve(operation).then(function (oper) {
|
113 | return request(oper);
|
114 | }).then(function () {
|
115 | handle = forward(operation).subscribe({
|
116 | next: observer.next.bind(observer),
|
117 | error: observer.error.bind(observer),
|
118 | complete: observer.complete.bind(observer)
|
119 | });
|
120 | }).catch(observer.error.bind(observer));
|
121 | return function () {
|
122 | if (handle) {
|
123 | handle.unsubscribe();
|
124 | }
|
125 | };
|
126 | });
|
127 | }) : false;
|
128 | var httpLink = new _apolloLinkHttp.HttpLink({
|
129 | uri: uri || '/graphql',
|
130 | fetch: fetch,
|
131 | fetchOptions: fetchOptions || {},
|
132 | credentials: credentials || 'same-origin',
|
133 | headers: headers || {}
|
134 | });
|
135 |
|
136 | var link = _apolloLink.ApolloLink.from([errorLink, requestHandler, httpLink].filter(function (x) {
|
137 | return !!x;
|
138 | }));
|
139 |
|
140 | var activeResolvers = resolvers;
|
141 | var activeTypeDefs = typeDefs;
|
142 | var activeFragmentMatcher = fragmentMatcher;
|
143 |
|
144 | if (clientState) {
|
145 | if (clientState.defaults) {
|
146 | cache.writeData({
|
147 | data: clientState.defaults
|
148 | });
|
149 | }
|
150 |
|
151 | activeResolvers = clientState.resolvers;
|
152 | activeTypeDefs = clientState.typeDefs;
|
153 | activeFragmentMatcher = clientState.fragmentMatcher;
|
154 | }
|
155 |
|
156 | _this = _super.call(this, {
|
157 | cache: cache,
|
158 | link: link,
|
159 | name: name,
|
160 | version: version,
|
161 | resolvers: activeResolvers,
|
162 | typeDefs: activeTypeDefs,
|
163 | fragmentMatcher: activeFragmentMatcher
|
164 | }) || this;
|
165 | return _this;
|
166 | }
|
167 |
|
168 | return DefaultClient;
|
169 | }(_apolloClient.default);
|
170 |
|
171 | var _default = DefaultClient;
|
172 |
|
173 | _exports.default = _default;
|
174 | });
|