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-alpha.13 to 2.4.0-alpha.14

util/observableToPromise.d.ts

11

ApolloClient.d.ts

@@ -34,3 +34,3 @@ import { ApolloLink, FetchResult, GraphQLRequest } from 'apollo-link';

cache: ApolloCache<TCacheShape>;
queryManager: QueryManager<TCacheShape>;
queryManager: QueryManager<TCacheShape> | undefined;
disableNetworkFetches: boolean;

@@ -62,5 +62,5 @@ version: string;

/**
* This watches the results of the query according to the options specified and
* 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.
* receive updated results through a GraphQL observer when the cache store changes.
* <p /><p />

@@ -76,5 +76,6 @@ * Note that this method is not an implementation of GraphQL subscriptions. Rather,

* <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.
*
*/

@@ -158,3 +159,3 @@ watchQuery<T, TVariables = OperationVariables>(options: WatchQueryOptions<TVariables>): ObservableQuery<T>;

*/
initQueryManager(): void;
initQueryManager(): QueryManager<TCacheShape>;
/**

@@ -161,0 +162,0 @@ * Resets your entire store by clearing out your cache and then re-executing

@@ -100,5 +100,5 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {

/**
* This watches the results of the query according to the options specified and
* 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.
* receive updated results through a GraphQL observer when the cache store changes.
* <p /><p />

@@ -114,8 +114,8 @@ * Note that this method is not an implementation of GraphQL subscriptions. Rather,

* <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) {
this.initQueryManager();
if (this.defaultOptions.watchQuery) {

@@ -130,3 +130,3 @@ options = __assign({}, this.defaultOptions.watchQuery, options);

}
return this.queryManager.watchQuery(options);
return this.initQueryManager().watchQuery(options);
};

@@ -143,3 +143,2 @@ /**

ApolloClient.prototype.query = function (options) {
this.initQueryManager();
if (this.defaultOptions.query) {

@@ -156,3 +155,3 @@ options = __assign({}, this.defaultOptions.query, options);

}
return this.queryManager.query(options);
return this.initQueryManager().query(options);
};

@@ -167,7 +166,6 @@ /**

ApolloClient.prototype.mutate = function (options) {
this.initQueryManager();
if (this.defaultOptions.mutate) {
options = __assign({}, this.defaultOptions.mutate, options);
}
return this.queryManager.mutate(options);
return this.initQueryManager().mutate(options);
};

@@ -179,4 +177,3 @@ /**

ApolloClient.prototype.subscribe = function (options) {
this.initQueryManager();
return this.queryManager.startGraphQLSubscription(options);
return this.initQueryManager().startGraphQLSubscription(options);
};

@@ -213,3 +210,3 @@ /**

var result = this.initProxy().writeQuery(options);
this.queryManager.broadcastQueries();
this.initQueryManager().broadcastQueries();
return result;

@@ -230,3 +227,3 @@ };

var result = this.initProxy().writeFragment(options);
this.queryManager.broadcastQueries();
this.initQueryManager().broadcastQueries();
return result;

@@ -246,3 +243,3 @@ };

var result = this.initProxy().writeData(options);
this.queryManager.broadcastQueries();
this.initQueryManager().broadcastQueries();
return result;

@@ -261,22 +258,27 @@ };

var _this = this;
if (this.queryManager)
return;
this.queryManager = new QueryManager({
link: this.link,
store: this.store,
queryDeduplication: this.queryDeduplication,
ssrMode: this.ssrMode,
onBroadcast: function () {
if (_this.devToolsHookCb) {
_this.devToolsHookCb({
action: {},
state: {
queries: _this.queryManager.queryStore.getStore(),
mutations: _this.queryManager.mutationStore.getStore(),
},
dataWithOptimisticResults: _this.cache.extract(true),
});
}
},
});
if (!this.queryManager) {
this.queryManager = new QueryManager({
link: this.link,
store: this.store,
queryDeduplication: this.queryDeduplication,
ssrMode: this.ssrMode,
onBroadcast: function () {
if (_this.devToolsHookCb) {
_this.devToolsHookCb({
action: {},
state: {
queries: _this.queryManager
? _this.queryManager.queryStore.getStore()
: {},
mutations: _this.queryManager
? _this.queryManager.mutationStore.getStore()
: {},
},
dataWithOptimisticResults: _this.cache.extract(true),
});
}
},
});
}
return this.queryManager;
};

@@ -283,0 +285,0 @@ /**

@@ -7,3 +7,3 @@ import { GraphQLError } from 'graphql';

import { ApolloQueryResult, OperationVariables } from './types';
import { ModifiableWatchQueryOptions, WatchQueryOptions, FetchMoreQueryOptions, SubscribeToMoreOptions, ErrorPolicy } from './watchQueryOptions';
import { ErrorPolicy, FetchMoreQueryOptions, ModifiableWatchQueryOptions, SubscribeToMoreOptions, WatchQueryOptions } from './watchQueryOptions';
import { QueryStoreValue } from '../data/queries';

@@ -62,2 +62,9 @@ export declare type ApolloCurrentResult<T> = {

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>>;

@@ -68,11 +75,19 @@ fetchMore<K extends keyof TVariables>(fetchMoreOptions: FetchMoreQueryOptions<TVariables, K> & FetchMoreOptions<TData, TVariables>): 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: if the variables have not changed, the promise will return the old
* results immediately, and the `next` callback will *not* fire.
* Note: the `next` callback will *not* fire if the variables have not changed
* or if the result is coming from cache.
*
* Note: if the query is not active (there are no subscribers), the promise
* will return null immediately.
* 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,

@@ -86,3 +101,2 @@ * the previous values of those variables will be used.

* @param fetchResults: Option to ignore fetching results when updating variables
*
*/

@@ -89,0 +103,0 @@ setVariables(variables: TVariables, tryFetch?: boolean, fetchResults?: boolean): Promise<ApolloQueryResult<TData>>;

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

};
import { isEqual, tryFunctionOrLogError, maybeDeepFreeze, } from 'apollo-utilities';
import { NetworkStatus, isNetworkRequestInFlight } from './networkStatus';
import { isEqual, maybeDeepFreeze, tryFunctionOrLogError, } from 'apollo-utilities';
import { isNetworkRequestInFlight, NetworkStatus } from './networkStatus';
import { Observable } from '../util/Observable';
import { ApolloError } from '../errors/ApolloError';
import { FetchType } from './types';
import { hasDirectives } from 'apollo-utilities';
export var hasError = function (storeValue, policy) {

@@ -147,2 +148,10 @@ if (policy === void 0) { policy = 'none'; }

}
else {
if (hasDirectives(['defer'], this.options.query)) {
// Make sure that we have loadingState for deferred queries
// If the queryStore has not been initialized, set loading to true and
// wait for the next update.
result.loading = true;
}
}
if (!partial) {

@@ -167,2 +176,9 @@ var stale = false;

};
/**
* 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) {

@@ -232,3 +248,3 @@ var fetchPolicy = this.options.fetchPolicy;

.subscribe({
next: function (data) {
next: function (subscriptionData) {
if (options.updateQuery) {

@@ -238,3 +254,3 @@ _this.updateQuery(function (previous, _a) {

return options.updateQuery(previous, {
subscriptionData: data,
subscriptionData: subscriptionData,
variables: variables,

@@ -284,11 +300,19 @@ });

/**
* 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: if the variables have not changed, the promise will return the old
* results immediately, and the `next` callback will *not* fire.
* Note: the `next` callback will *not* fire if the variables have not changed
* or if the result is coming from cache.
*
* Note: if the query is not active (there are no subscribers), the promise
* will return null immediately.
* 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,

@@ -302,3 +326,2 @@ * the previous values of those variables will be used.

* @param fetchResults: Option to ignore fetching results when updating variables
*
*/

@@ -305,0 +328,0 @@ ObservableQuery.prototype.setVariables = function (variables, tryFetch, fetchResults) {

@@ -61,3 +61,2 @@ import { ApolloLink, FetchResult } from 'apollo-link';

resetStore(): Promise<ApolloQueryResult<any>[]>;
private getObservableQueryPromises;
reFetchObservableQueries(includeStandby?: boolean): Promise<ApolloQueryResult<any>[]>;

@@ -75,2 +74,3 @@ startQuery<T>(queryId: string, options: WatchQueryOptions, listener: QueryListener): string;

broadcastQueries(): void;
private getObservableQueryPromises;
/**

@@ -77,0 +77,0 @@ * Given a loadingState tree, update it with the patch by traversing its path

@@ -286,3 +286,3 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {

var loadingState = void 0;
if (hasDirectives(['defer'], query_1.document)) {
if (query_1.isDeferred) {
loadingState = this.initFieldLevelLoadingStates(query_1.document, {

@@ -421,4 +421,11 @@ data: storeResult,

if (newData) {
// clear out the latest new data, since we're now using it
_this.setQuery(queryId, function () { return ({ newData: null }); });
// 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') {
_this.setQuery(queryId, function () { return ({ newData: null }); });
}
data = newData.result;

@@ -687,20 +694,2 @@ isMissing = !newData.complete || false;

};
QueryManager.prototype.getObservableQueryPromises = function (includeStandby) {
var _this = this;
var observableQueryPromises = [];
this.queries.forEach(function (_a, queryId) {
var observableQuery = _a.observableQuery;
if (!observableQuery)
return;
var fetchPolicy = observableQuery.options.fetchPolicy;
observableQuery.resetLastResults();
if (fetchPolicy !== 'cache-only' &&
(includeStandby || fetchPolicy !== 'standby')) {
observableQueryPromises.push(observableQuery.refetch());
}
_this.setQuery(queryId, function () { return ({ newData: null }); });
_this.invalidate(true, queryId);
});
return observableQueryPromises;
};
QueryManager.prototype.reFetchObservableQueries = function (includeStandby) {

@@ -722,2 +711,3 @@ var observableQueryPromises = this.getObservableQueryPromises(includeStandby);

var query = options.query;
var isCacheEnabled = !(options.fetchPolicy && options.fetchPolicy === 'no-cache');
var cache = this.dataStore.getCache();

@@ -730,11 +720,16 @@ var transformedDoc = cache.transformDocument(query);

observers.push(observer);
// If this is the first observer, actually initiate the network subscription
// If this is the first observer, actually initiate the network
// subscription.
if (observers.length === 1) {
var handler = {
next: function (result) {
_this.dataStore.markSubscriptionResult(result, transformedDoc, variables);
_this.broadcastQueries();
// It's slightly awkward that the data for subscriptions doesn't come from the store.
if (isCacheEnabled) {
_this.dataStore.markSubscriptionResult(result, transformedDoc, variables);
_this.broadcastQueries();
}
// It's slightly awkward that the data for subscriptions doesn't
// come from the store.
observers.forEach(function (obs) {
// XXX I'd prefer a different way to handle errors for subscriptions
// XXX I'd prefer a different way to handle errors for
// subscriptions.
if (obs.next)

@@ -786,5 +781,8 @@ obs.next(result);

else {
try {
// the query is brand new, so we read from the store to see if anything is there
var data = this.dataStore.getCache().read({
if (isDeferred) {
// For deferred queries, we actually want to use partial data
// since certain fields might still be streaming in.
// Setting returnPartialData to true so that
// an error does not get thrown if fields are missing.
var diffResult = this.dataStore.getCache().diff({
query: query,

@@ -794,12 +792,23 @@ variables: variables,

optimistic: optimistic,
// Setting returnPartialData to true for deferred queries, so that
// an error does not get thrown if fields are missing.
// Returning {data: {}} will give us problems as it clobbers the
// data that we have already received.
returnPartialData: isDeferred,
returnPartialData: true,
});
return maybeDeepFreeze({ data: data, partial: false });
return maybeDeepFreeze({
data: diffResult.result,
partial: !diffResult.complete,
});
}
catch (e) {
return maybeDeepFreeze({ data: {}, partial: true });
else {
try {
// the query is brand new, so we read from the store to see if anything is there
var data = this.dataStore.getCache().read({
query: query,
variables: variables,
previousResult: lastResult ? lastResult.data : undefined,
optimistic: optimistic,
});
return maybeDeepFreeze({ data: data, partial: false });
}
catch (e) {
return maybeDeepFreeze({ data: {}, partial: true });
}
}

@@ -839,2 +848,11 @@ }

.forEach(function (listener) {
if (info.newData) {
// Make sure that loadingState is updated for deferred queries
var queryStoreValue = _this.queryStore.get(id);
if (queryStoreValue && queryStoreValue.isDeferred) {
_this.queryStore.updateLoadingState(id, _this.initFieldLevelLoadingStates(queryStoreValue.document, {
data: info.newData.result,
}));
}
}
listener(_this.queryStore.get(id), info.newData);

@@ -844,2 +862,20 @@ });

};
QueryManager.prototype.getObservableQueryPromises = function (includeStandby) {
var _this = this;
var observableQueryPromises = [];
this.queries.forEach(function (_a, queryId) {
var observableQuery = _a.observableQuery;
if (!observableQuery)
return;
var fetchPolicy = observableQuery.options.fetchPolicy;
observableQuery.resetLastResults();
if (fetchPolicy !== 'cache-only' &&
(includeStandby || fetchPolicy !== 'standby')) {
observableQueryPromises.push(observableQuery.refetch());
}
_this.setQuery(queryId, function () { return ({ newData: null }); });
_this.invalidate(true, queryId);
});
return observableQueryPromises;
};
/**

@@ -923,4 +959,2 @@ * Given a loadingState tree, update it with the patch by traversing its path

if (isDeferred && isPatch(result)) {
// TODO: Remove console.info when out of alpha
console.info("Patch received for path " + JSON.stringify(result.path));
// Update loadingState for every patch received, by traversing its path

@@ -974,2 +1008,7 @@ curLoadingState = _this.updateLoadingState(curLoadingState, result);

complete: function () {
if (isDeferred) {
_this.queryStore.markQueryComplete(queryId);
_this.invalidate(true, queryId, fetchMoreForQueryId);
_this.broadcastQueries();
}
_this.removeFetchQueryPromise(requestId);

@@ -976,0 +1015,0 @@ _this.setQuery(queryId, function (_a) {

@@ -110,2 +110,6 @@ import { DocumentNode, ExecutionResult } from 'graphql';

variables?: TVariables;
/**
* Specifies the {@link FetchPolicy} to be used for this subscription.
*/
fetchPolicy?: FetchPolicy;
}

@@ -165,2 +169,8 @@ export declare type RefetchQueryDescription = Array<string | PureQueryOptions>;

* 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.
*/

@@ -167,0 +177,0 @@ update?: MutationUpdaterFn<T>;

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

document: DocumentNode;
isDeferred: boolean;
variables: Object;

@@ -32,2 +33,4 @@ previousVariables?: Object | null;

}): void;
markQueryComplete(queryId: string): void;
updateLoadingState(queryId: string, loadingState: Record<string, any>): void;
markQueryResult(queryId: string, result: ExecutionResult | ExecutionPatchResult, fetchMoreForQueryId: string | undefined, isDeferred: boolean, loadingState?: Record<string, any>): void;

@@ -34,0 +37,0 @@ markQueryError(queryId: string, error: Error, fetchMoreForQueryId: string | undefined): void;

@@ -13,2 +13,3 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {

import { isPatch } from '../core/types';
import { hasDirectives } from 'apollo-utilities';
var QueryStore = /** @class */ (function () {

@@ -70,2 +71,5 @@ function QueryStore() {

document: query.document,
isDeferred: query.document.definitions
? hasDirectives(['defer'], query.document)
: false,
variables: query.variables,

@@ -91,2 +95,13 @@ previousVariables: previousVariables,

};
QueryStore.prototype.markQueryComplete = function (queryId) {
if (!this.store[queryId])
return;
this.store[queryId].networkStatus = NetworkStatus.ready;
};
QueryStore.prototype.updateLoadingState = function (queryId, loadingState) {
if (!this.store[queryId])
return;
this.store[queryId].loadingState = loadingState;
this.store[queryId].compactedLoadingState = this.compactLoadingStateTree(loadingState);
};
QueryStore.prototype.markQueryResult = function (queryId, result, fetchMoreForQueryId, isDeferred, loadingState) {

@@ -93,0 +108,0 @@ if (!this.store[queryId])

{
"name": "apollo-client",
"version": "2.4.0-alpha.13",
"version": "2.4.0-alpha.14",
"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.13-alpha.13",
"apollo-cache": "1.1.13-alpha.14",
"apollo-link": "^1.0.0",
"apollo-link-dedup": "alpha",
"apollo-utilities": "1.0.17-alpha.13",
"apollo-utilities": "1.0.17-alpha.14",
"symbol-observable": "^1.0.2",

@@ -37,5 +37,6 @@ "zen-observable": "^0.8.0"

"peerDependencies": {
"graphql": "^0.11.0 || ^14.0.0"
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"
},
"devDependencies": {
"@octokit/rest": "^15.9.5",
"@types/benchmark": "1.0.31",

@@ -45,5 +46,5 @@ "@types/graphql": "0.12.7",

"@types/jest": "22.2.3",
"@types/lodash": "4.14.112",
"@types/node": "10.5.2",
"apollo-cache-inmemory": "1.2.6-alpha.13",
"@types/lodash": "4.14.116",
"@types/node": "10.5.6",
"apollo-cache-inmemory": "1.2.6-alpha.14",
"benchmark": "2.1.4",

@@ -53,4 +54,3 @@ "browserify": "15.2.0",

"danger": "1.1.0",
"flow-bin": "0.77.0",
"github": "12.1.0",
"flow-bin": "0.78.0",
"graphql": "14.0.0-rc.2",

@@ -62,3 +62,3 @@ "graphql-tag": "2.9.2",

"lodash": "4.17.10",
"rollup": "0.63.4",
"rollup": "0.63.5",
"rxjs": "6.2.2",

@@ -68,3 +68,3 @@ "ts-jest": "20.0.14",

"typescript": "2.9.2",
"uglify-js": "3.4.5",
"uglify-js": "3.4.6",
"webpack": "3.12.0",

@@ -71,0 +71,0 @@ "webpack-bundle-analyzer": "2.13.1"

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

export declare const version = "2.4.0-alpha.13";
export declare const version = "2.4.0-alpha.14";

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

exports.version = "2.4.0-alpha.13"
exports.version = "2.4.0-alpha.14"

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

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