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