UNPKG

7.11 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? 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')) :
3 typeof define === 'function' && define.amd ? define(['exports', 'tslib', 'apollo-client', 'apollo-link', 'apollo-cache-inmemory', 'apollo-link-http', 'apollo-link-error', 'graphql-tag', 'ts-invariant'], factory) :
4 (global = global || self, factory(global['apollo.boost'] = {}, global.tslib, global.apollo.core, global.apolloLink.core, global.apolloCacheInMemory, global.apolloLinkHttp, global.apolloLinkError, global.graphqlTag, global.invariant));
5}(this, function (exports, tslib, ApolloClient__default, apolloLink, apolloCacheInmemory, apolloLinkHttp, apolloLinkError, graphqlTag, tsInvariant) { 'use strict';
6
7 var ApolloClient__default__default = 'default' in ApolloClient__default ? ApolloClient__default['default'] : ApolloClient__default;
8 graphqlTag = graphqlTag && graphqlTag.hasOwnProperty('default') ? graphqlTag['default'] : graphqlTag;
9
10 var PRESET_CONFIG_KEYS = [
11 'request',
12 'uri',
13 'credentials',
14 'headers',
15 'fetch',
16 'fetchOptions',
17 'clientState',
18 'onError',
19 'cacheRedirects',
20 'cache',
21 'name',
22 'version',
23 'resolvers',
24 'typeDefs',
25 'fragmentMatcher',
26 ];
27 var DefaultClient = (function (_super) {
28 tslib.__extends(DefaultClient, _super);
29 function DefaultClient(config) {
30 if (config === void 0) { config = {}; }
31 var _this = this;
32 if (config) {
33 var diff = Object.keys(config).filter(function (key) { return PRESET_CONFIG_KEYS.indexOf(key) === -1; });
34 if (diff.length > 0) {
35 process.env.NODE_ENV === "production" || tsInvariant.invariant.warn('ApolloBoost was initialized with unsupported options: ' +
36 ("" + diff.join(' ')));
37 }
38 }
39 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, name = config.name, version = config.version, resolvers = config.resolvers, typeDefs = config.typeDefs, fragmentMatcher = config.fragmentMatcher;
40 var cache = config.cache;
41 process.env.NODE_ENV === "production" ? tsInvariant.invariant(!cache || !cacheRedirects) : tsInvariant.invariant(!cache || !cacheRedirects, 'Incompatible cache configuration. If providing `cache` then ' +
42 'configure the provided instance with `cacheRedirects` instead.');
43 if (!cache) {
44 cache = cacheRedirects
45 ? new apolloCacheInmemory.InMemoryCache({ cacheRedirects: cacheRedirects })
46 : new apolloCacheInmemory.InMemoryCache();
47 }
48 var errorLink = errorCallback
49 ? apolloLinkError.onError(errorCallback)
50 : apolloLinkError.onError(function (_a) {
51 var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError;
52 if (graphQLErrors) {
53 graphQLErrors.map(function (_a) {
54 var message = _a.message, locations = _a.locations, path = _a.path;
55 return process.env.NODE_ENV === "production" || tsInvariant.invariant.warn("[GraphQL error]: Message: " + message + ", Location: " +
56 (locations + ", Path: " + path));
57 });
58 }
59 if (networkError) {
60 process.env.NODE_ENV === "production" || tsInvariant.invariant.warn("[Network error]: " + networkError);
61 }
62 });
63 var requestHandler = request
64 ? new apolloLink.ApolloLink(function (operation, forward) {
65 return new apolloLink.Observable(function (observer) {
66 var handle;
67 Promise.resolve(operation)
68 .then(function (oper) { return request(oper); })
69 .then(function () {
70 handle = forward(operation).subscribe({
71 next: observer.next.bind(observer),
72 error: observer.error.bind(observer),
73 complete: observer.complete.bind(observer),
74 });
75 })
76 .catch(observer.error.bind(observer));
77 return function () {
78 if (handle) {
79 handle.unsubscribe();
80 }
81 };
82 });
83 })
84 : false;
85 var httpLink = new apolloLinkHttp.HttpLink({
86 uri: uri || '/graphql',
87 fetch: fetch,
88 fetchOptions: fetchOptions || {},
89 credentials: credentials || 'same-origin',
90 headers: headers || {},
91 });
92 var link = apolloLink.ApolloLink.from([errorLink, requestHandler, httpLink].filter(function (x) { return !!x; }));
93 var activeResolvers = resolvers;
94 var activeTypeDefs = typeDefs;
95 var activeFragmentMatcher = fragmentMatcher;
96 if (clientState) {
97 if (clientState.defaults) {
98 cache.writeData({
99 data: clientState.defaults,
100 });
101 }
102 activeResolvers = clientState.resolvers;
103 activeTypeDefs = clientState.typeDefs;
104 activeFragmentMatcher = clientState.fragmentMatcher;
105 }
106 _this = _super.call(this, {
107 cache: cache,
108 link: link,
109 name: name,
110 version: version,
111 resolvers: activeResolvers,
112 typeDefs: activeTypeDefs,
113 fragmentMatcher: activeFragmentMatcher,
114 }) || this;
115 return _this;
116 }
117 return DefaultClient;
118 }(ApolloClient__default__default));
119
120 Object.keys(ApolloClient__default).forEach(function (key) { exports[key] = ApolloClient__default[key]; });
121 Object.keys(apolloLink).forEach(function (key) { exports[key] = apolloLink[key]; });
122 Object.keys(apolloCacheInmemory).forEach(function (key) { exports[key] = apolloCacheInmemory[key]; });
123 exports.HttpLink = apolloLinkHttp.HttpLink;
124 exports.gql = graphqlTag;
125 exports.default = DefaultClient;
126
127 Object.defineProperty(exports, '__esModule', { value: true });
128
129}));
130//# sourceMappingURL=bundle.umd.js.map