function ApolloClient(options) { if (options === void 0) { options = {}; } var _this = this; this.middleware = function () { return function (store) { _this.setStore(store); return function (next) { return function (action) { var previousApolloState = _this.queryManager.selectApolloState(store); var returnValue = next(action); var newApolloState = _this.queryManager.selectApolloState(store); if (newApolloState !== previousApolloState) { _this.queryManager.broadcastNewStore(store.getState()); } if (_this.devToolsHookCb) { _this.devToolsHookCb({ action: action, state: _this.queryManager.getApolloState(), dataWithOptimisticResults: _this.queryManager.getDataWithOptimisticResults(), }); } return returnValue; }; }; }; }; var dataIdFromObject = options.dataIdFromObject; var networkInterface = options.networkInterface, reduxRootSelector = options.reduxRootSelector, initialState = options.initialState , _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.addTypename, addTypename = _c === void 0 ? true : _c, customResolvers = options.customResolvers, connectToDevTools = options.connectToDevTools, fragmentMatcher = options.fragmentMatcher, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d; if (typeof reduxRootSelector === 'function') { this.reduxRootSelector = reduxRootSelector; } else if (typeof reduxRootSelector !== 'undefined') { throw new Error('"reduxRootSelector" must be a function.'); } if (typeof fragmentMatcher === 'undefined') { this.fragmentMatcher = new HeuristicFragmentMatcher(); } else { this.fragmentMatcher = fragmentMatcher; } this.initialState = initialState ? initialState : {}; this.networkInterface = networkInterface ? networkInterface : createNetworkInterface({ uri: '/graphql' }); this.addTypename = addTypename; this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0; this.dataId = dataIdFromObject = dataIdFromObject || defaultDataIdFromObject; this.fieldWithArgs = storeKeyNameFromFieldNameAndArgs; this.queryDeduplication = queryDeduplication; if (ssrForceFetchDelay) { setTimeout(function () { return _this.disableNetworkFetches = false; }, ssrForceFetchDelay); } this.reducerConfig = { dataIdFromObject: dataIdFromObject, customResolvers: customResolvers, addTypename: addTypename, fragmentMatcher: this.fragmentMatcher.match, }; this.watchQuery = this.watchQuery.bind(this); this.query = this.query.bind(this); this.mutate = this.mutate.bind(this); this.setStore = this.setStore.bind(this); this.resetStore = this.resetStore.bind(this); var defaultConnectToDevTools = !isProduction() && typeof window !== 'undefined' && (!window.__APOLLO_CLIENT__); if (typeof connectToDevTools === 'undefined' ? defaultConnectToDevTools : connectToDevTools) { window.__APOLLO_CLIENT__ = this; } if (!hasSuggestedDevtools && !isProduction()) { hasSuggestedDevtools = true; if (typeof window !== 'undefined' && window.document && window.top === window.self) { if (typeof window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') { if (navigator.userAgent.indexOf('Chrome') > -1) { console.debug('Download the Apollo DevTools ' + 'for a better development experience: ' + 'https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm'); } } } } this.version = version; }
n/a
function ApolloError(_a) { var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo ; var _this = _super.call(this, errorMessage) || this; _this.graphQLErrors = graphQLErrors || []; _this.networkError = networkError || null; if (!errorMessage) { _this.message = generateErrorMessage(_this); } else { _this.message = errorMessage; } _this.extraInfo = extraInfo; return _this; }
n/a
function HTTPBatchedNetworkInterface(uri, batchInterval, fetchOpts) { var _this = _super.call(this, uri, fetchOpts) || this; if (typeof batchInterval !== 'number') { throw new Error("batchInterval must be a number, got " + batchInterval); } _this.batcher = new QueryBatcher({ batchInterval: batchInterval, batchFetchFunction: _this.batchQuery.bind(_this), }); return _this; }
n/a
function HTTPFetchNetworkInterface() { return _super !== null && _super.apply(this, arguments) || this; }
n/a
function IntrospectionFragmentMatcher(options) { if (options && options.introspectionQueryResultData) { this.possibleTypesMap = this.parseIntrospectionResult(options.introspectionQueryResultData); this.isReady = true; } else { this.isReady = false; } this.match = this.match.bind(this); }
n/a
function ObservableQuery(_a) { var scheduler = _a.scheduler, options = _a.options, _b = _a.shouldSubscribe, shouldSubscribe = _b === void 0 ? true : _b; var _this = this; var queryManager = scheduler.queryManager; var queryId = queryManager.generateQueryId(); var subscriberFunction = function (observer) { return _this.onSubscribe(observer); }; _this = _super.call(this, subscriberFunction) || this; _this.isCurrentlyPolling = false; _this.options = options; _this.variables = _this.options.variables || {}; _this.scheduler = scheduler; _this.queryManager = queryManager; _this.queryId = queryId; _this.shouldSubscribe = shouldSubscribe; _this.observers = []; _this.subscriptionHandles = []; return _this; }
n/a
function addTypenameToDocument(doc) { checkDocument(doc); var docClone = cloneDeep(doc); docClone.definitions.forEach(function (definition) { var isRoot = definition.kind === 'OperationDefinition'; addTypenameToSelectionSet(definition.selectionSet, isRoot); }); return docClone; }
n/a
function createApolloReducer(config) { return function apolloReducer(state, action) { if (state === void 0) { state = {}; } try { var newState = { queries: queries(state.queries, action), mutations: mutations(state.mutations, action), data: data(state.data, action, state.queries, state.mutations, config), optimistic: [], reducerError: null, }; newState.optimistic = optimistic(state.optimistic, action, newState, config); if (state.data === newState.data && state.mutations === newState.mutations && state.queries === newState.queries && state.optimistic === newState.optimistic && state.reducerError === newState.reducerError) { return state; } return newState; } catch (reducerError) { return __assign$2({}, state, { reducerError: createReducerError(reducerError, action) }); } }; }
n/a
function createApolloStore(_a) { var _b = _a === void 0 ? {} : _a, _c = _b.reduxRootKey, reduxRootKey = _c === void 0 ? 'apollo' : _c, initialState = _b.initialState , _d = _b.config, config = _d === void 0 ? {} : _d, _e = _b.reportCrashes, reportCrashes = _e === void 0 ? true : _e, logger = _b .logger; var enhancers = []; var middlewares = []; if (reportCrashes) { middlewares.push(crashReporter); } if (logger) { middlewares.push(logger); } if (middlewares.length > 0) { enhancers.push(redux.applyMiddleware.apply(void 0, middlewares)); } if (typeof window !== 'undefined') { var anyWindow = window; if (anyWindow.devToolsExtension) { enhancers.push(anyWindow.devToolsExtension()); } } var compose$$1 = redux.compose; if (initialState && initialState[reduxRootKey] && initialState[reduxRootKey]['queries']) { throw new Error('Apollo initial state may not contain queries, only data'); } if (initialState && initialState[reduxRootKey] && initialState[reduxRootKey]['mutations']) { throw new Error('Apollo initial state may not contain mutations, only data'); } return redux.createStore(redux.combineReducers((_f = {}, _f[reduxRootKey] = createApolloReducer(config), _f)), initialState, compose$$1.apply(void 0, enhancers)); var _f; }
n/a
function createBatchingNetworkInterface(options) { if (!options) { throw new Error('You must pass an options argument to createNetworkInterface.'); } return new HTTPBatchedNetworkInterface(options.uri, options.batchInterval, options.opts || {}); }
n/a
function createFragmentMap(fragments) { if (fragments === void 0) { fragments = []; } var symTable = {}; fragments.forEach(function (fragment) { symTable[fragment.name.value] = fragment; }); return symTable; }
n/a
function createNetworkInterface(uriOrInterfaceOpts, secondArgOpts) { if (secondArgOpts === void 0) { secondArgOpts = {}; } if (!uriOrInterfaceOpts) { throw new Error('You must pass an options argument to createNetworkInterface.'); } var uri; var opts; if (typeof uriOrInterfaceOpts === 'string') { console.warn("Passing the URI as the first argument to createNetworkInterface is deprecated as of Apollo Client 0.5. Please pass it as the\"uri\" property of the network interface options."); opts = secondArgOpts; uri = uriOrInterfaceOpts; } else { opts = uriOrInterfaceOpts.opts; uri = uriOrInterfaceOpts.uri; } return new HTTPFetchNetworkInterface(uri, opts); }
n/a
function ApolloClient(options) { if (options === void 0) { options = {}; } var _this = this; this.middleware = function () { return function (store) { _this.setStore(store); return function (next) { return function (action) { var previousApolloState = _this.queryManager.selectApolloState(store); var returnValue = next(action); var newApolloState = _this.queryManager.selectApolloState(store); if (newApolloState !== previousApolloState) { _this.queryManager.broadcastNewStore(store.getState()); } if (_this.devToolsHookCb) { _this.devToolsHookCb({ action: action, state: _this.queryManager.getApolloState(), dataWithOptimisticResults: _this.queryManager.getDataWithOptimisticResults(), }); } return returnValue; }; }; }; }; var dataIdFromObject = options.dataIdFromObject; var networkInterface = options.networkInterface, reduxRootSelector = options.reduxRootSelector, initialState = options.initialState , _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.addTypename, addTypename = _c === void 0 ? true : _c, customResolvers = options.customResolvers, connectToDevTools = options.connectToDevTools, fragmentMatcher = options.fragmentMatcher, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d; if (typeof reduxRootSelector === 'function') { this.reduxRootSelector = reduxRootSelector; } else if (typeof reduxRootSelector !== 'undefined') { throw new Error('"reduxRootSelector" must be a function.'); } if (typeof fragmentMatcher === 'undefined') { this.fragmentMatcher = new HeuristicFragmentMatcher(); } else { this.fragmentMatcher = fragmentMatcher; } this.initialState = initialState ? initialState : {}; this.networkInterface = networkInterface ? networkInterface : createNetworkInterface({ uri: '/graphql' }); this.addTypename = addTypename; this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0; this.dataId = dataIdFromObject = dataIdFromObject || defaultDataIdFromObject; this.fieldWithArgs = storeKeyNameFromFieldNameAndArgs; this.queryDeduplication = queryDeduplication; if (ssrForceFetchDelay) { setTimeout(function () { return _this.disableNetworkFetches = false; }, ssrForceFetchDelay); } this.reducerConfig = { dataIdFromObject: dataIdFromObject, customResolvers: customResolvers, addTypename: addTypename, fragmentMatcher: this.fragmentMatcher.match, }; this.watchQuery = this.watchQuery.bind(this); this.query = this.query.bind(this); this.mutate = this.mutate.bind(this); this.setStore = this.setStore.bind(this); this.resetStore = this.resetStore.bind(this); var defaultConnectToDevTools = !isProduction() && typeof window !== 'undefined' && (!window.__APOLLO_CLIENT__); if (typeof connectToDevTools === 'undefined' ? defaultConnectToDevTools : connectToDevTools) { window.__APOLLO_CLIENT__ = this; } if (!hasSuggestedDevtools && !isProduction()) { hasSuggestedDevtools = true; if (typeof window !== 'undefined' && window.document && window.top === window.self) { if (typeof window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') { if (navigator.userAgent.indexOf('Chrome') > -1) { console.debug('Download the Apollo DevTools ' + 'for a better development experience: ' + 'https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm'); } } } } this.version = version; }
n/a
function getFragmentDefinitions(doc) { var fragmentDefinitions = doc.definitions.filter(function (definition) { if (definition.kind === 'FragmentDefinition') { return true; } else { return false; } }); return fragmentDefinitions; }
n/a
function getQueryDefinition(doc) { checkDocument(doc); var queryDef = null; doc.definitions.map(function (definition) { if (definition.kind === 'OperationDefinition' && definition.operation === 'query') { queryDef = definition; } }); if (!queryDef) { throw new Error('Must contain a query definition.'); } return queryDef; }
n/a
function print(ast) { return (0, _visitor.visit)(ast, { leave: printDocASTReducer }); }
n/a
function readQueryFromStore(options) { var optsPatch = { returnPartialData: false }; return diffQueryAgainstStore(__assign$8({}, options, optsPatch)).result; }
n/a
function toIdValue(id, generated) { if (generated === void 0) { generated = false; } return { type: 'id', id: id, generated: generated, }; }
n/a
function writeQueryToStore(_a) { var result = _a.result, query = _a.query, _b = _a.store, store = _b === void 0 ? {} : _b, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, _c = _a.fragmentMap, fragmentMap = _c === void 0 ? {} : _c; var queryDefinition = getQueryDefinition(query); return writeSelectionSetToStore({ dataId: 'ROOT_QUERY', result: result, selectionSet: queryDefinition.selectionSet, context: { store: store, variables: variables, dataIdFromObject: dataIdFromObject, fragmentMap: fragmentMap, }, }); }
n/a
function ApolloClient(options) { if (options === void 0) { options = {}; } var _this = this; this.middleware = function () { return function (store) { _this.setStore(store); return function (next) { return function (action) { var previousApolloState = _this.queryManager.selectApolloState(store); var returnValue = next(action); var newApolloState = _this.queryManager.selectApolloState(store); if (newApolloState !== previousApolloState) { _this.queryManager.broadcastNewStore(store.getState()); } if (_this.devToolsHookCb) { _this.devToolsHookCb({ action: action, state: _this.queryManager.getApolloState(), dataWithOptimisticResults: _this.queryManager.getDataWithOptimisticResults(), }); } return returnValue; }; }; }; }; var dataIdFromObject = options.dataIdFromObject; var networkInterface = options.networkInterface, reduxRootSelector = options.reduxRootSelector, initialState = options.initialState , _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.addTypename, addTypename = _c === void 0 ? true : _c, customResolvers = options.customResolvers, connectToDevTools = options.connectToDevTools, fragmentMatcher = options.fragmentMatcher, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d; if (typeof reduxRootSelector === 'function') { this.reduxRootSelector = reduxRootSelector; } else if (typeof reduxRootSelector !== 'undefined') { throw new Error('"reduxRootSelector" must be a function.'); } if (typeof fragmentMatcher === 'undefined') { this.fragmentMatcher = new HeuristicFragmentMatcher(); } else { this.fragmentMatcher = fragmentMatcher; } this.initialState = initialState ? initialState : {}; this.networkInterface = networkInterface ? networkInterface : createNetworkInterface({ uri: '/graphql' }); this.addTypename = addTypename; this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0; this.dataId = dataIdFromObject = dataIdFromObject || defaultDataIdFromObject; this.fieldWithArgs = storeKeyNameFromFieldNameAndArgs; this.queryDeduplication = queryDeduplication; if (ssrForceFetchDelay) { setTimeout(function () { return _this.disableNetworkFetches = false; }, ssrForceFetchDelay); } this.reducerConfig = { dataIdFromObject: dataIdFromObject, customResolvers: customResolvers, addTypename: addTypename, fragmentMatcher: this.fragmentMatcher.match, }; this.watchQuery = this.watchQuery.bind(this); this.query = this.query.bind(this); this.mutate = this.mutate.bind(this); this.setStore = this.setStore.bind(this); this.resetStore = this.resetStore.bind(this); var defaultConnectToDevTools = !isProduction() && typeof window !== 'undefined' && (!window.__APOLLO_CLIENT__); if (typeof connectToDevTools === 'undefined' ? defaultConnectToDevTools : connectToDevTools) { window.__APOLLO_CLIENT__ = this; } if (!hasSuggestedDevtools && !isProduction()) { hasSuggestedDevtools = true; if (typeof window !== 'undefined' && window.document && window.top === window.self) { if (typeof window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') { if (navigator.userAgent.indexOf('Chrome') > -1) { console.debug('Download the Apollo DevTools ' + 'for a better development experience: ' + 'https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm'); } } } } this.version = version; }
n/a
__actionHookForDevTools = function (cb) { this.devToolsHookCb = cb; }
n/a
getInitialState = function () { this.initStore(); return this.queryManager.getInitialState(); }
...
ApolloClient.prototype.resetStore = function () {
if (this.queryManager) {
this.queryManager.resetStore();
}
};
ApolloClient.prototype.getInitialState = function () {
this.initStore();
return this.queryManager.getInitialState();
};
ApolloClient.prototype.setStore = function (store) {
var reduxRootSelector;
if (this.reduxRootSelector) {
reduxRootSelector = this.reduxRootSelector;
}
else {
...
initProxy = function () { if (!this.proxy) { this.initStore(); this.proxy = new ReduxDataProxy(this.store, this.reduxRootSelector || defaultReduxRootSelector, this.fragmentMatcher, this .reducerConfig); } return this.proxy; }
...
return this.queryManager.mutate(options);
};
ApolloClient.prototype.subscribe = function (options) {
this.initStore();
return this.queryManager.startGraphQLSubscription(options);
};
ApolloClient.prototype.readQuery = function (options) {
return this.initProxy().readQuery(options);
};
ApolloClient.prototype.readFragment = function (options) {
return this.initProxy().readFragment(options);
};
ApolloClient.prototype.writeQuery = function (options) {
return this.initProxy().writeQuery(options);
};
...
initStore = function () { var _this = this; if (this.store) { return; } if (this.reduxRootSelector) { throw new Error('Cannot initialize the store because "reduxRootSelector" is provided. ' + 'reduxRootSelector should only be used when the store is created outside of the client. ' + 'This may lead to unexpected results when querying the store internally. ' + "Please remove that option from ApolloClient constructor."); } this.setStore(createApolloStore({ reduxRootKey: DEFAULT_REDUX_ROOT_KEY, initialState: this.initialState, config: this.reducerConfig, logger: function (store) { return function (next) { return function (action) { var result = next(action); if (_this.devToolsHookCb) { _this.devToolsHookCb({ action: action, state: _this.queryManager.getApolloState(), dataWithOptimisticResults: _this.queryManager.getDataWithOptimisticResults(), }); } return result; }; }; }, })); }
...
}
}
}
}
this.version = version;
}
ApolloClient.prototype.watchQuery = function (options) {
this.initStore();
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
options = __assign({}, options, { fetchPolicy: 'cache-first' });
}
return this.queryManager.watchQuery(options);
};
ApolloClient.prototype.query = function (options) {
this.initStore();
...
mutate = function (options) { this.initStore(); return this.queryManager.mutate(options); }
...
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
options = __assign({}, options, { fetchPolicy: 'cache-first' });
}
return this.queryManager.query(options);
};
ApolloClient.prototype.mutate = function (options) {
this.initStore();
return this.queryManager.mutate(options);
};
ApolloClient.prototype.subscribe = function (options) {
this.initStore();
return this.queryManager.startGraphQLSubscription(options);
};
ApolloClient.prototype.readQuery = function (options) {
return this.initProxy().readQuery(options);
...
query = function (options) { this.initStore(); if (options.fetchPolicy === 'cache-and-network') { throw new Error('cache-and-network fetchPolicy can only be used with watchQuery'); } if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') { options = __assign$13({}, options, { fetchPolicy: 'cache-first' }); } return this.queryManager.query(options); }
...
this.initStore();
if (options.fetchPolicy === 'cache-and-network') {
throw new Error('cache-and-network fetchPolicy can only be used with watchQuery');
}
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
options = __assign({}, options, { fetchPolicy: 'cache-first' });
}
return this.queryManager.query(options);
};
ApolloClient.prototype.mutate = function (options) {
this.initStore();
return this.queryManager.mutate(options);
};
ApolloClient.prototype.subscribe = function (options) {
this.initStore();
...
readFragment = function (options) { return this.initProxy().readFragment(options); }
...
this.initStore();
return this.queryManager.startGraphQLSubscription(options);
};
ApolloClient.prototype.readQuery = function (options) {
return this.initProxy().readQuery(options);
};
ApolloClient.prototype.readFragment = function (options) {
return this.initProxy().readFragment(options);
};
ApolloClient.prototype.writeQuery = function (options) {
return this.initProxy().writeQuery(options);
};
ApolloClient.prototype.writeFragment = function (options) {
return this.initProxy().writeFragment(options);
};
...
readQuery = function (options) { return this.initProxy().readQuery(options); }
...
return this.queryManager.mutate(options);
};
ApolloClient.prototype.subscribe = function (options) {
this.initStore();
return this.queryManager.startGraphQLSubscription(options);
};
ApolloClient.prototype.readQuery = function (options) {
return this.initProxy().readQuery(options);
};
ApolloClient.prototype.readFragment = function (options) {
return this.initProxy().readFragment(options);
};
ApolloClient.prototype.writeQuery = function (options) {
return this.initProxy().writeQuery(options);
};
...
reducer = function () { return createApolloReducer(this.reducerConfig); }
n/a
resetStore = function () { if (this.queryManager) { this.queryManager.resetStore(); } }
...
}
return result;
}; }; },
}));
};
ApolloClient.prototype.resetStore = function () {
if (this.queryManager) {
this.queryManager.resetStore();
}
};
ApolloClient.prototype.getInitialState = function () {
this.initStore();
return this.queryManager.getInitialState();
};
ApolloClient.prototype.setStore = function (store) {
...
setStore = function (store) { var reduxRootSelector; if (this.reduxRootSelector) { reduxRootSelector = this.reduxRootSelector; } else { reduxRootSelector = defaultReduxRootSelector; } if (typeof reduxRootSelector(store.getState()) === 'undefined') { throw new Error('Existing store does not use apolloReducer. Please make sure the store ' + 'is properly configured and "reduxRootSelector" is correctly specified.'); } this.store = store; this.queryManager = new QueryManager({ networkInterface: this.networkInterface, reduxRootSelector: reduxRootSelector, store: store, addTypename: this.addTypename, reducerConfig: this.reducerConfig, queryDeduplication: this.queryDeduplication, fragmentMatcher: this.fragmentMatcher, }); }
...
var hasSuggestedDevtools = false;
var ApolloClient = (function () {
function ApolloClient(options) {
if (options === void 0) { options = {}; }
var _this = this;
this.middleware = function () {
return function (store) {
_this.setStore(store);
return function (next) { return function (action) {
var previousApolloState = _this.queryManager.selectApolloState(store);
var returnValue = next(action);
var newApolloState = _this.queryManager.selectApolloState(store);
if (newApolloState !== previousApolloState) {
_this.queryManager.broadcastNewStore(store.getState());
}
...
subscribe = function (options) { this.initStore(); return this.queryManager.startGraphQLSubscription(options); }
...
subscription.unsubscribe();
}, 0);
},
error: function (error) {
reject(error);
},
};
subscription = that.subscribe(observer);
});
};
ObservableQuery.prototype.currentResult = function () {
var _a = this.queryManager.getCurrentQueryResult(this, true), data = _a.data, partial = _a.partial;
var queryStoreValue = this.queryManager.getApolloState().queries[this.queryId];
if (queryStoreValue && ((queryStoreValue.graphQLErrors && queryStoreValue.graphQLErrors.length > 0) ||
queryStoreValue.networkError)) {
...
watchQuery = function (options) { this.initStore(); if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') { options = __assign$13({}, options, { fetchPolicy: 'cache-first' }); } return this.queryManager.watchQuery(options); }
...
this.version = version;
}
ApolloClient.prototype.watchQuery = function (options) {
this.initStore();
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
options = __assign({}, options, { fetchPolicy: 'cache-first' });
}
return this.queryManager.watchQuery(options);
};
ApolloClient.prototype.query = function (options) {
this.initStore();
if (options.fetchPolicy === 'cache-and-network') {
throw new Error('cache-and-network fetchPolicy can only be used with watchQuery');
}
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
...
writeFragment = function (options) { return this.initProxy().writeFragment(options); }
...
ApolloClient.prototype.readFragment = function (options) {
return this.initProxy().readFragment(options);
};
ApolloClient.prototype.writeQuery = function (options) {
return this.initProxy().writeQuery(options);
};
ApolloClient.prototype.writeFragment = function (options) {
return this.initProxy().writeFragment(options);
};
ApolloClient.prototype.reducer = function () {
return createApolloReducer(this.reducerConfig);
};
ApolloClient.prototype.__actionHookForDevTools = function (cb) {
this.devToolsHookCb = cb;
};
...
writeQuery = function (options) { return this.initProxy().writeQuery(options); }
...
ApolloClient.prototype.readQuery = function (options) {
return this.initProxy().readQuery(options);
};
ApolloClient.prototype.readFragment = function (options) {
return this.initProxy().readFragment(options);
};
ApolloClient.prototype.writeQuery = function (options) {
return this.initProxy().writeQuery(options);
};
ApolloClient.prototype.writeFragment = function (options) {
return this.initProxy().writeFragment(options);
};
ApolloClient.prototype.reducer = function () {
return createApolloReducer(this.reducerConfig);
};
...
function ApolloError(_a) { var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo ; var _this = _super.call(this, errorMessage) || this; _this.graphQLErrors = graphQLErrors || []; _this.networkError = networkError || null; if (!errorMessage) { _this.message = generateErrorMessage(_this); } else { _this.message = errorMessage; } _this.extraInfo = extraInfo; return _this; }
n/a
function ApolloError(_a) { var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo ; var _this = _super.call(this, errorMessage) || this; _this.graphQLErrors = graphQLErrors || []; _this.networkError = networkError || null; if (!errorMessage) { _this.message = generateErrorMessage(_this); } else { _this.message = errorMessage; } _this.extraInfo = extraInfo; return _this; }
n/a
function HTTPBatchedNetworkInterface(uri, batchInterval, fetchOpts) { var _this = _super.call(this, uri, fetchOpts) || this; if (typeof batchInterval !== 'number') { throw new Error("batchInterval must be a number, got " + batchInterval); } _this.batcher = new QueryBatcher({ batchInterval: batchInterval, batchFetchFunction: _this.batchQuery.bind(_this), }); return _this; }
n/a
applyBatchAfterwares = function (_a) { var _this = this; var responses = _a.responses, options = _a.options; return new Promise(function (resolve, reject) { var responseObject = { responses: responses, options: options }; var queue = function (funcs, scope) { var next = function () { if (funcs.length > 0) { var f = funcs.shift(); if (f) { f.applyBatchAfterware.apply(scope, [responseObject, next]); } } else { resolve(responseObject); } }; next(); }; queue(_this._afterwares.slice(), _this); }); }
...
});
return new Promise(function (resolve, reject) {
middlewarePromise.then(function (batchRequestAndOptions) {
return _this.batchedFetchFromRemoteEndpoint(batchRequestAndOptions)
.then(function (result) {
var httpResponse = result;
if (!httpResponse.ok) {
return _this.applyBatchAfterwares({ responses: [httpResponse], options
: batchRequestAndOptions })
.then(function () {
var httpError = new Error("Network request failed with status " + httpResponse.status + " - \
x22;" + httpResponse.statusText + "\"");
httpError.response = httpResponse;
throw httpError;
});
}
return result.json();
...
applyBatchMiddlewares = function (_a) { var _this = this; var requests = _a.requests, options = _a.options; return new Promise(function (resolve, reject) { var queue = function (funcs, scope) { var next = function () { if (funcs.length > 0) { var f = funcs.shift(); if (f) { f.applyBatchMiddleware.apply(scope, [{ requests: requests, options: options }, next]); } } else { resolve({ requests: requests, options: options, }); } }; next(); }; queue(_this._middlewares.slice(), _this); }); }
...
}
HTTPBatchedNetworkInterface.prototype.query = function (request) {
return this.batcher.enqueueRequest(request);
};
HTTPBatchedNetworkInterface.prototype.batchQuery = function (requests) {
var _this = this;
var options = __assign$1({}, this._opts);
var middlewarePromise = this.applyBatchMiddlewares({
requests: requests,
options: options,
});
return new Promise(function (resolve, reject) {
middlewarePromise.then(function (batchRequestAndOptions) {
return _this.batchedFetchFromRemoteEndpoint(batchRequestAndOptions)
.then(function (result) {
...
batchQuery = function (requests) { var _this = this; var options = __assign$1({}, this._opts); var middlewarePromise = this.applyBatchMiddlewares({ requests: requests, options: options, }); return new Promise(function (resolve, reject) { middlewarePromise.then(function (batchRequestAndOptions) { return _this.batchedFetchFromRemoteEndpoint(batchRequestAndOptions) .then(function (result) { var httpResponse = result; if (!httpResponse.ok) { return _this.applyBatchAfterwares({ responses: [httpResponse], options: batchRequestAndOptions }) .then(function () { var httpError = new Error("Network request failed with status " + httpResponse.status + " - \"" + httpResponse .statusText + "\""); httpError.response = httpResponse; throw httpError; }); } return result.json(); }) .then(function (responses) { if (typeof responses.map !== 'function') { throw new Error('BatchingNetworkInterface: server response is not an array'); } _this.applyBatchAfterwares({ responses: responses, options: batchRequestAndOptions.options, }).then(function (responseAndOptions) { resolve(responseAndOptions.responses); }).catch(function (error) { reject(error); }); }); }).catch(function (error) { reject(error); }); }); }
n/a
batchedFetchFromRemoteEndpoint = function (batchRequestAndOptions) { var options = {}; assign(options, batchRequestAndOptions.options); var printedRequests = batchRequestAndOptions.requests.map(function (request) { return printRequest(request); }); return fetch(this._uri, __assign$1({}, this._opts, { body: JSON.stringify(printedRequests), method: 'POST' }, options, { headers : __assign$1({ Accept: '*/*', 'Content-Type': 'application/json' }, options.headers) })); }
...
var options = __assign$1({}, this._opts);
var middlewarePromise = this.applyBatchMiddlewares({
requests: requests,
options: options,
});
return new Promise(function (resolve, reject) {
middlewarePromise.then(function (batchRequestAndOptions) {
return _this.batchedFetchFromRemoteEndpoint(batchRequestAndOptions)
.then(function (result) {
var httpResponse = result;
if (!httpResponse.ok) {
return _this.applyBatchAfterwares({ responses: [httpResponse], options: batchRequestAndOptions })
.then(function () {
var httpError = new Error("Network request failed with status " + httpResponse.status + " - \
x22;" + httpResponse.statusText + "\"");
httpError.response = httpResponse;
...
function HTTPBatchedNetworkInterface(uri, batchInterval, fetchOpts) { var _this = _super.call(this, uri, fetchOpts) || this; if (typeof batchInterval !== 'number') { throw new Error("batchInterval must be a number, got " + batchInterval); } _this.batcher = new QueryBatcher({ batchInterval: batchInterval, batchFetchFunction: _this.batchQuery.bind(_this), }); return _this; }
n/a
query = function (request) { return this.batcher.enqueueRequest(request); }
...
this.initStore();
if (options.fetchPolicy === 'cache-and-network') {
throw new Error('cache-and-network fetchPolicy can only be used with watchQuery');
}
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
options = __assign({}, options, { fetchPolicy: 'cache-first' });
}
return this.queryManager.query(options);
};
ApolloClient.prototype.mutate = function (options) {
this.initStore();
return this.queryManager.mutate(options);
};
ApolloClient.prototype.subscribe = function (options) {
this.initStore();
...
use = function (middlewares) { var _this = this; middlewares.map(function (middleware) { if (typeof middleware.applyBatchMiddleware === 'function') { _this._middlewares.push(middleware); } else { throw new Error('Batch middleware must implement the applyBatchMiddleware function'); } }); return this; }
n/a
useAfter = function (afterwares) { var _this = this; afterwares.map(function (afterware) { if (typeof afterware.applyBatchAfterware === 'function') { _this._afterwares.push(afterware); } else { throw new Error('Batch afterware must implement the applyBatchAfterware function'); } }); return this; }
n/a
function HTTPFetchNetworkInterface() { return _super !== null && _super.apply(this, arguments) || this; }
n/a
applyAfterwares = function (_a) { var _this = this; var response = _a.response, options = _a.options; return new Promise(function (resolve, reject) { var responseObject = { response: response, options: options }; var queue = function (funcs, scope) { var next = function () { if (funcs.length > 0) { var f = funcs.shift(); if (f) { f.applyAfterware.apply(scope, [responseObject, next]); } } else { resolve(responseObject); } }; next(); }; queue(_this._afterwares.slice(), _this); }); }
...
HTTPFetchNetworkInterface.prototype.query = function (request) {
var _this = this;
var options = __assign({}, this._opts);
return this.applyMiddlewares({
request: request,
options: options,
}).then(function (rao) { return _this.fetchFromRemoteEndpoint.call(_this, rao); })
.then(function (response) { return _this.applyAfterwares({
response: response,
options: options,
}); })
.then(function (_a) {
var response = _a.response;
var httpResponse = response;
return httpResponse.json().catch(function () {
...
applyMiddlewares = function (requestAndOptions) { var _this = this; return new Promise(function (resolve, reject) { var request = requestAndOptions.request, options = requestAndOptions.options; var queue = function (funcs, scope) { var next = function () { if (funcs.length > 0) { var f = funcs.shift(); if (f) { f.applyMiddleware.apply(scope, [{ request: request, options: options }, next]); } } else { resolve({ request: request, options: options, }); } }; next(); }; queue(_this._middlewares.slice(), _this); }); }
...
HTTPFetchNetworkInterface.prototype.fetchFromRemoteEndpoint = function (_a) {
var request = _a.request, options = _a.options;
return fetch(this._uri, __assign({}, this._opts, { body: JSON.stringify(printRequest(request)), method: 'POST' },
options, { headers: __assign({ Accept: '*/*', 'Content-Type': 'application/json' }, options.headers
) }));
};
HTTPFetchNetworkInterface.prototype.query = function (request) {
var _this = this;
var options = __assign({}, this._opts);
return this.applyMiddlewares({
request: request,
options: options,
}).then(function (rao) { return _this.fetchFromRemoteEndpoint.call(_this, rao); })
.then(function (response) { return _this.applyAfterwares({
response: response,
options: options,
}); })
...
function HTTPFetchNetworkInterface() { return _super !== null && _super.apply(this, arguments) || this; }
n/a
fetchFromRemoteEndpoint = function (_a) { var request = _a.request, options = _a.options; return fetch(this._uri, __assign({}, this._opts, { body: JSON.stringify(printRequest(request)), method: 'POST' }, options, { headers: __assign({ Accept: '*/*', 'Content-Type': 'application/json' }, options.headers) })); }
n/a
query = function (request) { var _this = this; var options = __assign({}, this._opts); return this.applyMiddlewares({ request: request, options: options, }).then(function (rao) { return _this.fetchFromRemoteEndpoint.call(_this, rao); }) .then(function (response) { return _this.applyAfterwares({ response: response, options: options, }); }) .then(function (_a) { var response = _a.response; var httpResponse = response; return httpResponse.json().catch(function () { var httpError = new Error("Network request failed with status " + response.status + " - \"" + response.statusText + "\""); httpError.response = httpResponse; throw httpError; }); }) .then(function (payload) { if (!payload.hasOwnProperty('data') && !payload.hasOwnProperty('errors')) { throw new Error("Server response was missing for query '" + request.debugName + "'."); } else { return payload; } }); }
...
this.initStore();
if (options.fetchPolicy === 'cache-and-network') {
throw new Error('cache-and-network fetchPolicy can only be used with watchQuery');
}
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
options = __assign({}, options, { fetchPolicy: 'cache-first' });
}
return this.queryManager.query(options);
};
ApolloClient.prototype.mutate = function (options) {
this.initStore();
return this.queryManager.mutate(options);
};
ApolloClient.prototype.subscribe = function (options) {
this.initStore();
...
use = function (middlewares) { var _this = this; middlewares.map(function (middleware) { if (typeof middleware.applyMiddleware === 'function') { _this._middlewares.push(middleware); } else { throw new Error('Middleware must implement the applyMiddleware function'); } }); return this; }
n/a
useAfter = function (afterwares) { var _this = this; afterwares.map(function (afterware) { if (typeof afterware.applyAfterware === 'function') { _this._afterwares.push(afterware); } else { throw new Error('Afterware must implement the applyAfterware function'); } }); return this; }
n/a
function IntrospectionFragmentMatcher(options) { if (options && options.introspectionQueryResultData) { this.possibleTypesMap = this.parseIntrospectionResult(options.introspectionQueryResultData); this.isReady = true; } else { this.isReady = false; } this.match = this.match.bind(this); }
n/a
match = function (idValue, typeCondition, context) { if (!this.isReady) { throw new Error('FragmentMatcher.match() was called before FragmentMatcher.init()'); } var obj = context.store[idValue.id]; if (!obj) { return false; } if (!obj.__typename) { throw new Error("Cannot match fragment because __typename property is missing: " + JSON.stringify(obj)); } if (obj.__typename === typeCondition) { return true; } var implementingTypes = this.possibleTypesMap[typeCondition]; if (implementingTypes && implementingTypes.indexOf(obj.__typename) > -1) { return true; } return false; }
...
else {
this.isReady = false;
}
this.match = this.match.bind(this);
}
IntrospectionFragmentMatcher.prototype.match = function (idValue, typeCondition, context) {
if (!this.isReady) {
throw new Error('FragmentMatcher.match() was called before FragmentMatcher
.init()');
}
var obj = context.store[idValue.id];
if (!obj) {
return false;
}
if (!obj.__typename) {
throw new Error("Cannot match fragment because __typename property is missing: " + JSON.stringify(obj));
...
parseIntrospectionResult = function (introspectionResultData) { var typeMap = {}; introspectionResultData.__schema.types.forEach(function (type) { if (type.kind === 'UNION' || type.kind === 'INTERFACE') { typeMap[type.name] = type.possibleTypes.map(function (implementingType) { return implementingType.name; }); } }); return typeMap; }
...
};
return ObservableQuery;
}(Observable));
var IntrospectionFragmentMatcher = (function () {
function IntrospectionFragmentMatcher(options) {
if (options && options.introspectionQueryResultData) {
this.possibleTypesMap = this.parseIntrospectionResult(options.introspectionQueryResultData
);
this.isReady = true;
}
else {
this.isReady = false;
}
this.match = this.match.bind(this);
}
...
function ObservableQuery(_a) { var scheduler = _a.scheduler, options = _a.options, _b = _a.shouldSubscribe, shouldSubscribe = _b === void 0 ? true : _b; var _this = this; var queryManager = scheduler.queryManager; var queryId = queryManager.generateQueryId(); var subscriberFunction = function (observer) { return _this.onSubscribe(observer); }; _this = _super.call(this, subscriberFunction) || this; _this.isCurrentlyPolling = false; _this.options = options; _this.variables = _this.options.variables || {}; _this.scheduler = scheduler; _this.queryManager = queryManager; _this.queryId = queryId; _this.shouldSubscribe = shouldSubscribe; _this.observers = []; _this.subscriptionHandles = []; return _this; }
n/a
function ObservableQuery(_a) { var scheduler = _a.scheduler, options = _a.options, _b = _a.shouldSubscribe, shouldSubscribe = _b === void 0 ? true : _b; var _this = this; var queryManager = scheduler.queryManager; var queryId = queryManager.generateQueryId(); var subscriberFunction = function (observer) { return _this.onSubscribe(observer); }; _this = _super.call(this, subscriberFunction) || this; _this.isCurrentlyPolling = false; _this.options = options; _this.variables = _this.options.variables || {}; _this.scheduler = scheduler; _this.queryManager = queryManager; _this.queryId = queryId; _this.shouldSubscribe = shouldSubscribe; _this.observers = []; _this.subscriptionHandles = []; return _this; }
n/a
currentResult = function () { var _a = this.queryManager.getCurrentQueryResult(this, true), data = _a.data, partial = _a.partial; var queryStoreValue = this.queryManager.getApolloState().queries[this.queryId]; if (queryStoreValue && ((queryStoreValue.graphQLErrors && queryStoreValue.graphQLErrors.length > 0) || queryStoreValue.networkError)) { var error = new ApolloError({ graphQLErrors: queryStoreValue.graphQLErrors, networkError: queryStoreValue.networkError, }); return { data: {}, loading: false, networkStatus: queryStoreValue.networkStatus, error: error }; } var queryLoading = !queryStoreValue || queryStoreValue.networkStatus === exports.NetworkStatus.loading; var loading = (this.options.fetchPolicy === 'network-only' && queryLoading) || (partial && this.options.fetchPolicy !== 'cache-only'); var networkStatus; if (queryStoreValue) { networkStatus = queryStoreValue.networkStatus; } else { networkStatus = loading ? exports.NetworkStatus.loading : exports.NetworkStatus.ready; } return { data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus, partial: partial, }; }
n/a
fetchMore = function (fetchMoreOptions) { var _this = this; if (!fetchMoreOptions.updateQuery) { throw new Error('updateQuery option is required. This function defines how to update the query data with the new results .'); } return Promise.resolve() .then(function () { var qid = _this.queryManager.generateQueryId(); var combinedOptions = null; if (fetchMoreOptions.query) { combinedOptions = fetchMoreOptions; } else { var variables = __assign$12({}, _this.variables, fetchMoreOptions.variables); combinedOptions = __assign$12({}, _this.options, fetchMoreOptions, { variables: variables }); } combinedOptions = __assign$12({}, combinedOptions, { query: combinedOptions.query, fetchPolicy: 'network-only' }); return _this.queryManager.fetchQuery(qid, combinedOptions, FetchType.normal, _this.queryId); }) .then(function (fetchMoreResult) { var data = fetchMoreResult.data; var reducer = fetchMoreOptions.updateQuery; var mapFn = function (previousResult, _a) { var variables = _a.variables; var queryVariables = variables; return reducer(previousResult, { fetchMoreResult: data, queryVariables: queryVariables, }); }; _this.updateQuery(mapFn); return fetchMoreResult; }); }
n/a
getLastResult = function () { return this.lastResult; }
...
QueryManager.prototype.stopQuery = function (queryId) {
this.removeQuery(queryId);
this.stopQueryInStore(queryId);
};
QueryManager.prototype.getCurrentQueryResult = function (observableQuery, isOptimistic) {
if (isOptimistic === void 0) { isOptimistic = false; }
var _a = this.getQueryParts(observableQuery), variables = _a.variables, document = _a.document;
var lastResult = observableQuery.getLastResult();
var queryOptions = observableQuery.options;
var readOptions = {
store: isOptimistic ? this.getDataWithOptimisticResults() : this.getApolloState().data,
query: document,
variables: variables,
config: this.reducerConfig,
previousResult: lastResult ? lastResult.data : undefined,
...
onSubscribe = function (observer) { var _this = this; this.observers.push(observer); if (observer.next && this.lastResult) { observer.next(this.lastResult); } if (observer.error && this.lastError) { observer.error(this.lastError); } if (this.observers.length === 1) { this.setUpQuery(); } var retQuerySubscription = { unsubscribe: function () { if (!_this.observers.some(function (el) { return el === observer; })) { return; } _this.observers = _this.observers.filter(function (obs) { return obs !== observer; }); if (_this.observers.length === 0) { _this.tearDownQuery(); } }, }; return retQuerySubscription; }
...
__extends$2(ObservableQuery, _super);
function ObservableQuery(_a) {
var scheduler = _a.scheduler, options = _a.options, _b = _a.shouldSubscribe, shouldSubscribe = _b === void 0 ? true : _b;
var _this = this;
var queryManager = scheduler.queryManager;
var queryId = queryManager.generateQueryId();
var subscriberFunction = function (observer) {
return _this.onSubscribe(observer);
};
_this = _super.call(this, subscriberFunction) || this;
_this.isCurrentlyPolling = false;
_this.options = options;
_this.variables = _this.options.variables || {};
_this.scheduler = scheduler;
_this.queryManager = queryManager;
...
refetch = function (variables) { this.variables = __assign$12({}, this.variables, variables); if (this.options.fetchPolicy === 'cache-only') { return Promise.reject(new Error('cache-only fetchPolicy option should not be used together with query refetch.')); } this.options.variables = __assign$12({}, this.options.variables, this.variables); var combinedOptions = __assign$12({}, this.options, { fetchPolicy: 'network-only' }); return this.queryManager.fetchQuery(this.queryId, combinedOptions, FetchType.refetch) .then(function (result) { return maybeDeepFreeze(result); }); }
...
type: 'APOLLO_STORE_RESET',
observableQueryIds: Object.keys(this.observableQueries),
});
Object.keys(this.observableQueries).forEach(function (queryId) {
var storeQuery = _this.reduxRootSelector(_this.store.getState()).queries[queryId];
var fetchPolicy = _this.observableQueries[queryId].observableQuery.options.fetchPolicy;
if (fetchPolicy !== 'cache-only') {
_this.observableQueries[queryId].observableQuery.refetch();
}
});
};
QueryManager.prototype.startQuery = function (queryId, options, listener) {
this.addQueryListener(queryId, listener);
this.fetchQuery(queryId, options)
.catch(function (error) { return undefined; });
...
result = function () { var that = this; return new Promise(function (resolve, reject) { var subscription = null; var observer = { next: function (result) { resolve(result); var selectedObservers = that.observers.filter(function (obs) { return obs !== observer; }); if (selectedObservers.length === 0) { that.queryManager.removeQuery(that.queryId); } setTimeout(function () { subscription.unsubscribe(); }, 0); }, error: function (error) { reject(error); }, }; subscription = that.subscribe(observer); }); }
...
ObservableQuery.prototype.setVariables = function (variables, tryFetch) {
if (tryFetch === void 0) { tryFetch = false; }
var newVariables = __assign$12({}, this.variables, variables);
if (isEqual(newVariables, this.variables) && !tryFetch) {
if (this.observers.length === 0) {
return new Promise(function (resolve) { return resolve(); });
}
return this.result();
}
else {
this.variables = newVariables;
if (this.observers.length === 0) {
return new Promise(function (resolve) { return resolve(); });
}
return this.queryManager.fetchQuery(this.queryId, __assign$12({}, this.options, { variables: this.variables }))
...
setOptions = function (opts) { var oldOptions = this.options; this.options = __assign$12({}, this.options, opts); if (opts.pollInterval) { this.startPolling(opts.pollInterval); } else if (opts.pollInterval === 0) { this.stopPolling(); } var tryFetch = (oldOptions.fetchPolicy !== 'network-only' && opts.fetchPolicy === 'network-only') || (oldOptions.fetchPolicy === 'cache-only' && opts.fetchPolicy !== 'cache-only') || false; return this.setVariables(this.options.variables, tryFetch); }
n/a
setUpQuery = function () { var _this = this; if (this.shouldSubscribe) { this.queryManager.addObservableQuery(this.queryId, this); } if (!!this.options.pollInterval) { if (this.options.fetchPolicy === 'cache-first' || (this.options.fetchPolicy === 'cache-only')) { throw new Error('Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries.'); } this.isCurrentlyPolling = true; this.scheduler.startPollingQuery(this.options, this.queryId); } var observer = { next: function (result) { _this.lastResult = result; _this.observers.forEach(function (obs) { if (obs.next) { obs.next(result); } }); }, error: function (error) { _this.observers.forEach(function (obs) { if (obs.error) { obs.error(error); } else { console.error('Unhandled error', error.message, error.stack); } }); _this.lastError = error; }, }; this.queryManager.startQuery(this.queryId, this.options, this.queryManager.queryListenerForObserver(this.queryId, this.options , observer)); }
...
if (observer.next && this.lastResult) {
observer.next(this.lastResult);
}
if (observer.error && this.lastError) {
observer.error(this.lastError);
}
if (this.observers.length === 1) {
this.setUpQuery();
}
var retQuerySubscription = {
unsubscribe: function () {
if (!_this.observers.some(function (el) { return el === observer; })) {
return;
}
_this.observers = _this.observers.filter(function (obs) { return obs !== observer; });
...
setVariables = function (variables, tryFetch) { if (tryFetch === void 0) { tryFetch = false; } var newVariables = __assign$12({}, this.variables, variables); if (isEqual(newVariables, this.variables) && !tryFetch) { if (this.observers.length === 0) { return new Promise(function (resolve) { return resolve(); }); } return this.result(); } else { this.variables = newVariables; if (this.observers.length === 0) { return new Promise(function (resolve) { return resolve(); }); } return this.queryManager.fetchQuery(this.queryId, __assign$12({}, this.options, { variables: this.variables })) .then(function (result) { return maybeDeepFreeze(result); }); } }
...
}
else if (opts.pollInterval === 0) {
this.stopPolling();
}
var tryFetch = (oldOptions.fetchPolicy !== 'network-only' && opts.fetchPolicy === 'network-only'
;)
|| (oldOptions.fetchPolicy === 'cache-only' && opts.fetchPolicy !== 'cache-only')
|| false;
return this.setVariables(this.options.variables, tryFetch);
};
ObservableQuery.prototype.setVariables = function (variables, tryFetch) {
if (tryFetch === void 0) { tryFetch = false; }
var newVariables = __assign$12({}, this.variables, variables);
if (isEqual(newVariables, this.variables) && !tryFetch) {
if (this.observers.length === 0) {
return new Promise(function (resolve) { return resolve(); });
...
startPolling = function (pollInterval) { if (this.options.fetchPolicy === 'cache-first' || (this.options.fetchPolicy === 'cache-only')) { throw new Error('Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries.'); } if (this.isCurrentlyPolling) { this.scheduler.stopPollingQuery(this.queryId); this.isCurrentlyPolling = false; } this.options.pollInterval = pollInterval; this.isCurrentlyPolling = true; this.scheduler.startPollingQuery(this.options, this.queryId); }
...
}
};
};
ObservableQuery.prototype.setOptions = function (opts) {
var oldOptions = this.options;
this.options = __assign$12({}, this.options, opts);
if (opts.pollInterval) {
this.startPolling(opts.pollInterval);
}
else if (opts.pollInterval === 0) {
this.stopPolling();
}
var tryFetch = (oldOptions.fetchPolicy !== 'network-only' && opts.fetchPolicy === 'network-only'
;)
|| (oldOptions.fetchPolicy === 'cache-only' && opts.fetchPolicy !== 'cache-only')
|| false;
...
stopPolling = function () { if (this.isCurrentlyPolling) { this.scheduler.stopPollingQuery(this.queryId); this.options.pollInterval = undefined; this.isCurrentlyPolling = false; } }
...
ObservableQuery.prototype.setOptions = function (opts) {
var oldOptions = this.options;
this.options = __assign$12({}, this.options, opts);
if (opts.pollInterval) {
this.startPolling(opts.pollInterval);
}
else if (opts.pollInterval === 0) {
this.stopPolling();
}
var tryFetch = (oldOptions.fetchPolicy !== 'network-only' && opts.fetchPolicy === 'network-only'
;)
|| (oldOptions.fetchPolicy === 'cache-only' && opts.fetchPolicy !== 'cache-only')
|| false;
return this.setVariables(this.options.variables, tryFetch);
};
ObservableQuery.prototype.setVariables = function (variables, tryFetch) {
...
subscribeToMore = function (options) { var _this = this; var observable = this.queryManager.startGraphQLSubscription({ query: options.document, variables: options.variables, }); var subscription = observable.subscribe({ next: function (data) { if (options.updateQuery) { var reducer_1 = options.updateQuery; var mapFn = function (previousResult, _a) { var variables = _a.variables; return reducer_1(previousResult, { subscriptionData: { data: data }, variables: variables, }); }; _this.updateQuery(mapFn); } }, error: function (err) { if (options.onError) { options.onError(err); } else { console.error('Unhandled GraphQL subscription error', err); } }, }); this.subscriptionHandles.push(subscription); return function () { var i = _this.subscriptionHandles.indexOf(subscription); if (i >= 0) { _this.subscriptionHandles.splice(i, 1); subscription.unsubscribe(); } }; }
n/a
tearDownQuery = function () { if (this.isCurrentlyPolling) { this.scheduler.stopPollingQuery(this.queryId); this.isCurrentlyPolling = false; } this.subscriptionHandles.forEach(function (sub) { return sub.unsubscribe(); }); this.subscriptionHandles = []; this.queryManager.stopQuery(this.queryId); if (this.shouldSubscribe) { this.queryManager.removeObservableQuery(this.queryId); } this.observers = []; }
...
var retQuerySubscription = {
unsubscribe: function () {
if (!_this.observers.some(function (el) { return el === observer; })) {
return;
}
_this.observers = _this.observers.filter(function (obs) { return obs !== observer; });
if (_this.observers.length === 0) {
_this.tearDownQuery();
}
},
};
return retQuerySubscription;
};
ObservableQuery.prototype.setUpQuery = function () {
var _this = this;
...
updateQuery = function (mapFn) { var _a = this.queryManager.getQueryWithPreviousResult(this.queryId), previousResult = _a.previousResult, variables = _a.variables , document = _a.document; var newResult = tryFunctionOrLogError(function () { return mapFn(previousResult, { variables: variables }); }); if (newResult) { this.queryManager.store.dispatch({ type: 'APOLLO_UPDATE_QUERY_RESULT', newResult: newResult, variables: variables, document: document, }); } }
...
var variables = _a.variables;
var queryVariables = variables;
return reducer(previousResult, {
fetchMoreResult: data,
queryVariables: queryVariables,
});
};
_this.updateQuery(mapFn);
return fetchMoreResult;
});
};
ObservableQuery.prototype.subscribeToMore = function (options) {
var _this = this;
var observable = this.queryManager.startGraphQLSubscription({
query: options.document,
...