Socket
Socket
Sign inDemoInstall

@apollo/client

Package Overview
Dependencies
Maintainers
1
Versions
574
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 3.0.0-beta.14 to 3.0.0-beta.15

2

cache/core/cache.d.ts

@@ -10,4 +10,4 @@ import { DocumentNode } from 'graphql';

abstract watch(watch: Cache.WatchOptions): () => void;
abstract evict(dataId: string): boolean;
abstract reset(): Promise<void>;
abstract evict(dataId: string, fieldName?: string): boolean;
abstract restore(serializedState: TSerialized): ApolloCache<TSerialized>;

@@ -14,0 +14,0 @@ abstract extract(optimistic?: boolean): TSerialized;

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

import { OptimisticDependencyFunction } from 'optimism';
import { KeyTrie } from 'optimism';
import { StoreValue } from '../../utilities/graphql/storeUtils';
import { NormalizedCache, NormalizedCacheObject, StoreObject } from './types';
declare type DependType = OptimisticDependencyFunction<string> | null;
export declare abstract class EntityStore implements NormalizedCache {
protected data: NormalizedCacheObject;
readonly depend: DependType;
readonly group: CacheGroup;
abstract addLayer(layerId: string, replay: (layer: EntityStore) => any): EntityStore;

@@ -13,5 +12,5 @@ abstract removeLayer(layerId: string): EntityStore;

get(dataId: string): StoreObject;
getFieldValue(dataId: string, fieldName: string): StoreValue;
getFieldValue(dataId: string, storeFieldName: string): StoreValue;
merge(dataId: string, incoming: StoreObject): void;
delete(dataId: string): void;
delete(dataId: string, fieldName?: string): void;
clear(): void;

@@ -26,6 +25,15 @@ replace(newData: NormalizedCacheObject | null): void;

findChildRefIds(dataId: string): Record<string, true>;
makeCacheKey(...args: any[]): object;
}
declare class CacheGroup {
readonly caching: boolean;
private d;
constructor(caching: boolean);
depend(dataId: string, storeFieldName?: string): void;
dirty(dataId: string, storeFieldName?: string): void;
readonly keyMaker: KeyTrie<object>;
}
export declare namespace EntityStore {
class Root extends EntityStore {
private sharedLayerDepend;
private sharedLayerGroup;
constructor({ resultCaching, seed, }: {

@@ -32,0 +40,0 @@ resultCaching?: boolean;

import { __assign, __extends } from 'tslib';
import { invariant } from 'ts-invariant';
import { isReference } from '../../utilities/graphql/storeUtils.js';
import { canUseWeakMap } from '../../utilities/common/canUse.js';
import { equal } from '@wry/equality';
import { DeepMerger } from '../../utilities/common/mergeDeep.js';
import { dep } from 'optimism';
import { getTypenameFromStoreObject } from './helpers.js';
import { KeyTrie, dep } from 'optimism';
import { fieldNameFromStoreName, getTypenameFromStoreObject } from './helpers.js';
var hasOwn = Object.prototype.hasOwnProperty;
function makeDepKey(dataId, fieldName) {
var parts = [dataId];
if (typeof fieldName === "string") {
parts.push(fieldName);
}
return JSON.stringify(parts);
}
function depend(store, dataId, fieldName) {
if (store.depend) {
store.depend(makeDepKey(dataId, fieldName));
}
}
function dirty(store, dataId, fieldName) {
if (store.depend) {
store.depend.dirty(makeDepKey(dataId));
if (typeof fieldName === "string") {
store.depend.dirty(makeDepKey(dataId, fieldName));
}
}
}
var EntityStore = (function () {
function EntityStore() {
this.data = Object.create(null);
this.depend = null;
this.rootIds = Object.create(null);

@@ -44,9 +24,9 @@ this.refs = Object.create(null);

EntityStore.prototype.get = function (dataId) {
depend(this, dataId);
this.group.depend(dataId);
return this.data[dataId];
};
EntityStore.prototype.getFieldValue = function (dataId, fieldName) {
depend(this, dataId, fieldName);
EntityStore.prototype.getFieldValue = function (dataId, storeFieldName) {
this.group.depend(dataId, storeFieldName);
var storeObject = this.data[dataId];
return storeObject && storeObject[fieldName];
return storeObject && storeObject[storeFieldName];
};

@@ -61,7 +41,7 @@ EntityStore.prototype.merge = function (dataId, incoming) {

delete this.refs[dataId];
if (this.depend) {
dirty(this, dataId);
Object.keys(incoming).forEach(function (fieldName) {
if (!existing || incoming[fieldName] !== existing[fieldName]) {
dirty(_this, dataId, fieldName);
if (this.group.caching) {
this.group.dirty(dataId);
Object.keys(incoming).forEach(function (storeFieldName) {
if (!existing || incoming[storeFieldName] !== existing[storeFieldName]) {
_this.group.dirty(dataId, storeFieldName);
}

@@ -72,12 +52,47 @@ });

};
EntityStore.prototype.delete = function (dataId) {
EntityStore.prototype.delete = function (dataId, fieldName) {
var _this = this;
var storeObject = this.data[dataId];
delete this.data[dataId];
delete this.refs[dataId];
if (this.depend && storeObject) {
dirty(this, dataId);
Object.keys(storeObject).forEach(function (fieldName) {
dirty(_this, dataId, fieldName);
var storeObject = this.get(dataId);
if (storeObject) {
fieldName = fieldName && fieldNameFromStoreName(fieldName);
var storeNamesToDelete_1 = [];
Object.keys(storeObject).forEach(function (storeFieldName) {
if (storeObject[storeFieldName] !== void 0 &&
(!fieldName || fieldName === fieldNameFromStoreName(storeFieldName))) {
storeNamesToDelete_1.push(storeFieldName);
}
});
if (storeNamesToDelete_1.length) {
var canDelete_1 = this instanceof EntityStore.Root;
var remove_1 = function (obj, key) {
if (canDelete_1) {
delete obj[key];
}
else {
obj[key] = void 0;
}
};
delete this.refs[dataId];
var fieldsToDirty_1 = Object.create(null);
if (fieldName) {
var cleaned_1 = this.data[dataId] = __assign({}, storeObject);
storeNamesToDelete_1.forEach(function (storeFieldName) {
remove_1(cleaned_1, storeFieldName);
});
fieldsToDirty_1[fieldName] = true;
}
else {
remove_1(this.data, dataId);
storeNamesToDelete_1.forEach(function (storeFieldName) {
var fieldName = fieldNameFromStoreName(storeFieldName);
fieldsToDirty_1[fieldName] = true;
});
}
if (this.group.caching) {
this.group.dirty(dataId);
Object.keys(fieldsToDirty_1).forEach(function (fieldName) {
_this.group.dirty(dataId, fieldName);
});
}
}
}

@@ -128,6 +143,6 @@ };

if (idsToRemove.length) {
var root = this;
while (root instanceof Layer)
root = root.parent;
idsToRemove.forEach(root.delete, root);
var root_1 = this;
while (root_1 instanceof Layer)
root_1 = root_1.parent;
idsToRemove.forEach(function (id) { return root_1.delete(id); });
}

@@ -154,4 +169,39 @@ return idsToRemove;

};
EntityStore.prototype.makeCacheKey = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return this.group.keyMaker.lookupArray(args);
};
return EntityStore;
}());
var CacheGroup = (function () {
function CacheGroup(caching) {
this.caching = caching;
this.d = null;
this.keyMaker = new KeyTrie(canUseWeakMap);
this.d = caching ? dep() : null;
}
CacheGroup.prototype.depend = function (dataId, storeFieldName) {
if (this.d) {
this.d(makeDepKey(dataId, storeFieldName));
}
};
CacheGroup.prototype.dirty = function (dataId, storeFieldName) {
if (this.d) {
this.d.dirty(typeof storeFieldName === "string"
? makeDepKey(dataId, storeFieldName)
: makeDepKey(dataId));
}
};
return CacheGroup;
}());
function makeDepKey(dataId, storeFieldName) {
var parts = [dataId];
if (typeof storeFieldName === "string") {
parts.push(fieldNameFromStoreName(storeFieldName));
}
return JSON.stringify(parts);
}
(function (EntityStore) {

@@ -163,7 +213,5 @@ var Root = (function (_super) {

var _this = _super.call(this) || this;
_this.sharedLayerDepend = null;
if (resultCaching) {
_this.depend = dep();
_this.sharedLayerDepend = dep();
}
_this.sharedLayerGroup = null;
_this.group = new CacheGroup(resultCaching);
_this.sharedLayerGroup = new CacheGroup(resultCaching);
if (seed)

@@ -174,3 +222,3 @@ _this.replace(seed);

Root.prototype.addLayer = function (layerId, replay) {
return new Layer(layerId, this, replay, this.sharedLayerDepend);
return new Layer(layerId, this, replay, this.sharedLayerGroup);
};

@@ -186,3 +234,3 @@ Root.prototype.removeLayer = function (layerId) {

__extends(Layer, _super);
function Layer(id, parent, replay, depend) {
function Layer(id, parent, replay, group) {
var _this = _super.call(this) || this;

@@ -192,3 +240,3 @@ _this.id = id;

_this.replay = replay;
_this.depend = depend;
_this.group = group;
replay(_this);

@@ -198,3 +246,3 @@ return _this;

Layer.prototype.addLayer = function (layerId, replay) {
return new Layer(layerId, this, replay, this.depend);
return new Layer(layerId, this, replay, this.group);
};

@@ -205,3 +253,3 @@ Layer.prototype.removeLayer = function (layerId) {

if (layerId === this.id) {
if (this.depend) {
if (this.group.caching) {
Object.keys(this.data).forEach(function (dataId) { return _this.delete(dataId); });

@@ -222,23 +270,19 @@ }

}
if (this.depend && this.depend !== this.parent.depend) {
depend(this, dataId);
if (this.group.caching && this.group !== this.parent.group) {
this.group.depend(dataId);
}
return this.parent.get(dataId);
};
Layer.prototype.getFieldValue = function (dataId, fieldName) {
Layer.prototype.getFieldValue = function (dataId, storeFieldName) {
if (hasOwn.call(this.data, dataId)) {
var storeObject = this.data[dataId];
if (storeObject && hasOwn.call(storeObject, fieldName)) {
return _super.prototype.getFieldValue.call(this, dataId, fieldName);
if (storeObject && hasOwn.call(storeObject, storeFieldName)) {
return _super.prototype.getFieldValue.call(this, dataId, storeFieldName);
}
}
if (this.depend && this.depend !== this.parent.depend) {
depend(this, dataId, fieldName);
if (this.group.caching && this.group !== this.parent.group) {
this.group.depend(dataId, storeFieldName);
}
return this.parent.getFieldValue(dataId, fieldName);
return this.parent.getFieldValue(dataId, storeFieldName);
};
Layer.prototype.delete = function (dataId) {
_super.prototype.delete.call(this, dataId);
this.data[dataId] = void 0;
};
Layer.prototype.getRootIdSet = function () {

@@ -276,3 +320,3 @@ var ids = this.parent.getRootIdSet();

function supportsResultCaching(store) {
return !!(store instanceof EntityStore && store.depend);
return !!(store instanceof EntityStore && store.group.caching);
}

@@ -279,0 +323,0 @@ function defaultNormalizedCacheFactory(seed) {

import { NormalizedCache, StoreObject } from './types';
import { Reference } from '../../utilities/graphql/storeUtils';
export declare function getTypenameFromStoreObject(store: NormalizedCache, objectOrReference: StoreObject | Reference): string | undefined;
export declare function fieldNameFromStoreName(storeFieldName: string): string;
//# sourceMappingURL=helpers.d.ts.map

@@ -8,4 +8,9 @@ import { isReference } from '../../utilities/graphql/storeUtils.js';

}
var FieldNamePattern = /^[_A-Za-z0-9]+/;
function fieldNameFromStoreName(storeFieldName) {
var match = storeFieldName.match(FieldNamePattern);
return match && match[0];
}
export { getTypenameFromStoreObject };
export { fieldNameFromStoreName, getTypenameFromStoreObject };
//# sourceMappingURL=helpers.js.map

@@ -5,3 +5,3 @@ import './fixPolyfills';

import { Cache } from '../core/types/Cache';
import { ApolloReducerConfig, NormalizedCacheObject } from './types';
import { ApolloReducerConfig, NormalizedCacheObject, StoreObject } from './types';
import { PossibleTypesMap, TypePolicies } from './policies';

@@ -23,3 +23,2 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig {

private storeWriter;
private cacheKeyRoot;
private silenceBroadcast;

@@ -36,3 +35,4 @@ constructor(config?: InMemoryCacheConfig);

release(rootId: string, optimistic?: boolean): number;
evict(dataId: string): boolean;
identify(object: StoreObject): string | null;
evict(dataId: string, fieldName?: string): boolean;
reset(): Promise<void>;

@@ -39,0 +39,0 @@ removeOptimistic(idToRemove: string): void;

import { __extends, __assign } from 'tslib';
import { addTypenameToDocument } from '../../utilities/graphql/transform.js';
import { canUseWeakMap } from '../../utilities/common/canUse.js';
import { ApolloCache } from '../core/cache.js';
import './fixPolyfills.js';
import { KeyTrie, wrap } from 'optimism';
import { wrap } from 'optimism';
import { EntityStore, supportsResultCaching } from './entityStore.js';

@@ -25,3 +24,2 @@ import { StoreReader } from './readFromStore.js';

_this.typenameDocumentCache = new Map();
_this.cacheKeyRoot = new KeyTrie(canUseWeakMap);
_this.silenceBroadcast = false;

@@ -44,3 +42,2 @@ _this.config = __assign(__assign({}, defaultConfig), config);

addTypename: _this.addTypename,
cacheKeyRoot: _this.cacheKeyRoot,
policies: _this.policies,

@@ -54,8 +51,7 @@ });

makeCacheKey: function (c) {
if (c.previousResult) {
return;
var store = c.optimistic ? cache.optimisticData : cache.data;
if (supportsResultCaching(store)) {
var optimistic = c.optimistic, rootId = c.rootId, variables = c.variables;
return store.makeCacheKey(c.query, JSON.stringify({ optimistic: optimistic, rootId: rootId, variables: variables }));
}
if (supportsResultCaching(cache.data)) {
return cache.cacheKeyRoot.lookup(c.query, JSON.stringify(c.variables));
}
}

@@ -84,3 +80,2 @@ });

rootId: options.rootId,
previousResult: options.previousResult,
config: this.config,

@@ -105,3 +100,2 @@ }) || null;

returnPartialData: options.returnPartialData,
previousResult: options.previousResult,
config: this.config,

@@ -126,5 +120,8 @@ });

};
InMemoryCache.prototype.evict = function (dataId) {
InMemoryCache.prototype.identify = function (object) {
return this.policies.identify(object);
};
InMemoryCache.prototype.evict = function (dataId, fieldName) {
if (this.optimisticData.has(dataId)) {
this.optimisticData.delete(dataId);
this.optimisticData.delete(dataId, fieldName);
this.broadcastWatches();

@@ -191,3 +188,2 @@ return !this.optimisticData.has(dataId);

variables: c.variables,
previousResult: c.previousResult && c.previousResult(),
optimistic: c.optimistic,

@@ -194,0 +190,0 @@ }));

import { InlineFragmentNode, FragmentDefinitionNode, SelectionSetNode, FieldNode } from "graphql";
import { FragmentMap } from '../../utilities/graphql/fragments';
import { StoreValue } from '../../utilities/graphql/storeUtils';
import { StoreValue, isReference, Reference } from '../../utilities/graphql/storeUtils';
import { IdGetter, StoreObject } from "./types";

@@ -36,4 +36,5 @@ export declare type TypePolicies = {

variables?: Record<string, any>;
isReference: typeof isReference;
toReference: Policies["toReference"];
getFieldValue(field: string | FieldNode): Readonly<StoreValue>;
getFieldValue<T = StoreValue>(field: string | FieldNode, foreignRef?: Reference): Readonly<T>;
}

@@ -62,3 +63,3 @@ interface FieldReadFunction<TExisting, TResult = TExisting> {

});
toReference: (object: StoreObject, selectionSet?: SelectionSetNode, fragmentMap?: FragmentMap) => import("../../utilities/graphql/storeUtils").Reference;
toReference: (object: StoreObject, selectionSet?: SelectionSetNode, fragmentMap?: FragmentMap) => Reference;
identify(object: StoreObject, selectionSet?: SelectionSetNode, fragmentMap?: FragmentMap): string | null;

@@ -73,3 +74,3 @@ addTypePolicies(typePolicies: TypePolicies): void;

getStoreFieldName(typename: string | undefined, field: FieldNode, variables: Record<string, any>): string;
readFieldFromStoreObject(field: FieldNode, getFieldValue: (field: string) => StoreValue, typename?: string, variables?: Record<string, any>): StoreValue;
readFieldFromStoreObject(field: FieldNode, getFieldValue: (field: string, foreignRef?: Reference) => any, typename?: string, variables?: Record<string, any>): StoreValue;
getFieldMergeFunction(typename: string, field: FieldNode, variables?: Record<string, any>): StoreValueMergeFunction;

@@ -76,0 +77,0 @@ }

import { __assign } from 'tslib';
import invariant from 'ts-invariant';
import { getFragmentFromSelection } from '../../utilities/graphql/fragments.js';
import { makeReference, getTypenameFromResult, valueToObjectRepresentation, storeKeyNameFromField, argumentsObjectFromField, isField } from '../../utilities/graphql/storeUtils.js';
import { makeReference, getTypenameFromResult, valueToObjectRepresentation, storeKeyNameFromField, argumentsObjectFromField, isReference, isField } from '../../utilities/graphql/storeUtils.js';
import { canUseWeakMap } from '../../utilities/common/canUse.js';
import { KeyTrie } from 'optimism';
import { fieldNameFromStoreName } from './helpers.js';

@@ -167,12 +168,19 @@ var hasOwn = Object.prototype.hasOwnProperty;

Policies.prototype.getStoreFieldName = function (typename, field, variables) {
var fieldName = field.name.value;
var storeFieldName;
if (typeof typename === "string") {
var policy = this.getFieldPolicy(typename, field.name.value, false);
var policy = this.getFieldPolicy(typename, fieldName, false);
if (policy && policy.keyFn) {
return policy.keyFn.call(this, field, {
storeFieldName = policy.keyFn.call(this, field, {
typename: typename,
variables: variables,
});
}) || fieldName;
}
}
return storeKeyNameFromField(field, variables);
if (storeFieldName === void 0) {
storeFieldName = storeKeyNameFromField(field, variables);
}
return fieldName === fieldNameFromStoreName(storeFieldName)
? storeFieldName
: fieldName + ":" + storeFieldName;
};

@@ -190,6 +198,7 @@ Policies.prototype.readFieldFromStoreObject = function (field, getFieldValue, typename, variables) {

variables: variables,
isReference: isReference,
toReference: policies.toReference,
getFieldValue: function (nameOrField) {
getFieldValue: function (nameOrField, foreignRef) {
return getFieldValue(typeof nameOrField === "string" ? nameOrField :
policies.getStoreFieldName(typename, nameOrField, variables));
policies.getStoreFieldName(typename, nameOrField, variables), foreignRef);
},

@@ -209,2 +218,3 @@ });

variables: variables,
isReference: isReference,
toReference: policies.toReference,

@@ -211,0 +221,0 @@ getFieldValue: emptyGetFieldValueForMerge,

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

import { KeyTrie } from 'optimism';
import { Cache } from '../core/types/Cache';

@@ -19,3 +18,2 @@ import { DiffQueryAgainstStoreOptions, ReadQueryOptions, StoreObject } from './types';

addTypename?: boolean;
cacheKeyRoot?: KeyTrie<object>;
policies: Policies;

@@ -27,3 +25,3 @@ }

readQueryFromStore<QueryType>(options: ReadQueryOptions): QueryType | undefined;
diffQueryAgainstStore<T>({ store, query, variables, previousResult, returnPartialData, rootId, config, }: DiffQueryAgainstStoreOptions): Cache.DiffResult<T>;
diffQueryAgainstStore<T>({ store, query, variables, returnPartialData, rootId, config, }: DiffQueryAgainstStoreOptions): Cache.DiffResult<T>;
private executeSelectionSet;

@@ -30,0 +28,0 @@ private executeSubSelectedArray;

@@ -7,6 +7,4 @@ import { __assign } from 'tslib';

import { shouldInclude } from '../../utilities/graphql/directives.js';
import { canUseWeakMap } from '../../utilities/common/canUse.js';
import { equal } from '@wry/equality';
import { mergeDeepArray } from '../../utilities/common/mergeDeep.js';
import { KeyTrie, wrap } from 'optimism';
import { wrap } from 'optimism';
import { maybeDeepFreeze } from '../../utilities/common/maybeDeepFreeze.js';

@@ -20,4 +18,3 @@ import { getTypenameFromStoreObject } from './helpers.js';

this.config = config;
var cacheKeyRoot = config && config.cacheKeyRoot || new KeyTrie(canUseWeakMap);
this.config = __assign({ addTypename: true, cacheKeyRoot: cacheKeyRoot }, config);
this.config = __assign({ addTypename: true }, config);
var _a = this, executeSelectionSet = _a.executeSelectionSet, executeSubSelectedArray = _a.executeSubSelectedArray;

@@ -30,3 +27,5 @@ this.executeSelectionSet = wrap(function (options) {

if (supportsResultCaching(context.store)) {
return cacheKeyRoot.lookup(context.store, selectionSet, JSON.stringify(context.variables), isReference(objectOrReference) ? objectOrReference.__ref : objectOrReference);
return context.store.makeCacheKey(selectionSet, JSON.stringify(context.variables), isReference(objectOrReference)
? objectOrReference.__ref
: objectOrReference);
}

@@ -41,3 +40,3 @@ }

if (supportsResultCaching(context.store)) {
return cacheKeyRoot.lookup(context.store, field, array, JSON.stringify(context.variables));
return context.store.makeCacheKey(field, array, JSON.stringify(context.variables));
}

@@ -51,3 +50,3 @@ }

StoreReader.prototype.diffQueryAgainstStore = function (_a) {
var store = _a.store, query = _a.query, variables = _a.variables, previousResult = _a.previousResult, _b = _a.returnPartialData, returnPartialData = _b === void 0 ? true : _b, _c = _a.rootId, rootId = _c === void 0 ? 'ROOT_QUERY' : _c, config = _a.config;
var store = _a.store, query = _a.query, variables = _a.variables, _b = _a.returnPartialData, returnPartialData = _b === void 0 ? true : _b, _c = _a.rootId, rootId = _c === void 0 ? 'ROOT_QUERY' : _c, config = _a.config;
var policies = this.config.policies;

@@ -71,7 +70,2 @@ var execResult = this.executeSelectionSet({

}
if (previousResult) {
if (equal(previousResult, execResult.result)) {
execResult.result = previousResult;
}
}
return {

@@ -88,4 +82,6 @@ result: execResult.result,

var finalResult = { result: null };
function getFieldValue(fieldName) {
function getFieldValue(fieldName, foreignRef) {
var fieldValue;
if (foreignRef)
objectOrReference = foreignRef;
if (isReference(objectOrReference)) {

@@ -92,0 +88,0 @@ var dataId = objectOrReference.__ref;

@@ -13,5 +13,5 @@ import { DocumentNode } from 'graphql';

get(dataId: string): StoreObject;
getFieldValue(dataId: string, fieldName: string): StoreValue;
getFieldValue(dataId: string, storeFieldName: string): StoreValue;
merge(dataId: string, incoming: StoreObject): void;
delete(dataId: string): void;
delete(dataId: string, fieldName?: string): void;
clear(): void;

@@ -28,3 +28,3 @@ toObject(): NormalizedCacheObject;

__typename?: string;
[storeFieldKey: string]: StoreValue;
[storeFieldName: string]: StoreValue;
}

@@ -31,0 +31,0 @@ export declare type OptimisticStoreItem = {

@@ -85,3 +85,3 @@ import { __awaiter, __generator, __assign } from 'tslib';

else {
process.env.NODE_ENV === "production" ? invariant(false, 25) : invariant(false, 'To use context.getCacheKey, you need to use a cache that has ' +
process.env.NODE_ENV === "production" ? invariant(false, 36) : invariant(false, 'To use context.getCacheKey, you need to use a cache that has ' +
'a configurable dataIdFromObject, like apollo-cache-inmemory.');

@@ -194,3 +194,3 @@ }

fragment = fragmentMap[selection.name.value];
process.env.NODE_ENV === "production" ? invariant(fragment, 26) : invariant(fragment, "No fragment named " + selection.name.value);
process.env.NODE_ENV === "production" ? invariant(fragment, 37) : invariant(fragment, "No fragment named " + selection.name.value);
}

@@ -197,0 +197,0 @@ if (fragment && fragment.typeCondition) {

@@ -49,3 +49,3 @@ import { __awaiter, __generator, __assign } from 'tslib';

this.fetchQueryRejectFns.forEach(function (reject) {
reject(process.env.NODE_ENV === "production" ? new InvariantError(27) : new InvariantError('QueryManager stopped while query was in flight'));
reject(process.env.NODE_ENV === "production" ? new InvariantError(25) : new InvariantError('QueryManager stopped while query was in flight'));
});

@@ -61,4 +61,4 @@ };

case 0:
process.env.NODE_ENV === "production" ? invariant(mutation, 28) : invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.');
process.env.NODE_ENV === "production" ? invariant(!fetchPolicy || fetchPolicy === 'no-cache', 29) : invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.");
process.env.NODE_ENV === "production" ? invariant(mutation, 26) : invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.');
process.env.NODE_ENV === "production" ? invariant(!fetchPolicy || fetchPolicy === 'no-cache', 27) : invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.");
mutationId = this.generateQueryId();

@@ -457,3 +457,3 @@ mutation = this.transform(mutation).document;

if (shouldSubscribe === void 0) { shouldSubscribe = true; }
process.env.NODE_ENV === "production" ? invariant(options.fetchPolicy !== 'standby', 30) : invariant(options.fetchPolicy !== 'standby', 'client.watchQuery cannot be called with fetchPolicy set to "standby"');
process.env.NODE_ENV === "production" ? invariant(options.fetchPolicy !== 'standby', 28) : invariant(options.fetchPolicy !== 'standby', 'client.watchQuery cannot be called with fetchPolicy set to "standby"');
options.variables = this.getVariables(options.query, options.variables);

@@ -483,7 +483,7 @@ if (typeof options.notifyOnNetworkStatusChange === 'undefined') {

var _this = this;
process.env.NODE_ENV === "production" ? invariant(options.query, 31) : invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
process.env.NODE_ENV === "production" ? invariant(options.query, 29) : invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
'in the query option.');
process.env.NODE_ENV === "production" ? invariant(options.query.kind === 'Document', 32) : invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.');
process.env.NODE_ENV === "production" ? invariant(!options.returnPartialData, 33) : invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.');
process.env.NODE_ENV === "production" ? invariant(!options.pollInterval, 34) : invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.');
process.env.NODE_ENV === "production" ? invariant(options.query.kind === 'Document', 30) : invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.');
process.env.NODE_ENV === "production" ? invariant(!options.returnPartialData, 31) : invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.');
process.env.NODE_ENV === "production" ? invariant(!options.pollInterval, 32) : invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.');
return new Promise(function (resolve, reject) {

@@ -556,3 +556,3 @@ var watchedQuery = _this.watchQuery(options, false);

this.fetchQueryRejectFns.forEach(function (reject) {
reject(process.env.NODE_ENV === "production" ? new InvariantError(35) : new InvariantError('Store reset while query was in flight (not completed in link chain)'));
reject(process.env.NODE_ENV === "production" ? new InvariantError(33) : new InvariantError('Store reset while query was in flight (not completed in link chain)'));
});

@@ -676,3 +676,3 @@ var resetIds = [];

var foundObservableQuery = this.getQuery(queryIdOrObservable).observableQuery;
process.env.NODE_ENV === "production" ? invariant(foundObservableQuery, 36) : invariant(foundObservableQuery, "ObservableQuery with this id doesn't exist: " + queryIdOrObservable);
process.env.NODE_ENV === "production" ? invariant(foundObservableQuery, 34) : invariant(foundObservableQuery, "ObservableQuery with this id doesn't exist: " + queryIdOrObservable);
observableQuery = foundObservableQuery;

@@ -866,3 +866,3 @@ }

var pollInterval = options.pollInterval;
process.env.NODE_ENV === "production" ? invariant(pollInterval, 37) : invariant(pollInterval, 'Attempted to start a polling query without a polling interval.');
process.env.NODE_ENV === "production" ? invariant(pollInterval, 35) : invariant(pollInterval, 'Attempted to start a polling query without a polling interval.');
if (!this.ssrMode) {

@@ -869,0 +869,0 @@ var info = this.pollingInfoByQueryId.get(queryId);

@@ -20,3 +20,3 @@ import { invariant } from 'ts-invariant';

previousQuery.document === query.document ||
equal(previousQuery.document, query.document), 50) : invariant(!previousQuery ||
equal(previousQuery.document, query.document), 43) : invariant(!previousQuery ||
previousQuery.document === query.document ||

@@ -23,0 +23,0 @@ equal(previousQuery.document, query.document), 'Internal Error: may not update existing query string in store');

{
"name": "@apollo/client",
"version": "3.0.0-beta.14",
"version": "3.0.0-beta.15",
"description": "A fully-featured caching GraphQL client.",

@@ -55,4 +55,4 @@ "private": false,

"@types/lodash": "4.14.149",
"@types/node": "12.12.11",
"@types/react": "16.9.11",
"@types/node": "12.12.14",
"@types/react": "16.9.13",
"@types/react-dom": "16.9.4",

@@ -59,0 +59,0 @@ "bundlesize": "0.18.0",

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

import { ApolloQueryResult } from '../../core/types';
import { QueryResult, QueryDataOptions, QueryTuple } from '../types/types';

@@ -17,3 +16,3 @@ import { OperationData } from './OperationData';

executeLazy(): QueryTuple<TData, TVariables>;
fetchData(): Promise<ApolloQueryResult<any>> | boolean;
fetchData(): Promise<void> | boolean;
afterExecute({ queryResult, lazy, }: {

@@ -20,0 +19,0 @@ queryResult: QueryResult<TData, TVariables>;

@@ -22,6 +22,51 @@ import { __extends, __assign } from 'tslib';

};
_this.getExecuteResult = function () {
var result = _this.getQueryResult();
_this.startQuerySubscription();
return result;
_this.getQueryResult = function () {
var result = _this.observableQueryFields();
var options = _this.getOptions();
if (options.skip) {
result = __assign(__assign({}, result), { data: undefined, error: undefined, loading: false, called: true });
}
else {
var currentResult = _this.currentObservable.query.getCurrentResult();
var loading = currentResult.loading, networkStatus = currentResult.networkStatus, errors = currentResult.errors;
var error = currentResult.error, data = currentResult.data;
if (errors && errors.length > 0) {
error = new ApolloError({ graphQLErrors: errors });
}
result = __assign(__assign({}, result), { loading: loading,
networkStatus: networkStatus,
error: error, called: true });
if (loading) {
var previousData = _this.previousData.result && _this.previousData.result.data;
result.data =
previousData && data
? __assign(__assign({}, previousData), data) : previousData || data;
}
else if (error) {
Object.assign(result, {
data: (_this.currentObservable.query.getLastResult() || {})
.data
});
}
else {
var fetchPolicy = _this.currentObservable.query.options.fetchPolicy;
var partialRefetch = options.partialRefetch;
if (partialRefetch &&
!data &&
fetchPolicy !== 'cache-only') {
Object.assign(result, {
loading: true,
networkStatus: NetworkStatus.loading
});
result.refetch();
return result;
}
result.data = data;
}
}
result.client = _this.client;
_this.setOptions(options, true);
_this.previousData.loading =
_this.previousData.result && _this.previousData.result.loading || false;
return _this.previousData.result = result;
};

@@ -73,8 +118,7 @@ _this.obsRefetch = function (variables) {

QueryData.prototype.fetchData = function () {
var _this = this;
var options = this.getOptions();
if (options.skip || options.ssr === false)
return false;
var obs = this.currentObservable.query;
var currentResult = obs.getCurrentResult();
return currentResult.loading ? obs.result() : false;
return new Promise(function (resolve) { return _this.startQuerySubscription(resolve); });
};

@@ -111,2 +155,7 @@ QueryData.prototype.afterExecute = function (_a) {

};
QueryData.prototype.getExecuteResult = function () {
var result = this.getQueryResult();
this.startQuerySubscription();
return result;
};
QueryData.prototype.getExecuteSsrResult = function () {

@@ -128,3 +177,3 @@ var treeRenderingInitiated = this.context && this.context.renderPromises;

result =
this.context.renderPromises.addQueryPromise(this, this.getExecuteResult) || ssrLoading;
this.context.renderPromises.addQueryPromise(this, this.getQueryResult) || ssrLoading;
}

@@ -171,4 +220,5 @@ return result;

};
QueryData.prototype.startQuerySubscription = function () {
QueryData.prototype.startQuerySubscription = function (onNewData) {
var _this = this;
if (onNewData === void 0) { onNewData = this.forceUpdate; }
if (this.currentObservable.subscription || this.getOptions().skip)

@@ -187,3 +237,6 @@ return;

}
_this.forceUpdate();
if (_this.previousOptions.skip) {
return;
}
onNewData();
},

@@ -198,3 +251,3 @@ error: function (error) {

_this.previousData.error = error;
_this.forceUpdate();
onNewData();
}

@@ -215,52 +268,2 @@ }

};
QueryData.prototype.getQueryResult = function () {
var result = this.observableQueryFields();
var options = this.getOptions();
if (options.skip) {
result = __assign(__assign({}, result), { data: undefined, error: undefined, loading: false, called: true });
}
else {
var currentResult = this.currentObservable.query.getCurrentResult();
var loading = currentResult.loading, networkStatus = currentResult.networkStatus, errors = currentResult.errors;
var error = currentResult.error, data = currentResult.data;
if (errors && errors.length > 0) {
error = new ApolloError({ graphQLErrors: errors });
}
result = __assign(__assign({}, result), { loading: loading,
networkStatus: networkStatus,
error: error, called: true });
if (loading) {
var previousData = this.previousData.result && this.previousData.result.data;
result.data =
previousData && data
? __assign(__assign({}, previousData), data) : previousData || data;
}
else if (error) {
Object.assign(result, {
data: (this.currentObservable.query.getLastResult() || {})
.data
});
}
else {
var fetchPolicy = this.currentObservable.query.options.fetchPolicy;
var partialRefetch = options.partialRefetch;
if (partialRefetch &&
!data &&
fetchPolicy !== 'cache-only') {
Object.assign(result, {
loading: true,
networkStatus: NetworkStatus.loading
});
result.refetch();
return result;
}
result.data = data;
}
}
result.client = this.client;
this.setOptions(options, true);
this.previousData.loading =
this.previousData.result && this.previousData.result.loading || false;
return this.previousData.result = result;
};
QueryData.prototype.handleErrorOrCompleted = function (_a) {

@@ -267,0 +270,0 @@ var data = _a.data, loading = _a.loading, error = _a.error;

@@ -12,3 +12,3 @@ import { invariant } from 'ts-invariant';

evaledValue = variables[ifArgument.value.name.value];
process.env.NODE_ENV === "production" ? invariant(evaledValue !== void 0, 43) : invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.");
process.env.NODE_ENV === "production" ? invariant(evaledValue !== void 0, 44) : invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.");
}

@@ -46,8 +46,8 @@ else {

var directiveName = directive.name.value;
process.env.NODE_ENV === "production" ? invariant(directiveArguments && directiveArguments.length === 1, 44) : invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
process.env.NODE_ENV === "production" ? invariant(directiveArguments && directiveArguments.length === 1, 45) : invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
process.env.NODE_ENV === "production" ? invariant(ifArgument.name && ifArgument.name.value === 'if', 45) : invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
process.env.NODE_ENV === "production" ? invariant(ifArgument.name && ifArgument.name.value === 'if', 46) : invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = ifArgument.value;
process.env.NODE_ENV === "production" ? invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 46) : invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 47) : invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");

@@ -54,0 +54,0 @@ return { directive: directive, ifArgument: ifArgument };

@@ -9,3 +9,3 @@ import { __assign, __spreadArrays } from 'tslib';

if (definition.kind === 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new InvariantError(47) : new InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
throw process.env.NODE_ENV === "production" ? new InvariantError(48) : new InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
'No operations are allowed when using a fragment as a query. Only fragments are allowed.');

@@ -18,3 +18,3 @@ }

if (typeof actualFragmentName === 'undefined') {
process.env.NODE_ENV === "production" ? invariant(fragments.length === 1, 48) : invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
process.env.NODE_ENV === "production" ? invariant(fragments.length === 1, 49) : invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
actualFragmentName = fragments[0].name.value;

@@ -56,3 +56,3 @@ }

var fragment = fragmentMap && fragmentMap[selection.name.value];
process.env.NODE_ENV === "production" ? invariant(fragment, 49) : invariant(fragment, "No fragment named " + selection.name.value + ".");
process.env.NODE_ENV === "production" ? invariant(fragment, 50) : invariant(fragment, "No fragment named " + selection.name.value + ".");
return fragment;

@@ -59,0 +59,0 @@ }

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 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 too big to display

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