New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apollo-client

Package Overview
Dependencies
Maintainers
8
Versions
309
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-client - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1

ApolloClient.d.ts.map

161

ApolloClient.d.ts

@@ -24,8 +24,2 @@ import { ApolloLink, FetchResult, GraphQLRequest } from 'apollo-link';

};
/**
* This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries
* and mutations) to a GraphQL spec-compliant server over a {@link NetworkInterface} instance,
* receive results from the server and cache the results in a store. It also delivers updates
* to GraphQL queries through {@link Observable} instances.
*/
export default class ApolloClient<TCacheShape> implements DataProxy {

@@ -44,175 +38,22 @@ link: ApolloLink;

private resetStoreCallbacks;
/**
* Constructs an instance of {@link ApolloClient}.
*
* @param link The {@link ApolloLink} over which GraphQL documents will be resolved into a response.
*
* @param cache The initial cache to use in the data store.
*
* @param ssrMode Determines whether this is being run in Server Side Rendering (SSR) mode.
*
* @param ssrForceFetchDelay Determines the time interval before we force fetch queries for a
* server side render.
*
* @param queryDeduplication If set to false, a query will still be sent to the server even if a query
* with identical parameters (query, variables, operationName) is already in flight.
*
*/
constructor(options: ApolloClientOptions<TCacheShape>);
/**
* This watches the cache store of the query according to the options specified and
* returns an {@link ObservableQuery}. We can subscribe to this {@link ObservableQuery} and
* receive updated results through a GraphQL observer when the cache store changes.
* <p /><p />
* Note that this method is not an implementation of GraphQL subscriptions. Rather,
* it uses Apollo's store in order to reactively deliver updates to your query results.
* <p /><p />
* For example, suppose you call watchQuery on a GraphQL query that fetches a person's
* first and last name and this person has a particular object identifer, provided by
* dataIdFromObject. Later, a different query fetches that same person's
* first and last name and the first name has now changed. Then, any observers associated
* with the results of the first query will be updated with a new result object.
* <p /><p />
* Note that if the cache does not change, the subscriber will *not* be notified.
* <p /><p />
* See [here](https://medium.com/apollo-stack/the-concepts-of-graphql-bc68bd819be3#.3mb0cbcmc) for
* a description of store reactivity.
*/
watchQuery<T, TVariables = OperationVariables>(options: WatchQueryOptions<TVariables>): ObservableQuery<T>;
/**
* This resolves a single query according to the options specified and
* returns a {@link Promise} which is either resolved with the resulting data
* or rejected with an error.
*
* @param options An object of type {@link QueryOptions} that allows us to
* describe how this query should be treated e.g. whether it should hit the
* server at all or just resolve from the cache, etc.
*/
query<T, TVariables = OperationVariables>(options: QueryOptions<TVariables>): Promise<ApolloQueryResult<T>>;
/**
* This resolves a single mutation according to the options specified and returns a
* {@link Promise} which is either resolved with the resulting data or rejected with an
* error.
*
* It takes options as an object with the following keys and values:
*/
mutate<T, TVariables = OperationVariables>(options: MutationOptions<T, TVariables>): Promise<FetchResult<T>>;
/**
* This subscribes to a graphql subscription according to the options specified and returns an
* {@link Observable} which either emits received data or an error.
*/
subscribe<T = any, TVariables = OperationVariables>(options: SubscriptionOptions<TVariables>): Observable<T>;
/**
* Tries to read some data from the store in the shape of the provided
* GraphQL query without making a network request. This method will start at
* the root query. To start at a specific id returned by `dataIdFromObject`
* use `readFragment`.
*
* @param optimistic Set to `true` to allow `readQuery` to return
* optimisic results. Is `false` by default.
*/
readQuery<T, TVariables = OperationVariables>(options: DataProxy.Query<TVariables>, optimistic?: boolean): T | null;
/**
* Tries to read some data from the store in the shape of the provided
* GraphQL fragment without making a network request. This method will read a
* GraphQL fragment from any arbitrary id that is currently cached, unlike
* `readQuery` which will only read from the root query.
*
* You must pass in a GraphQL document with a single fragment or a document
* with multiple fragments that represent what you are reading. If you pass
* in a document with multiple fragments then you must also specify a
* `fragmentName`.
*
* @param optimistic Set to `true` to allow `readFragment` to return
* optimisic results. Is `false` by default.
*/
readFragment<T, TVariables = OperationVariables>(options: DataProxy.Fragment<TVariables>, optimistic?: boolean): T | null;
/**
* Writes some data in the shape of the provided GraphQL query directly to
* the store. This method will start at the root query. To start at a a
* specific id returned by `dataIdFromObject` then use `writeFragment`.
*/
writeQuery<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteQueryOptions<TData, TVariables>): void;
/**
* Writes some data in the shape of the provided GraphQL fragment directly to
* the store. This method will write to a GraphQL fragment from any arbitrary
* id that is currently cached, unlike `writeQuery` which will only write
* from the root query.
*
* You must pass in a GraphQL document with a single fragment or a document
* with multiple fragments that represent what you are writing. If you pass
* in a document with multiple fragments then you must also specify a
* `fragmentName`.
*/
writeFragment<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteFragmentOptions<TData, TVariables>): void;
/**
* Sugar for writeQuery & writeFragment
* This method will construct a query from the data object passed in.
* If no id is supplied, writeData will write the data to the root.
* If an id is supplied, writeData will write a fragment to the object
* specified by the id in the store.
*
* Since you aren't passing in a query to check the shape of the data,
* you must pass in an object that conforms to the shape of valid GraphQL data.
*/
writeData<TData = any>(options: DataProxy.WriteDataOptions<TData>): void;
__actionHookForDevTools(cb: () => any): void;
__requestRaw(payload: GraphQLRequest): Observable<ExecutionResult>;
/**
* This initializes the query manager that tracks queries and the cache
*/
initQueryManager(): QueryManager<TCacheShape>;
/**
* Resets your entire store by clearing out your cache and then re-executing
* all of your active queries. This makes it so that you may guarantee that
* there is no data left in your store from a time before you called this
* method.
*
* `resetStore()` is useful when your user just logged out. You’ve removed the
* user session, and you now want to make sure that any references to data you
* might have fetched while the user session was active is gone.
*
* It is important to remember that `resetStore()` *will* refetch any active
* queries. This means that any components that might be mounted will execute
* their queries again using your network interface. If you do not want to
* re-execute any queries then you should make sure to stop watching any
* active queries.
*/
resetStore(): Promise<ApolloQueryResult<any>[] | null>;
/**
* Allows callbacks to be registered that are executed with the store is reset.
* onResetStore returns an unsubscribe function for removing your registered callbacks.
*/
onResetStore(cb: () => Promise<any>): () => void;
/**
* Refetches all of your active queries.
*
* `reFetchObservableQueries()` is useful if you want to bring the client back to proper state in case of a network outage
*
* It is important to remember that `reFetchObservableQueries()` *will* refetch any active
* queries. This means that any components that might be mounted will execute
* their queries again using your network interface. If you do not want to
* re-execute any queries then you should make sure to stop watching any
* active queries.
* Takes optional parameter `includeStandby` which will include queries in standby-mode when refetching.
*/
reFetchObservableQueries(includeStandby?: boolean): Promise<ApolloQueryResult<any>[]> | Promise<null>;
/**
* Exposes the cache's complete state, in a serializable format for later restoration.
*/
extract(optimistic?: boolean): TCacheShape;
/**
* Replaces existing state in the cache (if any) with the values expressed by
* `serializedState`.
*
* Called when hydrating a cache (server side rendering, or offline storage),
* and also (potentially) during hot reloads.
*/
restore(serializedState: TCacheShape): ApolloCache<TCacheShape>;
/**
* Initializes a data proxy for this client instance if one does not already
* exist and returns either a previously initialized proxy instance or the
* newly initialized instance.
*/
private initProxy;
}
//# sourceMappingURL=ApolloClient.d.ts.map

@@ -22,25 +22,3 @@ var __assign = (this && this.__assign) || function () {

});
/**
* This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries
* and mutations) to a GraphQL spec-compliant server over a {@link NetworkInterface} instance,
* receive results from the server and cache the results in a store. It also delivers updates
* to GraphQL queries through {@link Observable} instances.
*/
var ApolloClient = /** @class */ (function () {
/**
* Constructs an instance of {@link ApolloClient}.
*
* @param link The {@link ApolloLink} over which GraphQL documents will be resolved into a response.
*
* @param cache The initial cache to use in the data store.
*
* @param ssrMode Determines whether this is being run in Server Side Rendering (SSR) mode.
*
* @param ssrForceFetchDelay Determines the time interval before we force fetch queries for a
* server side render.
*
* @param queryDeduplication If set to false, a query will still be sent to the server even if a query
* with identical parameters (query, variables, operationName) is already in flight.
*
*/
var ApolloClient = (function () {
function ApolloClient(options) {

@@ -54,3 +32,2 @@ var _this = this;

}
// remove apollo-client supported directives
this.link = supportedDirectives.concat(link);

@@ -71,4 +48,2 @@ this.cache = cache;

this.reFetchObservableQueries = this.reFetchObservableQueries.bind(this);
// Attach the client instance to window to let us be found by chrome devtools, but only in
// development mode
var defaultConnectToDevTools = !isProduction() &&

@@ -82,5 +57,2 @@ typeof window !== 'undefined' &&

}
/**
* Suggest installing the devtools for developers who don't have them
*/
if (!hasSuggestedDevtools && !isProduction()) {

@@ -91,8 +63,5 @@ hasSuggestedDevtools = true;

window.top === window.self) {
// First check if devtools is not installed
if (typeof window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
// Only for Chrome
if (window.navigator &&
window.navigator.userAgent.indexOf('Chrome') > -1) {
// tslint:disable-next-line
console.debug('Download the Apollo DevTools ' +

@@ -107,21 +76,2 @@ 'for a better development experience: ' +

}
/**
* This watches the cache store of the query according to the options specified and
* returns an {@link ObservableQuery}. We can subscribe to this {@link ObservableQuery} and
* receive updated results through a GraphQL observer when the cache store changes.
* <p /><p />
* Note that this method is not an implementation of GraphQL subscriptions. Rather,
* it uses Apollo's store in order to reactively deliver updates to your query results.
* <p /><p />
* For example, suppose you call watchQuery on a GraphQL query that fetches a person's
* first and last name and this person has a particular object identifer, provided by
* dataIdFromObject. Later, a different query fetches that same person's
* first and last name and the first name has now changed. Then, any observers associated
* with the results of the first query will be updated with a new result object.
* <p /><p />
* Note that if the cache does not change, the subscriber will *not* be notified.
* <p /><p />
* See [here](https://medium.com/apollo-stack/the-concepts-of-graphql-bc68bd819be3#.3mb0cbcmc) for
* a description of store reactivity.
*/
ApolloClient.prototype.watchQuery = function (options) {

@@ -131,3 +81,2 @@ if (this.defaultOptions.watchQuery) {

}
// XXX Overwriting options is probably not the best way to do this long term...
if (this.disableNetworkFetches &&

@@ -140,11 +89,2 @@ (options.fetchPolicy === 'network-only' ||

};
/**
* This resolves a single query according to the options specified and
* returns a {@link Promise} which is either resolved with the resulting data
* or rejected with an error.
*
* @param options An object of type {@link QueryOptions} that allows us to
* describe how this query should be treated e.g. whether it should hit the
* server at all or just resolve from the cache, etc.
*/
ApolloClient.prototype.query = function (options) {

@@ -157,4 +97,2 @@ if (this.defaultOptions.query) {

}
// XXX Overwriting options is probably not the best way to do this long
// term...
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {

@@ -165,9 +103,2 @@ options = __assign({}, options, { fetchPolicy: 'cache-first' });

};
/**
* This resolves a single mutation according to the options specified and returns a
* {@link Promise} which is either resolved with the resulting data or rejected with an
* error.
*
* It takes options as an object with the following keys and values:
*/
ApolloClient.prototype.mutate = function (options) {

@@ -179,18 +110,5 @@ if (this.defaultOptions.mutate) {

};
/**
* This subscribes to a graphql subscription according to the options specified and returns an
* {@link Observable} which either emits received data or an error.
*/
ApolloClient.prototype.subscribe = function (options) {
return this.initQueryManager().startGraphQLSubscription(options);
};
/**
* Tries to read some data from the store in the shape of the provided
* GraphQL query without making a network request. This method will start at
* the root query. To start at a specific id returned by `dataIdFromObject`
* use `readFragment`.
*
* @param optimistic Set to `true` to allow `readQuery` to return
* optimisic results. Is `false` by default.
*/
ApolloClient.prototype.readQuery = function (options, optimistic) {

@@ -200,16 +118,2 @@ if (optimistic === void 0) { optimistic = false; }

};
/**
* Tries to read some data from the store in the shape of the provided
* GraphQL fragment without making a network request. This method will read a
* GraphQL fragment from any arbitrary id that is currently cached, unlike
* `readQuery` which will only read from the root query.
*
* You must pass in a GraphQL document with a single fragment or a document
* with multiple fragments that represent what you are reading. If you pass
* in a document with multiple fragments then you must also specify a
* `fragmentName`.
*
* @param optimistic Set to `true` to allow `readFragment` to return
* optimisic results. Is `false` by default.
*/
ApolloClient.prototype.readFragment = function (options, optimistic) {

@@ -219,7 +123,2 @@ if (optimistic === void 0) { optimistic = false; }

};
/**
* Writes some data in the shape of the provided GraphQL query directly to
* the store. This method will start at the root query. To start at a a
* specific id returned by `dataIdFromObject` then use `writeFragment`.
*/
ApolloClient.prototype.writeQuery = function (options) {

@@ -230,13 +129,2 @@ var result = this.initProxy().writeQuery(options);

};
/**
* Writes some data in the shape of the provided GraphQL fragment directly to
* the store. This method will write to a GraphQL fragment from any arbitrary
* id that is currently cached, unlike `writeQuery` which will only write
* from the root query.
*
* You must pass in a GraphQL document with a single fragment or a document
* with multiple fragments that represent what you are writing. If you pass
* in a document with multiple fragments then you must also specify a
* `fragmentName`.
*/
ApolloClient.prototype.writeFragment = function (options) {

@@ -247,12 +135,2 @@ var result = this.initProxy().writeFragment(options);

};
/**
* Sugar for writeQuery & writeFragment
* This method will construct a query from the data object passed in.
* If no id is supplied, writeData will write the data to the root.
* If an id is supplied, writeData will write a fragment to the object
* specified by the id in the store.
*
* Since you aren't passing in a query to check the shape of the data,
* you must pass in an object that conforms to the shape of valid GraphQL data.
*/
ApolloClient.prototype.writeData = function (options) {

@@ -269,5 +147,2 @@ var result = this.initProxy().writeData(options);

};
/**
* This initializes the query manager that tracks queries and the cache
*/
ApolloClient.prototype.initQueryManager = function () {

@@ -301,18 +176,2 @@ var _this = this;

};
/**
* Resets your entire store by clearing out your cache and then re-executing
* all of your active queries. This makes it so that you may guarantee that
* there is no data left in your store from a time before you called this
* method.
*
* `resetStore()` is useful when your user just logged out. You’ve removed the
* user session, and you now want to make sure that any references to data you
* might have fetched while the user session was active is gone.
*
* It is important to remember that `resetStore()` *will* refetch any active
* queries. This means that any components that might be mounted will execute
* their queries again using your network interface. If you do not want to
* re-execute any queries then you should make sure to stop watching any
* active queries.
*/
ApolloClient.prototype.resetStore = function () {

@@ -333,6 +192,2 @@ var _this = this;

};
/**
* Allows callbacks to be registered that are executed with the store is reset.
* onResetStore returns an unsubscribe function for removing your registered callbacks.
*/
ApolloClient.prototype.onResetStore = function (cb) {

@@ -345,14 +200,2 @@ var _this = this;

};
/**
* Refetches all of your active queries.
*
* `reFetchObservableQueries()` is useful if you want to bring the client back to proper state in case of a network outage
*
* It is important to remember that `reFetchObservableQueries()` *will* refetch any active
* queries. This means that any components that might be mounted will execute
* their queries again using your network interface. If you do not want to
* re-execute any queries then you should make sure to stop watching any
* active queries.
* Takes optional parameter `includeStandby` which will include queries in standby-mode when refetching.
*/
ApolloClient.prototype.reFetchObservableQueries = function (includeStandby) {

@@ -363,23 +206,8 @@ return this.queryManager

};
/**
* Exposes the cache's complete state, in a serializable format for later restoration.
*/
ApolloClient.prototype.extract = function (optimistic) {
return this.initProxy().extract(optimistic);
};
/**
* Replaces existing state in the cache (if any) with the values expressed by
* `serializedState`.
*
* Called when hydrating a cache (server side rendering, or offline storage),
* and also (potentially) during hot reloads.
*/
ApolloClient.prototype.restore = function (serializedState) {
return this.initProxy().restore(serializedState);
};
/**
* Initializes a data proxy for this client instance if one does not already
* exist and returns either a previously initialized proxy instance or the
* newly initialized instance.
*/
ApolloClient.prototype.initProxy = function () {

@@ -386,0 +214,0 @@ if (!this.proxy) {

@@ -1,45 +0,11 @@

/**
* The current status of a query’s execution in our system.
*/
export declare enum NetworkStatus {
/**
* The query has never been run before and the query is now currently running. A query will still
* have this network status even if a partial data result was returned from the cache, but a
* query was dispatched anyway.
*/
loading = 1,
/**
* If `setVariables` was called and a query was fired because of that then the network status
* will be `setVariables` until the result of that query comes back.
*/
setVariables = 2,
/**
* Indicates that `fetchMore` was called on this query and that the query created is currently in
* flight.
*/
fetchMore = 3,
/**
* Similar to the `setVariables` network status. It means that `refetch` was called on a query
* and the refetch request is currently in flight.
*/
refetch = 4,
/**
* Indicates that a polling query is currently in flight. So for example if you are polling a
* query every 10 seconds then the network status will switch to `poll` every 10 seconds whenever
* a poll request has been sent but not resolved.
*/
poll = 6,
/**
* No request is in flight for this query, and no errors happened. Everything is OK.
*/
ready = 7,
/**
* No request is in flight for this query, but one or more errors were detected.
*/
error = 8
}
/**
* Returns true if there is currently a network request in flight according to a given network
* status.
*/
export declare function isNetworkRequestInFlight(networkStatus: NetworkStatus): boolean;
//# sourceMappingURL=networkStatus.d.ts.map

@@ -1,46 +0,11 @@

/**
* The current status of a query’s execution in our system.
*/
export var NetworkStatus;
(function (NetworkStatus) {
/**
* The query has never been run before and the query is now currently running. A query will still
* have this network status even if a partial data result was returned from the cache, but a
* query was dispatched anyway.
*/
NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
/**
* If `setVariables` was called and a query was fired because of that then the network status
* will be `setVariables` until the result of that query comes back.
*/
NetworkStatus[NetworkStatus["setVariables"] = 2] = "setVariables";
/**
* Indicates that `fetchMore` was called on this query and that the query created is currently in
* flight.
*/
NetworkStatus[NetworkStatus["fetchMore"] = 3] = "fetchMore";
/**
* Similar to the `setVariables` network status. It means that `refetch` was called on a query
* and the refetch request is currently in flight.
*/
NetworkStatus[NetworkStatus["refetch"] = 4] = "refetch";
/**
* Indicates that a polling query is currently in flight. So for example if you are polling a
* query every 10 seconds then the network status will switch to `poll` every 10 seconds whenever
* a poll request has been sent but not resolved.
*/
NetworkStatus[NetworkStatus["poll"] = 6] = "poll";
/**
* No request is in flight for this query, and no errors happened. Everything is OK.
*/
NetworkStatus[NetworkStatus["ready"] = 7] = "ready";
/**
* No request is in flight for this query, but one or more errors were detected.
*/
NetworkStatus[NetworkStatus["error"] = 8] = "error";
})(NetworkStatus || (NetworkStatus = {}));
/**
* Returns true if there is currently a network request in flight according to a given network
* status.
*/
export function isNetworkRequestInFlight(networkStatus) {

@@ -47,0 +12,0 @@ return networkStatus < 7;

@@ -30,6 +30,2 @@ import { GraphQLError } from 'graphql';

queryId: string;
/**
*
* The current value of the variables for this query. Can change.
*/
variables: TVariables;

@@ -51,8 +47,2 @@ private isCurrentlyPolling;

result(): Promise<ApolloQueryResult<TData>>;
/**
* Return the result of the query from the local cache as well as some fetching status
* `loading` and `networkStatus` allow to know if a request is in flight
* `partial` lets you know if the result from the local cache is complete or partial
* @return {data: Object, error: ApolloError, loading: boolean, networkStatus: number, partial: boolean}
*/
currentResult(): ApolloCurrentResult<TData>;

@@ -62,9 +52,2 @@ getLastResult(): ApolloQueryResult<TData>;

resetLastResults(): void;
/**
* Update the variables of this observable query, and fetch the new results.
* This method should be preferred over `setVariables` in most use cases.
*
* @param variables: The new set of variables. If there are missing variables,
* the previous values of those variables will be used.
*/
refetch(variables?: TVariables): Promise<ApolloQueryResult<TData>>;

@@ -74,29 +57,2 @@ fetchMore<K extends keyof TVariables>(fetchMoreOptions: FetchMoreQueryOptions<TVariables, K> & FetchMoreOptions<TData, TVariables>): Promise<ApolloQueryResult<TData>>;

setOptions(opts: ModifiableWatchQueryOptions): Promise<ApolloQueryResult<TData>>;
/**
* This is for *internal* use only. Most users should instead use `refetch`
* in order to be properly notified of results even when they come from cache.
*
* Update the variables of this observable query, and fetch the new results
* if they've changed. If you want to force new results, use `refetch`.
*
* Note: the `next` callback will *not* fire if the variables have not changed
* or if the result is coming from cache.
*
* Note: the promise will return the old results immediately if the variables
* have not changed.
*
* Note: the promise will return null immediately if the query is not active
* (there are no subscribers).
*
* @private
*
* @param variables: The new set of variables. If there are missing variables,
* the previous values of those variables will be used.
*
* @param tryFetch: Try and fetch new results even if the variables haven't
* changed (we may still just hit the store, but if there's nothing in there
* this will refetch)
*
* @param fetchResults: Option to ignore fetching results when updating variables
*/
setVariables(variables: TVariables, tryFetch?: boolean, fetchResults?: boolean): Promise<ApolloQueryResult<TData>>;

@@ -110,1 +66,2 @@ updateQuery(mapFn: (previousQueryResult: TData, options: UpdateQueryOptions<TVariables>) => TData): void;

}
//# sourceMappingURL=ObservableQuery.d.ts.map

@@ -38,3 +38,3 @@ var __extends = (this && this.__extends) || (function () {

};
var ObservableQuery = /** @class */ (function (_super) {
var ObservableQuery = (function (_super) {
__extends(ObservableQuery, _super);

@@ -46,6 +46,4 @@ function ObservableQuery(_a) {

}) || this;
// active state
_this.isCurrentlyPolling = false;
_this.isTornDown = false;
// query information
_this.options = options;

@@ -55,6 +53,4 @@ _this.variables = options.variables || {};

_this.shouldSubscribe = shouldSubscribe;
// related classes
_this.scheduler = scheduler;
_this.queryManager = scheduler.queryManager;
// interal data stores
_this.observers = [];

@@ -71,12 +67,2 @@ _this.subscriptionHandles = [];

resolve(result);
// Stop the query within the QueryManager if we can before
// this function returns.
//
// We do this in order to prevent observers piling up within
// the QueryManager. Notice that we only fully unsubscribe
// from the subscription in a setTimeout(..., 0) call. This call can
// actually be handled by the browser at a much later time. If queries
// are fired in the meantime, observers that should have been removed
// from the QueryManager will continue to fire, causing an unnecessary
// performance hit.
if (!that.observers.some(function (obs) { return obs !== observer; })) {

@@ -96,8 +82,2 @@ that.queryManager.removeQuery(that.queryId);

};
/**
* Return the result of the query from the local cache as well as some fetching status
* `loading` and `networkStatus` allow to know if a request is in flight
* `partial` lets you know if the result from the local cache is complete or partial
* @return {data: Object, error: ApolloError, loading: boolean, networkStatus: number, partial: boolean}
*/
ObservableQuery.prototype.currentResult = function () {

@@ -127,12 +107,4 @@ if (this.isTornDown) {

queryStoreValue.networkStatus === NetworkStatus.loading;
// We need to be careful about the loading state we show to the user, to try
// and be vaguely in line with what the user would have seen from .subscribe()
// but to still provide useful information synchronously when the query
// will not end up hitting the server.
// See more: https://github.com/apollostack/apollo-client/issues/707
// Basically: is there a query in flight right now (modolo the next tick)?
var loading = (this.options.fetchPolicy === 'network-only' && queryLoading) ||
(partial && this.options.fetchPolicy !== 'cache-only');
// if there is nothing in the query store, it means this query hasn't fired yet or it has been cleaned up. Therefore the
// network status is dependent on queryLoading.
var networkStatus;

@@ -161,4 +133,2 @@ if (queryStoreValue) {

};
// Returns the last result that observer.next was called with. This is not the same as
// currentResult! If you're not sure which you need, then you probably need currentResult.
ObservableQuery.prototype.getLastResult = function () {

@@ -175,12 +145,4 @@ return this.lastResult;

};
/**
* Update the variables of this observable query, and fetch the new results.
* This method should be preferred over `setVariables` in most use cases.
*
* @param variables: The new set of variables. If there are missing variables,
* the previous values of those variables will be used.
*/
ObservableQuery.prototype.refetch = function (variables) {
var fetchPolicy = this.options.fetchPolicy;
// early return if trying to read from cache during refetch
if (fetchPolicy === 'cache-only') {

@@ -190,11 +152,7 @@ return Promise.reject(new Error('cache-only fetchPolicy option should not be used together with query refetch.'));

if (!isEqual(this.variables, variables)) {
// update observable variables
this.variables = Object.assign({}, this.variables, variables);
}
if (!isEqual(this.options.variables, this.variables)) {
// Update the existing options with new variables
this.options.variables = Object.assign({}, this.options.variables, this.variables);
}
// Override fetchPolicy for this call only
// only network-only and no-cache are safe to use
var isNetworkFetchPolicy = fetchPolicy === 'network-only' || fetchPolicy === 'no-cache';

@@ -208,3 +166,2 @@ var combinedOptions = __assign({}, this.options, { fetchPolicy: isNetworkFetchPolicy ? fetchPolicy : 'network-only' });

var _this = this;
// early return if no update Query
if (!fetchMoreOptions.updateQuery) {

@@ -218,7 +175,5 @@ throw new Error('updateQuery option is required. This function defines how to update the query data with the new results.');

if (fetchMoreOptions.query) {
// fetch a new query
combinedOptions = fetchMoreOptions;
}
else {
// fetch the same query with a possibly new variables
combinedOptions = __assign({}, _this.options, fetchMoreOptions, { variables: Object.assign({}, _this.variables, fetchMoreOptions.variables) });

@@ -239,5 +194,2 @@ }

};
// XXX the subscription variables are separate from the query variables.
// if you want to update subscription variables, right now you have to do that separately,
// and you can only do it by stopping the subscription and then subscribing again with new variables.
ObservableQuery.prototype.subscribeToMore = function (options) {

@@ -279,4 +231,2 @@ var _this = this;

};
// Note: if the query is not active (there are no subscribers), the promise
// will return null immediately.
ObservableQuery.prototype.setOptions = function (opts) {

@@ -291,3 +241,2 @@ var oldOptions = this.options;

}
// If fetchPolicy went from cache-only to something else, or from something else to network-only
var tryFetch = (oldOptions.fetchPolicy !== 'network-only' &&

@@ -302,39 +251,8 @@ opts.fetchPolicy === 'network-only') ||

};
/**
* This is for *internal* use only. Most users should instead use `refetch`
* in order to be properly notified of results even when they come from cache.
*
* Update the variables of this observable query, and fetch the new results
* if they've changed. If you want to force new results, use `refetch`.
*
* Note: the `next` callback will *not* fire if the variables have not changed
* or if the result is coming from cache.
*
* Note: the promise will return the old results immediately if the variables
* have not changed.
*
* Note: the promise will return null immediately if the query is not active
* (there are no subscribers).
*
* @private
*
* @param variables: The new set of variables. If there are missing variables,
* the previous values of those variables will be used.
*
* @param tryFetch: Try and fetch new results even if the variables haven't
* changed (we may still just hit the store, but if there's nothing in there
* this will refetch)
*
* @param fetchResults: Option to ignore fetching results when updating variables
*/
ObservableQuery.prototype.setVariables = function (variables, tryFetch, fetchResults) {
if (tryFetch === void 0) { tryFetch = false; }
if (fetchResults === void 0) { fetchResults = true; }
// since setVariables restarts the subscription, we reset the tornDown status
this.isTornDown = false;
var newVariables = variables ? variables : this.variables;
if (isEqual(newVariables, this.variables) && !tryFetch) {
// If we have no observers, then we don't actually want to make a network
// request. As soon as someone observes the query, the request will kick
// off. For now, we just store any changes. (See #1077)
if (this.observers.length === 0 || !fetchResults) {

@@ -348,7 +266,5 @@ return new Promise(function (resolve) { return resolve(); });

this.options.variables = newVariables;
// See comment above
if (this.observers.length === 0) {
return new Promise(function (resolve) { return resolve(); });
}
// Use the same options as before, but with new variables
return this.queryManager

@@ -391,4 +307,2 @@ .fetchQuery(this.queryId, __assign({}, this.options, { variables: this.variables }))

var _this = this;
// Zen Observable has its own error function, in order to log correctly
// we need to declare a custom error if nothing is passed
if (observer._subscription &&

@@ -402,3 +316,2 @@ observer._subscription._observer &&

this.observers.push(observer);
// Deliver initial result
if (observer.next && this.lastResult)

@@ -408,3 +321,2 @@ observer.next(this.lastResult);

observer.error(this.lastError);
// setup the query if it hasn't been done before
if (this.observers.length === 1)

@@ -450,3 +362,2 @@ this.setUpQuery();

}
// stop all active GraphQL subscriptions
this.subscriptionHandles.forEach(function (sub) { return sub.unsubscribe(); });

@@ -453,0 +364,0 @@ this.subscriptionHandles = [];

@@ -82,1 +82,2 @@ import { ApolloLink, FetchResult } from 'apollo-link';

}
//# sourceMappingURL=QueryManager.d.ts.map

@@ -69,3 +69,3 @@ var __assign = (this && this.__assign) || function () {

};
var QueryManager = /** @class */ (function () {
var QueryManager = (function () {
function QueryManager(_a) {

@@ -75,14 +75,5 @@ var link = _a.link, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, store = _a.store, _c = _a.onBroadcast, onBroadcast = _c === void 0 ? function () { return undefined; } : _c, _d = _a.ssrMode, ssrMode = _d === void 0 ? false : _d;

this.queryStore = new QueryStore();
// let's not start at zero to avoid pain with bad checks
this.idCounter = 1;
// XXX merge with ObservableQuery but that needs to be expanded to support mutations and
// subscriptions as well
this.queries = new Map();
// A map going from a requestId to a promise that has not yet been resolved. We use this to keep
// track of queries that are inflight and reject them in case some
// destabalizing action occurs (e.g. reset of the Apollo store).
this.fetchQueryPromises = new Map();
// A map going from the name of a query to an observer issued for it by watchQuery. This is
// generally used to refetches for refetchQueries and to update mutation results through
// updateQueries.
this.queryIdsByName = {};

@@ -111,3 +102,2 @@ this.link = link;

this.setQuery(mutationId, function () { return ({ document: mutation }); });
// Create a map of update queries by id to the query instead of by name.
var generateUpdateQueriesInfo = function () {

@@ -142,3 +132,3 @@ var ret = {};

var completeMutation = function () { return __awaiter(_this, void 0, void 0, function () {
var refetchQueryPromises, _i, refetchQueries_1, refetchQuery, promise;
var refetchQueryPromises, _i, refetchQueries_1, refetchQuery, promise, queryOptions;
return __generator(this, function (_a) {

@@ -158,4 +148,2 @@ switch (_a.label) {

}
// allow for conditional refetches
// XXX do we want to make this the only API one day?
if (typeof refetchQueries === 'function') {

@@ -174,10 +162,14 @@ refetchQueries = refetchQueries(storeResult);

}
refetchQueryPromises.push(this.query({
queryOptions = {
query: refetchQuery.query,
variables: refetchQuery.variables,
fetchPolicy: 'network-only',
}));
};
if (refetchQuery.context) {
queryOptions.context = refetchQuery.context;
}
refetchQueryPromises.push(this.query(queryOptions));
}
if (!awaitRefetchQueries) return [3 /*break*/, 2];
return [4 /*yield*/, Promise.all(refetchQueryPromises)];
if (!awaitRefetchQueries) return [3, 2];
return [4, Promise.all(refetchQueryPromises)];
case 1:

@@ -193,3 +185,3 @@ _a.sent();

}
return [2 /*return*/, storeResult];
return [2, storeResult];
}

@@ -235,7 +227,3 @@ });

};
QueryManager.prototype.fetchQuery = function (queryId, options, fetchType,
// This allows us to track if this is a query spawned by a `fetchMore`
// call for another query. We need this data to compute the `fetchMore`
// network status for the query this is fetching for.
fetchMoreForQueryId) {
QueryManager.prototype.fetchQuery = function (queryId, options, fetchType, fetchMoreForQueryId) {
var _this = this;

@@ -247,5 +235,2 @@ var _a = options.variables, variables = _a === void 0 ? {} : _a, _b = options.metadata, metadata = _b === void 0 ? null : _b, _c = options.fetchPolicy, fetchPolicy = _c === void 0 ? 'cache-first' : _c;

var needToFetch = fetchPolicy === 'network-only' || fetchPolicy === 'no-cache';
// If this is not a force fetch, we want to diff the query against the
// store before we fetch it from the network interface.
// TODO we hit the cache even if the policy is network-first. This could be unnecessary if the network is up.
if (fetchType !== FetchType.refetch &&

@@ -260,3 +245,2 @@ fetchPolicy !== 'network-only' &&

}), complete = _d.complete, result = _d.result;
// If we're in here, only fetch if we have missing fields
needToFetch = !complete || fetchPolicy === 'cache-and-network';

@@ -266,9 +250,6 @@ storeResult = result;

var shouldFetch = needToFetch && fetchPolicy !== 'cache-only' && fetchPolicy !== 'standby';
// we need to check to see if this is an operation that uses the @live directive
if (hasDirectives(['live'], query))
shouldFetch = true;
var requestId = this.generateRequestId();
// set up a watcher to listen to cache updates
var cancel = this.updateQueryWatch(queryId, query, options);
// Initialize query in store with unique requestId
this.setQuery(queryId, function () { return ({

@@ -292,4 +273,2 @@ document: query,

this.broadcastQueries();
// If there is no part of the query we need to fetch from the server (or,
// fetchPolicy is cache-only), we just write the store result as the final result.
var shouldDispatchClientResult = !shouldFetch || fetchPolicy === 'cache-and-network';

@@ -309,4 +288,2 @@ if (shouldDispatchClientResult) {

}).catch(function (error) {
// This is for the benefit of `refetch` promises, which currently don't get their errors
// through the store like watchQuery observers do
if (isApolloError(error)) {

@@ -326,4 +303,2 @@ throw error;

});
// we don't return the promise for cache-and-network since it is already
// returned below from the cache
if (fetchPolicy !== 'cache-and-network') {

@@ -333,13 +308,7 @@ return networkResult;

else {
// however we need to catch the error so it isn't unhandled in case of
// network error
networkResult.catch(function () { });
}
}
// If we have no query to send to the server, we should return the result
// found within the store.
return Promise.resolve({ data: storeResult });
};
// Returns a query listener that will update the given observer based on the
// results (or lack thereof) for a particular query.
QueryManager.prototype.queryListenerForObserver = function (queryId, options, observer) {

@@ -349,6 +318,3 @@ var _this = this;

return function (queryStoreValue, newData) {
// we're going to take a look at the data, so the query is no longer invalidated
_this.invalidate(false, queryId);
// The query store value can be undefined in the event of a store
// reset.
if (!queryStoreValue)

@@ -360,3 +326,2 @@ return;

: options.fetchPolicy;
// don't watch the store for queries on standby
if (fetchPolicy === 'standby')

@@ -374,10 +339,2 @@ return;

fetchPolicy === 'cache-and-network';
// if this caused by a cache broadcast but the query is still in flight
// don't notify the observer
// if (
// isCacheBroadcast &&
// isNetworkRequestInFlight(queryStoreValue.networkStatus)
// ) {
// shouldNotifyIfLoading = false;
// }
var networkStatusChanged = Boolean(lastResult &&

@@ -392,4 +349,2 @@ queryStoreValue.networkStatus !== lastResult.networkStatus);

shouldNotifyIfLoading) {
// If we have either a GraphQL error or a network error, we create
// an error and tell the observer about it.
if (((!errorPolicy || errorPolicy === 'none') &&

@@ -409,3 +364,2 @@ queryStoreValue.graphQLErrors &&

catch (e) {
// Throw error outside this control flow to avoid breaking Apollo's state
setTimeout(function () {

@@ -417,3 +371,2 @@ throw e;

else {
// Throw error outside this control flow to avoid breaking Apollo's state
setTimeout(function () {

@@ -423,3 +376,2 @@ throw apolloError_1;

if (!isProduction()) {
/* tslint:disable-next-line */
console.info('An unhandled error was thrown because no error handler is registered ' +

@@ -436,8 +388,2 @@ 'for the query ' +

if (newData) {
// As long as we're using the cache, clear out the latest
// `newData`, since it will now become the current data. We need
// to keep the `newData` stored with the query when using
// `no-cache` since `getCurrentQueryResult` attemps to pull from
// `newData` first, following by trying the cache (which won't
// find a hit for `no-cache`).
if (fetchPolicy !== 'no-cache') {

@@ -467,5 +413,2 @@ _this.setQuery(queryId, function () { return ({ newData: null }); });

var resultFromStore = void 0;
// If there is some data missing and the user has told us that they
// do not tolerate partial data then we want to return the previous
// result and mark it as stale.
if (isMissing && fetchPolicy !== 'cache-only') {

@@ -487,3 +430,2 @@ resultFromStore = {

}
// if the query wants updates on errors we need to add it to the result
if (errorPolicy === 'all' &&

@@ -499,5 +441,2 @@ queryStoreValue.graphQLErrors &&

lastResult.stale === resultFromStore.stale &&
// We can do a strict equality check here because we include a `previousResult`
// with `readQueryFromStore`. So if the results are the same they will be
// referentially equal.
lastResult.data === resultFromStore.data);

@@ -509,3 +448,2 @@ if (isDifferentResult || previouslyHadError) {

catch (e) {
// Throw error outside this control flow to avoid breaking Apollo's state
setTimeout(function () {

@@ -528,8 +466,2 @@ throw e;

};
// The shouldSubscribe option is a temporary fix that tells us whether watchQuery was called
// directly (i.e. through ApolloClient) or through the query method within QueryManager.
// Currently, the query method uses watchQuery in order to handle non-network errors correctly
// but we don't want to keep track observables issued for the query method since those aren't
// supposed to be refetched in the event of a store reset. Once we unify error handling for
// network errors and non-network errors, the shouldSubscribe option will go away.
QueryManager.prototype.watchQuery = function (options, shouldSubscribe) {

@@ -540,5 +472,3 @@ if (shouldSubscribe === void 0) { shouldSubscribe = true; }

}
// get errors synchronously
var queryDefinition = getQueryDefinition(options.query);
// assign variable default values if supplied
if (queryDefinition.variableDefinitions &&

@@ -634,3 +564,2 @@ queryDefinition.variableDefinitions.length) {

};
// Adds a promise to this.fetchQueryPromises for a given request ID.
QueryManager.prototype.addFetchQueryPromise = function (requestId, resolve, reject) {

@@ -642,14 +571,10 @@ this.fetchQueryPromises.set(requestId.toString(), {

};
// Removes the promise in this.fetchQueryPromises for a particular request ID.
QueryManager.prototype.removeFetchQueryPromise = function (requestId) {
this.fetchQueryPromises.delete(requestId.toString());
};
// Adds an ObservableQuery to this.observableQueries and to this.observableQueriesByName.
QueryManager.prototype.addObservableQuery = function (queryId, observableQuery) {
this.setQuery(queryId, function () { return ({ observableQuery: observableQuery }); });
// Insert the ObservableQuery into this.observableQueriesByName if the query has a name
var queryDef = getQueryDefinition(observableQuery.options.query);
if (queryDef.name && queryDef.name.value) {
var queryName = queryDef.name.value;
// XXX we may we want to warn the user about query name conflicts in the future
this.queryIdsByName[queryName] = this.queryIdsByName[queryName] || [];

@@ -675,8 +600,2 @@ this.queryIdsByName[queryName].push(observableQuery.queryId);

QueryManager.prototype.clearStore = function () {
// Before we have sent the reset action to the store,
// we can no longer rely on the results returned by in-flight
// requests since these may depend on values that previously existed
// in the data portion of the store. So, we cancel the promises and observers
// that we have issued so far and not yet resolved (in the case of
// queries).
this.fetchQueryPromises.forEach(function (_a) {

@@ -694,3 +613,2 @@ var reject = _a.reject;

this.mutationStore.reset();
// begin removing data from the store
var reset = this.dataStore.reset();

@@ -701,8 +619,2 @@ return reset;

var _this = this;
// Similarly, we have to have to refetch each of the queries currently being
// observed. We refetch instead of error'ing on these since the assumption is that
// resetting the store doesn't eliminate the need for the queries currently being
// watched. If there is an existing query in flight when the store is reset,
// the promise for it will be rejected and its results will not be written to the
// store.
return this.clearStore().then(function () {

@@ -720,4 +632,2 @@ return _this.reFetchObservableQueries();

this.fetchQuery(queryId, options)
// `fetchQuery` returns a Promise. In case of a failure it should be caucht or else the
// console will show an `Uncaught (in promise)` message. Ignore the error for now.
.catch(function () { return undefined; });

@@ -737,4 +647,2 @@ return queryId;

observers.push(observer);
// If this is the first observer, actually initiate the network
// subscription.
if (observers.length === 1) {

@@ -748,8 +656,2 @@ var handler = {

observers.forEach(function (obs) {
// If an error exists and a `error` handler has been defined on
// the observer, call that `error` handler and make sure the
// `next` handler is skipped. If no `error` handler exists, we're
// still passing any errors that might occur into the `next`
// handler, to give that handler a chance to deal with the
// error (we're doing this for backwards compatibilty).
if (graphQLResultHasError(result) && obs.error) {

@@ -773,4 +675,2 @@ obs.error(new ApolloError({

};
// TODO: Should subscriptions also accept a `context` option to pass
// through to links?
var operation = _this.buildOperationForLink(transformedDoc, variables);

@@ -781,3 +681,2 @@ sub = execute(_this.link, operation).subscribe(handler);

observers = observers.filter(function (obs) { return obs !== observer; });
// If we removed the last observer, tear down the network subscription
if (observers.length === 0 && sub) {

@@ -795,3 +694,2 @@ sub.unsubscribe();

var subscriptions = this.getQuery(queryId).subscriptions;
// teardown all links
subscriptions.forEach(function (x) { return x.unsubscribe(); });

@@ -805,3 +703,2 @@ this.queries.delete(queryId);

var newData = this.getQuery(observableQuery.queryId).newData;
// XXX test this
if (newData) {

@@ -812,3 +709,2 @@ return maybeDeepFreeze({ data: newData.result, partial: false });

try {
// the query is brand new, so we read from the store to see if anything is there
var data = this.dataStore.getCache().read({

@@ -854,4 +750,2 @@ query: query,

info.listeners
// it's possible for the listener to be undefined if the query is being stopped
// See here for more detail: https://github.com/apollostack/apollo-client/issues/231
.filter(function (x) { return !!x; })

@@ -881,5 +775,2 @@ .forEach(function (listener) {

};
// Takes a request id, query id, a query document and information associated with the query
// and send it to the network interface. Returns
// a promise for the result associated with that request.
QueryManager.prototype.fetchRequest = function (_a) {

@@ -889,6 +780,3 @@ var _this = this;

var variables = options.variables, context = options.context, _b = options.errorPolicy, errorPolicy = _b === void 0 ? 'none' : _b, fetchPolicy = options.fetchPolicy;
var operation = this.buildOperationForLink(document, variables, __assign({}, context, {
// TODO: Should this be included for all entry points via
// buildOperationForLink?
forceFetch: !this.queryDeduplication }));
var operation = this.buildOperationForLink(document, variables, __assign({}, context, { forceFetch: !this.queryDeduplication }));
var resultFromStore;

@@ -900,3 +788,2 @@ var errorsFromStore;

next: function (result) {
// default the lastRequestId to 1
var lastRequestId = _this.getQuery(queryId).lastRequestId;

@@ -932,4 +819,2 @@ if (requestId >= (lastRequestId || 1)) {

if (fetchMoreForQueryId || fetchPolicy === 'no-cache') {
// We don't write fetchMore results to the store because this would overwrite
// the original result in case an @connection directive is used.
resultFromStore = result.data;

@@ -939,3 +824,2 @@ }

try {
// ensure result is combined with data already in store
resultFromStore = _this.dataStore.getCache().read({

@@ -946,5 +830,2 @@ variables: variables,

});
// this will throw an error if there are missing fields in
// the results which can happen with errors from the server.
// tslint:disable-next-line
}

@@ -989,10 +870,5 @@ catch (e) { }

};
// Refetches a query given that query's name. Refetches
// all ObservableQuery instances associated with the query name.
QueryManager.prototype.refetchQueryByName = function (queryName) {
var _this = this;
var refetchedQueries = this.queryIdsByName[queryName];
// early return if the query named does not exist (not yet fetched)
// this used to warn but it may be inteneded behavoir to try and refetch
// un called queries because they could be on different routes
if (refetchedQueries === undefined)

@@ -1033,7 +909,4 @@ return;

operationName: getOperationName(document) || undefined,
context: __assign({}, extraContext, { cache: cache,
// getting an entry's cache key is useful for cacheResolvers & state-link
getCacheKey: function (obj) {
context: __assign({}, extraContext, { cache: cache, getCacheKey: function (obj) {
if (cache.config) {
// on the link, we just want the id string, not the full id value from toIdValue
return cache.config.dataIdFromObject(obj);

@@ -1040,0 +913,0 @@ }

@@ -14,2 +14,3 @@ import { DocumentNode, GraphQLError } from 'graphql';

};
context?: any;
};

@@ -38,1 +39,2 @@ export declare type ApolloQueryResult<T> = {

};
//# sourceMappingURL=types.d.ts.map

@@ -6,77 +6,19 @@ import { DocumentNode, ExecutionResult } from 'graphql';

import { PureQueryOptions, OperationVariables } from './types';
/**
* fetchPolicy determines where the client may return a result from. The options are:
* - cache-first (default): return result from cache. Only fetch from network if cached result is not available.
* - cache-and-network: return result from cache first (if it exists), then return network result once it's available.
* - cache-only: return result from cache if available, fail otherwise.
* - no-cache: return result from network, fail if network call doesn't succeed, don't save to cache
* - network-only: return result from network, fail if network call doesn't succeed, save to cache
* - standby: only for queries that aren't actively watched, but should be available for refetch and updateQueries.
*/
export declare type FetchPolicy = 'cache-first' | 'cache-and-network' | 'network-only' | 'cache-only' | 'no-cache' | 'standby';
/**
* errorPolicy determines the level of events for errors in the execution result. The options are:
* - none (default): any errors from the request are treated like runtime errors and the observable is stopped (XXX this is default to lower breaking changes going from AC 1.0 => 2.0)
* - ignore: errors from the request do not stop the observable, but also don't call `next`
* - all: errors are treated like data and will notify observables
*/
export declare type ErrorPolicy = 'none' | 'ignore' | 'all';
/**
* Common options shared across all query interfaces.
*/
export interface QueryBaseOptions<TVariables = OperationVariables> {
/**
* A map going from variable name to variable value, where the variables are used
* within the GraphQL query.
*/
variables?: TVariables;
/**
* Specifies the {@link FetchPolicy} to be used for this query
*/
fetchPolicy?: FetchPolicy;
/**
* Specifies the {@link ErrorPolicy} to be used for this query
*/
errorPolicy?: ErrorPolicy;
/**
* Whether or not to fetch results
*/
fetchResults?: boolean;
}
/**
* Query options.
*/
export interface QueryOptions<TVariables = OperationVariables> extends QueryBaseOptions<TVariables> {
/**
* A GraphQL document that consists of a single query to be sent down to the
* server.
*/
query: DocumentNode;
/**
* Arbitrary metadata stored in the store with this query. Designed for debugging,
* developer tools, etc.
*/
metadata?: any;
/**
* Context to be passed to link execution chain
*/
context?: any;
}
/**
* We can change these options to an ObservableQuery
*/
export interface ModifiableWatchQueryOptions<TVariables = OperationVariables> extends QueryBaseOptions<TVariables> {
/**
* The time interval (in milliseconds) on which this query should be
* refetched from the server.
*/
pollInterval?: number;
/**
* Whether or not updates to the network status should trigger next on the observer of this query
*/
notifyOnNetworkStatusChange?: boolean;
}
/**
* Watched query options.
*/
export interface WatchQueryOptions<TVariables = OperationVariables> extends QueryOptions<TVariables>, ModifiableWatchQueryOptions<TVariables> {

@@ -101,15 +43,4 @@ }

export interface SubscriptionOptions<TVariables = OperationVariables> {
/**
* A GraphQL document, often created with `gql` from the `graphql-tag`
* package, that contains a single subscription inside of it.
*/
query: DocumentNode;
/**
* An object that maps from the name of a variable as used in the subscription
* GraphQL document to that variable's value.
*/
variables?: TVariables;
/**
* Specifies the {@link FetchPolicy} to be used for this subscription.
*/
fetchPolicy?: FetchPolicy;

@@ -121,67 +52,8 @@ }

}, TVariables = OperationVariables> {
/**
* An object that represents the result of this mutation that will be
* optimistically stored before the server has actually returned a result.
* This is most often used for optimistic UI, where we want to be able to see
* the result of a mutation immediately, and update the UI later if any errors
* appear.
*/
optimisticResponse?: Object | Function;
/**
* A {@link MutationQueryReducersMap}, which is map from query names to
* mutation query reducers. Briefly, this map defines how to incorporate the
* results of the mutation into the results of queries that are currently
* being watched by your application.
*/
updateQueries?: MutationQueryReducersMap<T>;
/**
* A list of query names which will be refetched once this mutation has
* returned. This is often used if you have a set of queries which may be
* affected by a mutation and will have to update. Rather than writing a
* mutation query reducer (i.e. `updateQueries`) for this, you can simply
* refetch the queries that will be affected and achieve a consistent store
* once these queries return.
*/
refetchQueries?: ((result: ExecutionResult) => RefetchQueryDescription) | RefetchQueryDescription;
/**
* By default, `refetchQueries` does not wait for the refetched queries to
* be completed, before resolving the mutation `Promise`. This ensures that
* query refetching does not hold up mutation response handling (query
* refetching is handled asynchronously). Set `awaitRefetchQueries` to
* `true` if you would like to wait for the refetched queries to complete,
* before the mutation can be marked as resolved.
*/
awaitRefetchQueries?: boolean;
/**
* A function which provides a {@link DataProxy} and the result of the
* mutation to allow the user to update the store based on the results of the
* mutation.
*
* This function will be called twice over the lifecycle of a mutation. Once
* at the very beginning if an `optimisticResponse` was provided. The writes
* created from the optimistic data will be rolled back before the second time
* this function is called which is when the mutation has succesfully
* resolved. At that point `update` will be called with the *actual* mutation
* result and those writes will not be rolled back.
*
* The reason a {@link DataProxy} is provided instead of the user calling the
* methods directly on {@link ApolloClient} is that all of the writes are
* batched together at the end of the update, and it allows for writes
* generated by optimistic data to be rolled back.
*
* Note that since this function is intended to be used to update the
* store, it cannot be used with a `no-cache` fetch policy. If you're
* interested in performing some action after a mutation has completed,
* and you don't need to update the store, use the Promise returned from
* `client.mutate` instead.
*/
update?: MutationUpdaterFn<T>;
/**
* Specifies the {@link ErrorPolicy} to be used for this operation
*/
errorPolicy?: ErrorPolicy;
/**
* An object that maps from the name of a variable as used in the mutation
* GraphQL document to that variable's value.
*/
variables?: TVariables;

@@ -192,21 +64,4 @@ }

}, TVariables = OperationVariables> extends MutationBaseOptions<T, TVariables> {
/**
* A GraphQL document, often created with `gql` from the `graphql-tag`
* package, that contains a single mutation inside of it.
*/
mutation: DocumentNode;
/**
* The context to be passed to the link execution chain. This context will
* only be used with the mutation. It will not be used with
* `refetchQueries`. Refetched queries use the context they were
* initialized with (since the intitial context is stored as part of the
* `ObservableQuery` instance). If a specific context is needed when
* refetching queries, make sure it is configured (via the
* [`query` `context` option](/docs/react/api/apollo-client.html#ApolloClient.query))
* when the query is first initialized/run.
*/
context?: any;
/**
* Specifies the {@link FetchPolicy} to be used for this query
*/
fetchPolicy?: FetchPolicy;

@@ -217,1 +72,2 @@ }

}> = (proxy: DataProxy, mutationResult: FetchResult<T>) => void;
//# sourceMappingURL=watchQueryOptions.d.ts.map

@@ -18,1 +18,2 @@ export declare class MutationStore {

}
//# sourceMappingURL=mutations.d.ts.map

@@ -1,2 +0,2 @@

var MutationStore = /** @class */ (function () {
var MutationStore = (function () {
function MutationStore() {

@@ -3,0 +3,0 @@ this.store = {};

@@ -34,1 +34,2 @@ import { DocumentNode, GraphQLError, ExecutionResult } from 'graphql';

}
//# sourceMappingURL=queries.d.ts.map

@@ -15,3 +15,3 @@ var __assign = (this && this.__assign) || function () {

import { NetworkStatus } from '../core/networkStatus';
var QueryStore = /** @class */ (function () {
var QueryStore = (function () {
function QueryStore() {

@@ -31,5 +31,2 @@ this.store = {};

print(previousQuery.document) !== print(query.document)) {
// XXX we're throwing an error here to catch bugs where a query gets overwritten by a new one.
// we should implement a separate action for refetching so that QUERY_INIT may never overwrite
// an existing query (see also: https://github.com/apollostack/apollo-client/issues/732)
throw new Error('Internal Error: may not update existing query string in store');

@@ -41,5 +38,3 @@ }

previousQuery &&
previousQuery.networkStatus !== NetworkStatus.loading
// if the previous query was still loading, we don't want to remember it at all.
) {
previousQuery.networkStatus !== NetworkStatus.loading) {
if (!isEqual(previousQuery.variables, query.variables)) {

@@ -50,3 +45,2 @@ isSetVariables = true;

}
// TODO break this out into a separate function
var networkStatus;

@@ -61,3 +55,2 @@ if (isSetVariables) {

networkStatus = NetworkStatus.refetch;
// TODO: can we determine setVariables here if it's a refetch and the variables have changed?
}

@@ -71,5 +64,2 @@ else {

}
// XXX right now if QUERY_INIT is fired twice, like in a refetch situation, we just overwrite
// the store. We probably want a refetch action instead, because I suspect that if you refetch
// before the initial fetch is done, you'll get an error.
this.store[query.queryId] = {

@@ -84,9 +74,2 @@ document: query.document,

};
// If the action had a `moreForQueryId` property then we need to set the
// network status on that query as well to `fetchMore`.
//
// We have a complement to this if statement in the query result and query
// error action branch, but importantly *not* in the client result branch.
// This is because the implementation of `fetchMore` *always* sets
// `fetchPolicy` to `network-only` so we would never have a client result.
if (typeof query.fetchMoreForQueryId === 'string' &&

@@ -106,5 +89,2 @@ this.store[query.fetchMoreForQueryId]) {

this.store[queryId].networkStatus = NetworkStatus.ready;
// If we have a `fetchMoreForQueryId` then we need to update the network
// status for that query. See the branch for query initialization for more
// explanation about this process.
if (typeof fetchMoreForQueryId === 'string' &&

@@ -120,5 +100,2 @@ this.store[fetchMoreForQueryId]) {

this.store[queryId].networkStatus = NetworkStatus.error;
// If we have a `fetchMoreForQueryId` then we need to update the network
// status for that query. See the branch for query initialization for more
// explanation about this process.
if (typeof fetchMoreForQueryId === 'string') {

@@ -142,3 +119,2 @@ this.markQueryResultClient(fetchMoreForQueryId, true);

var _this = this;
// keep only the queries with query ids that are associated with observables
this.store = Object.keys(this.store)

@@ -149,3 +125,2 @@ .filter(function (queryId) {

.reduce(function (res, key) {
// XXX set loading to true so listeners don't trigger unless they want results with partial data
res[key] = __assign({}, _this.store[key], { networkStatus: NetworkStatus.loading });

@@ -152,0 +127,0 @@ return res;

@@ -49,1 +49,2 @@ import { ExecutionResult, DocumentNode } from 'graphql';

}
//# sourceMappingURL=store.d.ts.map
import { getOperationName, tryFunctionOrLogError, graphQLResultHasError, } from 'apollo-utilities';
var DataStore = /** @class */ (function () {
var DataStore = (function () {
function DataStore(initialCache) {

@@ -25,4 +25,2 @@ this.cache = initialCache;

DataStore.prototype.markSubscriptionResult = function (result, document, variables) {
// the subscription interface should handle not sending us results we no longer subscribe to.
// XXX I don't think we ever send in an object with errors, but we might in the future...
if (!graphQLResultHasError(result)) {

@@ -71,3 +69,2 @@ this.cache.write({

var _this = this;
// Incorporate the result from this mutation into the store
if (!graphQLResultHasError(mutation.result)) {

@@ -86,3 +83,2 @@ var cacheWrites_1 = [];

var _a = mutation.updateQueries[queryId], query = _a.query, updater = _a.updater;
// Read the current query result from the store.
var _b = _this.cache.diff({

@@ -97,3 +93,2 @@ query: query.document,

}
// Run our reducer using the current query result and the mutation result.
var nextQueryResult = tryFunctionOrLogError(function () {

@@ -106,3 +101,2 @@ return updater(currentQueryResult, {

});
// Write the modified result back into the store if we got a new result.
if (nextQueryResult) {

@@ -121,5 +115,2 @@ cacheWrites_1.push({

});
// If the mutation has some writes associated with it then we need to
// apply those writes to the store by running this reducer again with a
// write action.
var update_1 = mutation.update;

@@ -126,0 +117,0 @@ if (update_1) {

@@ -15,1 +15,2 @@ import { GraphQLError } from 'graphql';

}
//# sourceMappingURL=ApolloError.d.ts.map

@@ -17,9 +17,4 @@ var __extends = (this && this.__extends) || (function () {

}
// Sets the error message on this error according to the
// the GraphQL and network errors that are present.
// If the error message has already been set through the
// constructor or otherwise, this function is a nop.
var generateErrorMessage = function (err) {
var message = '';
// If we have GraphQL errors present, add that to the error message.
if (Array.isArray(err.graphQLErrors) && err.graphQLErrors.length !== 0) {

@@ -36,11 +31,7 @@ err.graphQLErrors.forEach(function (graphQLError) {

}
// strip newline from the end of the message
message = message.replace(/\n$/, '');
return message;
};
var ApolloError = /** @class */ (function (_super) {
var ApolloError = (function (_super) {
__extends(ApolloError, _super);
// Constructs an instance of ApolloError given a GraphQLError
// or a network error. Note that one of these has to be a valid
// value or the constructed error will be meaningless.
function ApolloError(_a) {

@@ -58,4 +49,2 @@ var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;

_this.extraInfo = extraInfo;
// We're not using `Object.setPrototypeOf` here as it isn't fully
// supported on Android (see issue #3236).
_this.__proto__ = ApolloError.prototype;

@@ -62,0 +51,0 @@ return _this;

@@ -11,1 +11,2 @@ export { print as printAST } from 'graphql/language/printer';

export default ApolloClient;
//# sourceMappingURL=index.d.ts.map

@@ -7,5 +7,4 @@ export { print as printAST } from 'graphql/language/printer';

import ApolloClient from './ApolloClient';
// export the client as both default and named
export { ApolloClient };
export default ApolloClient;
//# sourceMappingURL=index.js.map
{
"name": "apollo-client",
"version": "2.4.0",
"version": "2.4.1",
"description": "A simple yet functional GraphQL client.",

@@ -28,6 +28,6 @@ "main": "bundle.umd.js",

"@types/zen-observable": "^0.8.0",
"apollo-cache": "^1.1.15",
"apollo-cache": "1.1.16",
"apollo-link": "^1.0.0",
"apollo-link-dedup": "^1.0.0",
"apollo-utilities": "^1.0.19",
"apollo-utilities": "1.0.20",
"symbol-observable": "^1.0.2",

@@ -39,31 +39,2 @@ "zen-observable": "^0.8.0"

},
"devDependencies": {
"@octokit/rest": "15.10.0",
"@types/benchmark": "1.0.31",
"@types/graphql": "0.12.7",
"@types/isomorphic-fetch": "0.0.34",
"@types/jest": "23.3.1",
"@types/lodash": "4.14.116",
"@types/node": "10.5.7",
"apollo-cache-inmemory": "^1.2.8",
"benchmark": "2.1.4",
"browserify": "15.2.0",
"bundlesize": "0.17.0",
"danger": "1.1.0",
"flow-bin": "0.78.0",
"graphql": "14.0.0-rc.2",
"graphql-tag": "2.9.2",
"isomorphic-fetch": "2.2.1",
"jest": "23.5.0",
"lint-staged": "6.1.0",
"lodash": "4.17.10",
"rollup": "0.64.1",
"rxjs": "6.2.2",
"ts-jest": "23.1.3",
"tslint": "5.11.0",
"typescript": "3.0.1",
"uglify-js": "3.4.7",
"webpack": "3.12.0",
"webpack-bundle-analyzer": "2.13.1"
},
"optionalDependencies": {

@@ -70,0 +41,0 @@ "@types/async": "2.0.49"

@@ -101,5 +101,4 @@ # [Apollo Client](https://www.apollographql.com/client/) [![npm version](https://badge.fury.io/js/apollo-client.svg)](https://badge.fury.io/js/apollo-client) [![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](http://www.apollostack.com/#slack) [![Open Source Helpers](https://www.codetriage.com/apollographql/apollo-client/badges/users.svg)](https://www.codetriage.com/apollographql/apollo-client)

[![Build status](https://travis-ci.org/apollographql/apollo-client.svg?branch=master)](https://travis-ci.org/apollographql/apollo-client)
[![Build status](https://ci.appveyor.com/api/projects/status/ajdf70delshw2ire/branch/master?svg=true)](https://ci.appveyor.com/project/stubailo/apollo-client/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/apollographql/apollo-client/badge.svg?branch=master)](https://coveralls.io/github/apollographql/apollo-client?branch=master)
[![CircleCI](https://circleci.com/gh/apollographql/apollo-client.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-client)
[![codecov](https://codecov.io/gh/apollographql/apollo-client/branch/master/graph/badge.svg)](https://codecov.io/gh/apollographql/apollo-client)

@@ -111,5 +110,3 @@ [Read the Apollo Contributor Guidelines.](CONTRIBUTING.md)

```
# nvm use node
npm install
npm run build
npm test

@@ -116,0 +113,0 @@ ```

@@ -30,1 +30,2 @@ import { QueryManager } from '../core/QueryManager';

}
//# sourceMappingURL=scheduler.d.ts.map

@@ -1,7 +0,1 @@

// The QueryScheduler is supposed to be a mechanism that schedules polling queries such that
// they are clustered into the time slots of the QueryBatcher and are batched together. It
// also makes sure that for a given polling query, if one instance of the query is inflight,
// another instance will not be fired until the query returns or times out. We do this because
// another query fires while one is already in flight, the data will stay in the "loading" state
// even after the first query has returned.
var __assign = (this && this.__assign) || function () {

@@ -21,14 +15,8 @@ __assign = Object.assign || function(t) {

import { NetworkStatus } from '../core/networkStatus';
var QueryScheduler = /** @class */ (function () {
var QueryScheduler = (function () {
function QueryScheduler(_a) {
var queryManager = _a.queryManager, ssrMode = _a.ssrMode;
// Map going from queryIds to query options that are in flight.
this.inFlightQueries = {};
// Map going from query ids to the query options associated with those queries. Contains all of
// the queries, both in flight and not in flight.
this.registeredQueries = {};
// Map going from polling interval with to the query ids that fire on that interval.
// These query ids are associated with a set of options in the this.registeredQueries.
this.intervalQueries = {};
// Map going from polling interval widths to polling timers.
this.pollingTimers = {};

@@ -62,3 +50,2 @@ this.ssrMode = false;

}
// Do not poll in SSR mode
if (this.ssrMode)

@@ -74,22 +61,7 @@ return queryId;

QueryScheduler.prototype.stopPollingQuery = function (queryId) {
// Remove the query options from one of the registered queries.
// The polling function will then take care of not firing it anymore.
delete this.registeredQueries[queryId];
};
// Fires the all of the queries on a particular interval. Called on a setInterval.
QueryScheduler.prototype.fetchQueriesOnInterval = function (interval) {
var _this = this;
// XXX this "filter" here is nasty, because it does two things at the same time.
// 1. remove queries that have stopped polling
// 2. call fetchQueries for queries that are polling and not in flight.
// TODO: refactor this to make it cleaner
this.intervalQueries[interval] = this.intervalQueries[interval].filter(function (queryId) {
// If queryOptions can't be found from registeredQueries or if it has a
// different interval, it means that this queryId is no longer registered
// and should be removed from the list of queries firing on this interval.
//
// We don't remove queries from intervalQueries immediately in
// stopPollingQuery so that we can keep the timer consistent when queries
// are removed and replaced, and to avoid quadratic behavior when stopping
// many queries.
if (!(_this.registeredQueries.hasOwnProperty(queryId) &&

@@ -99,4 +71,2 @@ _this.registeredQueries[queryId].pollInterval === interval)) {

}
// Don't fire this instance of the polling query is one of the instances is already in
// flight.
if (_this.checkInFlight(queryId)) {

@@ -108,3 +78,2 @@ return true;

pollingOptions.fetchPolicy = 'network-only';
// don't let unhandled rejections happen
_this.fetchQuery(queryId, pollingOptions, FetchType.poll).catch(function () { });

@@ -118,5 +87,2 @@ return true;

};
// Adds a query on a particular interval to this.intervalQueries and then fires
// that query with all the other queries executing on that interval. Note that the query id
// and query options must have been added to this.registeredQueries before this function is called.
QueryScheduler.prototype.addQueryOnInterval = function (queryId, queryOptions) {

@@ -128,4 +94,2 @@ var _this = this;

}
// If there are other queries on this interval, this query will just fire with those
// and we don't need to create a new timer.
if (this.intervalQueries.hasOwnProperty(interval.toString()) &&

@@ -137,3 +101,2 @@ this.intervalQueries[interval].length > 0) {

this.intervalQueries[interval] = [queryId];
// set up the timer for the function that will handle this interval
this.pollingTimers[interval] = setInterval(function () {

@@ -144,3 +107,2 @@ _this.fetchQueriesOnInterval(interval);

};
// Used only for unit testing.
QueryScheduler.prototype.registerPollingQuery = function (queryOptions) {

@@ -147,0 +109,0 @@ if (!queryOptions.pollInterval) {

@@ -7,1 +7,2 @@ /// <reference types="zen-observable" />

}
//# sourceMappingURL=Observable.d.ts.map

@@ -14,8 +14,5 @@ var __extends = (this && this.__extends) || (function () {

})();
// This simplified polyfill attempts to follow the ECMAScript Observable proposal.
// See https://github.com/zenparsing/es-observable
import { Observable as LinkObservable } from 'apollo-link';
import $$observable from 'symbol-observable';
// rxjs interopt
var Observable = /** @class */ (function (_super) {
var Observable = (function (_super) {
__extends(Observable, _super);

@@ -22,0 +19,0 @@ function Observable() {

import { ObservableQuery } from '../../src/core/ObservableQuery';
import { ApolloQueryResult } from '../../src/core/types';
import { Subscription } from '../../src/util/Observable';
/**
*
* @param observable the observable query to subscribe to
* @param shouldResolve should we resolve after seeing all our callbacks [default: true]
* (use this if you are racing the promise against another)
* @param wait how long to wait after seeing desired callbacks before resolving
* [default: -1 => don't wait]
* @param errorCallbacks an expected set of errors
*/
export declare type Options = {

@@ -25,1 +16,2 @@ observable: ObservableQuery<any>;

export default function (options: Options, ...cbs: ResultCallback[]): Promise<any[]>;
//# sourceMappingURL=observableToPromise.d.ts.map

@@ -1,5 +0,1 @@

// Take an observable and N callbacks, and observe the observable,
// ensuring it is called exactly N times, resolving once it has done so.
// Optionally takes a timeout, which it will wait X ms after the Nth callback
// to ensure it is not called again.
export function observableToPromiseAndSubscription(_a) {

@@ -22,3 +18,2 @@ var observable = _a.observable, _b = _a.shouldResolve, shouldResolve = _b === void 0 ? true : _b, _c = _a.wait, wait = _c === void 0 ? -1 : _c, _d = _a.errorCallbacks, errorCallbacks = _d === void 0 ? [] : _d;

subscription.unsubscribe();
// XXX: we could pass a few other things out here?
resolve(results);

@@ -55,3 +50,2 @@ };

try {
// XXX: should we collect these results too?
errorCb(error);

@@ -58,0 +52,0 @@ }

@@ -6,1 +6,2 @@ /// <reference types="jest" />

export default function subscribeAndCount(done: jest.DoneCallback, observable: ObservableQuery<any>, cb: (handleCount: number, result: ApolloQueryResult<any>) => any): Subscription;
//# sourceMappingURL=subscribeAndCount.d.ts.map

@@ -10,5 +10,2 @@ export default function subscribeAndCount(done, observable, cb) {

catch (e) {
// Wrap in a `setImmediate` so that we will unsubscribe on the next
// tick so that we can make sure that the `subscription` has a chance
// to be defined.
setImmediate(function () {

@@ -15,0 +12,0 @@ subscription.unsubscribe();

@@ -6,1 +6,2 @@ /// <reference types="jest" />

export declare function withError(func: Function, regex: RegExp): any;
//# sourceMappingURL=wrap.d.ts.map

@@ -1,3 +0,1 @@

// I'm not sure why mocha doesn't provide something like this, you can't
// always use promises
export default (function (done, cb) { return function () {

@@ -4,0 +2,0 @@ var args = [];

@@ -1,1 +0,2 @@

export declare const version = "2.4.0";
export declare const version = "2.4.1";
//# sourceMappingURL=version.d.ts.map

@@ -1,1 +0,1 @@

exports.version = "2.4.0"
exports.version = "2.4.1"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc