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.13 to 3.0.0-beta.14

cache/inmemory/entityStore.d.ts

2

cache/inmemory/helpers.d.ts
import { NormalizedCache, StoreObject } from './types';
import { Reference } from '../../utilities/graphql/storeUtils';
export declare function getTypenameFromStoreObject(store: NormalizedCache, storeObject: StoreObject | Reference): string | undefined;
export declare function getTypenameFromStoreObject(store: NormalizedCache, objectOrReference: StoreObject | Reference): string | undefined;
//# sourceMappingURL=helpers.d.ts.map
import { isReference } from '../../utilities/graphql/storeUtils.js';
function getTypenameFromStoreObject(store, storeObject) {
return isReference(storeObject)
? getTypenameFromStoreObject(store, store.get(storeObject.__ref))
: storeObject && storeObject.__typename;
function getTypenameFromStoreObject(store, objectOrReference) {
return isReference(objectOrReference)
? store.getFieldValue(objectOrReference.__ref, "__typename")
: objectOrReference && objectOrReference.__typename;
}

@@ -8,0 +8,0 @@

@@ -7,3 +7,3 @@ import { __extends, __assign } from 'tslib';

import { KeyTrie, wrap } from 'optimism';
import { EntityCache, supportsResultCaching } from './entityCache.js';
import { EntityStore, supportsResultCaching } from './entityStore.js';
import { StoreReader } from './readFromStore.js';

@@ -35,3 +35,3 @@ import { StoreWriter } from './writeToStore.js';

});
_this.data = new EntityCache.Root({
_this.data = new EntityStore.Root({
resultCaching: _this.config.resultCaching,

@@ -75,3 +75,3 @@ });

if (typeof options.rootId === 'string' &&
typeof this.data.get(options.rootId) === 'undefined') {
!this.data.has(options.rootId)) {
return null;

@@ -78,0 +78,0 @@ }

@@ -34,6 +34,6 @@ import { InlineFragmentNode, FragmentDefinitionNode, SelectionSetNode, FieldNode } from "graphql";

args: Record<string, any>;
parentObject: Readonly<StoreObject>;
field: FieldNode;
variables?: Record<string, any>;
toReference: Policies["toReference"];
getFieldValue(field: string | FieldNode): Readonly<StoreValue>;
}

@@ -72,7 +72,7 @@ interface FieldReadFunction<TExisting, TResult = TExisting> {

getStoreFieldName(typename: string | undefined, field: FieldNode, variables: Record<string, any>): string;
readFieldFromStoreObject(parentObject: Readonly<StoreObject>, field: FieldNode, typename?: string, variables?: Record<string, any>): StoreValue;
readFieldFromStoreObject(field: FieldNode, getFieldValue: (field: string) => StoreValue, typename?: string, variables?: Record<string, any>): StoreValue;
getFieldMergeFunction(typename: string, field: FieldNode, variables?: Record<string, any>): StoreValueMergeFunction;
}
export declare type StoreValueMergeFunction = (existing: StoreValue, incoming: StoreValue, parentObject: Readonly<StoreObject>) => StoreValue;
export declare type StoreValueMergeFunction = (existing: StoreValue, incoming: StoreValue) => StoreValue;
export {};
//# sourceMappingURL=policies.d.ts.map

@@ -178,14 +178,18 @@ import { __assign } from 'tslib';

};
Policies.prototype.readFieldFromStoreObject = function (parentObject, field, typename, variables) {
if (typename === void 0) { typename = parentObject.__typename; }
var storeFieldName = this.getStoreFieldName(typename, field, variables);
var existing = parentObject[storeFieldName];
var policy = this.getFieldPolicy(typename, field.name.value, false);
Policies.prototype.readFieldFromStoreObject = function (field, getFieldValue, typename, variables) {
if (typename === void 0) { typename = getFieldValue("__typename"); }
var policies = this;
var storeFieldName = policies.getStoreFieldName(typename, field, variables);
var existing = getFieldValue(storeFieldName);
var policy = policies.getFieldPolicy(typename, field.name.value, false);
if (policy && policy.read) {
return policy.read.call(this, existing, {
return policy.read.call(policies, existing, {
args: argumentsObjectFromField(field, variables),
parentObject: parentObject,
field: field,
variables: variables,
toReference: this.toReference,
toReference: policies.toReference,
getFieldValue: function (nameOrField) {
return getFieldValue(typeof nameOrField === "string" ? nameOrField :
policies.getStoreFieldName(typename, nameOrField, variables));
},
});

@@ -196,11 +200,12 @@ }

Policies.prototype.getFieldMergeFunction = function (typename, field, variables) {
var _this = this;
var policy = this.getFieldPolicy(typename, field.name.value, false);
var policies = this;
var policy = policies.getFieldPolicy(typename, field.name.value, false);
if (policy && policy.merge) {
return function (existing, incoming, parentObject) { return policy.merge.call(_this, existing, incoming, {
args: argumentsObjectFromField(field, variables),
parentObject: parentObject,
var args_1 = argumentsObjectFromField(field, variables);
return function (existing, incoming) { return policy.merge.call(policies, existing, incoming, {
args: args_1,
field: field,
variables: variables,
toReference: _this.toReference,
toReference: policies.toReference,
getFieldValue: emptyGetFieldValueForMerge,
}); };

@@ -211,2 +216,5 @@ }

}());
function emptyGetFieldValueForMerge() {
process.env.NODE_ENV === "production" || invariant.warn("getFieldValue unavailable in merge functions");
}
function keyArgsFnFromSpecifier(specifier) {

@@ -222,9 +230,9 @@ var topLevelArgNames = Object.create(null);

if (field.arguments && field.arguments.length > 0) {
var args_1 = Object.create(null);
var args_2 = Object.create(null);
field.arguments.forEach(function (arg) {
if (topLevelArgNames[arg.name.value] === true) {
valueToObjectRepresentation(args_1, arg.name, arg.value, context.variables);
valueToObjectRepresentation(args_2, arg.name, arg.value, context.variables);
}
});
return fieldName + ":" + JSON.stringify(computeKeyObject(args_1, specifier));
return fieldName + ":" + JSON.stringify(computeKeyObject(args_2, specifier));
}

@@ -231,0 +239,0 @@ return fieldName;

@@ -28,6 +28,4 @@ import { KeyTrie } from 'optimism';

private executeSelectionSet;
private executeField;
private combineExecResults;
private executeSubSelectedArray;
}
//# sourceMappingURL=readFromStore.d.ts.map
import { __assign } from 'tslib';
import { InvariantError } from 'ts-invariant';
import { invariant } from 'ts-invariant';
import { createFragmentMap } from '../../utilities/graphql/fragments.js';

@@ -12,4 +12,4 @@ import { isReference, makeReference, isField, resultKeyNameFromField, isInlineFragment } from '../../utilities/graphql/storeUtils.js';

import { maybeDeepFreeze } from '../../utilities/common/maybeDeepFreeze.js';
import { supportsResultCaching } from './entityCache.js';
import { getTypenameFromStoreObject } from './helpers.js';
import { supportsResultCaching } from './entityStore.js';

@@ -64,5 +64,3 @@ var StoreReader = (function () {

execResult.missing.forEach(function (info) {
if (info.tolerable)
return;
throw process.env.NODE_ENV === "production" ? new InvariantError(53) : new InvariantError("Can't find field " + info.fieldName + " on object " + JSON.stringify(info.object, null, 2) + ".");
process.env.NODE_ENV === "production" ? invariant(info.tolerable, 53) : invariant(info.tolerable, "Can't find field " + info.fieldName + " on object " + JSON.stringify(info.object, null, 2) + ".");
});

@@ -84,29 +82,34 @@ }

var store = context.store, fragmentMap = context.fragmentMap, variables = context.variables, policies = context.policies;
var objectsToMerge = [];
var finalResult = { result: null };
var objectsToMerge = [];
var object;
var typename;
if (isReference(objectOrReference)) {
object = store.get(objectOrReference.__ref);
typename =
(object && object.__typename) ||
policies.rootTypenamesById[objectOrReference.__ref];
function getFieldValue(fieldName) {
var fieldValue;
if (isReference(objectOrReference)) {
var dataId = objectOrReference.__ref;
fieldValue = store.getFieldValue(dataId, fieldName);
if (fieldValue === void 0 && fieldName === "__typename") {
return policies.rootTypenamesById[dataId];
}
}
else {
fieldValue = objectOrReference && objectOrReference[fieldName];
}
if (process.env.NODE_ENV !== "production") {
maybeDeepFreeze(fieldValue);
}
return fieldValue;
}
else {
object = objectOrReference;
typename = object && object.__typename;
var typename = getFieldValue("__typename");
if (this.config.addTypename &&
typeof typename === "string" &&
Object.values(policies.rootTypenamesById).indexOf(typename) < 0) {
objectsToMerge.push({ __typename: typename });
}
if (this.config.addTypename) {
var typenameFromStore = object && object.__typename;
if (typeof typenameFromStore === "string" &&
Object.values(policies.rootTypenamesById).indexOf(typenameFromStore) < 0) {
objectsToMerge.push({ __typename: typenameFromStore });
}
function getMissing() {
return finalResult.missing || (finalResult.missing = []);
}
function handleMissing(result) {
var _a;
if (result.missing) {
finalResult.missing = finalResult.missing || [];
(_a = finalResult.missing).push.apply(_a, result.missing);
}
if (result.missing)
(_a = getMissing()).push.apply(_a, result.missing);
return result.result;

@@ -116,10 +119,36 @@ }

var _a;
if (!shouldInclude(selection, variables)) {
if (!shouldInclude(selection, variables))
return;
}
if (isField(selection)) {
var fieldResult = handleMissing(_this.executeField(object, typename, selection, context));
if (typeof fieldResult !== 'undefined') {
var fieldValue = policies.readFieldFromStoreObject(selection, getFieldValue, typename, variables);
if (fieldValue === void 0) {
getMissing().push({
object: objectOrReference,
fieldName: selection.name.value,
tolerable: false,
});
}
else if (Array.isArray(fieldValue)) {
fieldValue = handleMissing(_this.executeSubSelectedArray({
field: selection,
array: fieldValue,
context: context,
}));
}
else if (!selection.selectionSet) {
if (process.env.NODE_ENV !== 'production') {
assertSelectionSetForIdValue(context.store, selection, fieldValue);
maybeDeepFreeze(fieldValue);
}
}
else if (fieldValue != null) {
fieldValue = handleMissing(_this.executeSelectionSet({
selectionSet: selection.selectionSet,
objectOrReference: fieldValue,
context: context,
}));
}
if (fieldValue !== void 0) {
objectsToMerge.push((_a = {},
_a[resultKeyNameFromField(selection)] = fieldResult,
_a[resultKeyNameFromField(selection)] = fieldValue,
_a));

@@ -134,6 +163,3 @@ }

else {
fragment = fragmentMap[selection.name.value];
if (!fragment) {
throw process.env.NODE_ENV === "production" ? new InvariantError(54) : new InvariantError("No fragment named " + selection.name.value);
}
process.env.NODE_ENV === "production" ? invariant(fragment = fragmentMap[selection.name.value], 54) : invariant(fragment = fragmentMap[selection.name.value], "No fragment named " + selection.name.value);
}

@@ -162,56 +188,2 @@ var match = policies.fragmentMatches(fragment, typename);

};
StoreReader.prototype.executeField = function (object, typename, field, context) {
var variables = context.variables, store = context.store, policies = context.policies;
var fieldValue = object &&
policies.readFieldFromStoreObject(object, field, typename, variables);
var readStoreResult = typeof fieldValue === "undefined" ? {
result: fieldValue,
missing: [{
object: object,
fieldName: field.name.value,
tolerable: false,
}],
} : {
result: fieldValue,
};
if (Array.isArray(readStoreResult.result)) {
return this.combineExecResults(readStoreResult, this.executeSubSelectedArray({
field: field,
array: readStoreResult.result,
context: context,
}));
}
if (!field.selectionSet) {
if (process.env.NODE_ENV !== 'production') {
assertSelectionSetForIdValue(store, field, readStoreResult.result);
maybeDeepFreeze(readStoreResult);
}
return readStoreResult;
}
if (readStoreResult.result == null) {
return readStoreResult;
}
return this.combineExecResults(readStoreResult, this.executeSelectionSet({
selectionSet: field.selectionSet,
objectOrReference: readStoreResult.result,
context: context,
}));
};
StoreReader.prototype.combineExecResults = function () {
var execResults = [];
for (var _i = 0; _i < arguments.length; _i++) {
execResults[_i] = arguments[_i];
}
var missing;
execResults.forEach(function (execResult) {
if (execResult.missing) {
missing = missing || [];
missing.push.apply(missing, execResult.missing);
}
});
return {
result: execResults.pop().result,
missing: missing,
};
};
StoreReader.prototype.executeSubSelectedArray = function (_a) {

@@ -263,5 +235,3 @@ var _this = this;

if (value && typeof value === "object") {
if (isReference(value)) {
throw process.env.NODE_ENV === "production" ? new InvariantError(55) : new InvariantError("Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value);
}
process.env.NODE_ENV === "production" ? invariant(!isReference(value), 55) : invariant(!isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value);
Object.values(value).forEach(workSet_1.add, workSet_1);

@@ -268,0 +238,0 @@ }

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

get(dataId: string): StoreObject;
set(dataId: string, value: StoreObject): void;
getFieldValue(dataId: string, fieldName: string): StoreValue;
merge(dataId: string, incoming: StoreObject): void;
delete(dataId: string): void;

@@ -16,0 +17,0 @@ clear(): void;

@@ -11,3 +11,2 @@ import { SelectionSetNode, DocumentNode } from 'graphql';

readonly mergeFields: StoreObjectMergeFunction;
readonly mergeStoreObjects: StoreObjectMergeFunction;
readonly variables?: any;

@@ -14,0 +13,0 @@ readonly fragmentMap?: FragmentMap;

import { __assign } from 'tslib';
import { invariant } from 'ts-invariant';
import { createFragmentMap, getFragmentFromSelection } from '../../utilities/graphql/fragments.js';
import { getTypenameFromResult, isField, resultKeyNameFromField, makeReference, isReference } from '../../utilities/graphql/storeUtils.js';
import { getTypenameFromResult, isField, resultKeyNameFromField, makeReference } from '../../utilities/graphql/storeUtils.js';
import { getOperationDefinition, getDefaultValues, getFragmentDefinitions } from '../../utilities/graphql/getFromAST.js';
import { shouldInclude } from '../../utilities/graphql/directives.js';
import { equal } from '@wry/equality';
import { cloneDeep } from '../../utilities/common/cloneDeep.js';
import { DeepMerger } from '../../utilities/common/mergeDeep.js';
import { defaultNormalizedCacheFactory } from './entityCache.js';
import { getTypenameFromStoreObject } from './helpers.js';
import { maybeDeepFreeze } from '../../utilities/common/maybeDeepFreeze.js';
import { defaultNormalizedCacheFactory } from './entityStore.js';

@@ -22,3 +21,2 @@ var StoreWriter = (function () {

var simpleFieldsMerger = new DeepMerger;
var storeObjectMerger = new DeepMerger(storeObjectReconciler);
return this.writeSelectionSetToStore({

@@ -34,5 +32,2 @@ result: result || Object.create(null),

},
mergeStoreObjects: function (existing, incoming) {
return storeObjectMerger.merge(existing, incoming, store);
},
variables: __assign(__assign({}, getDefaultValues(operationDefinition)), variables),

@@ -56,7 +51,6 @@ fragmentMap: createFragmentMap(getFragmentDefinitions(query)),

});
var existing = store.get(dataId) || Object.create(null);
if (processed.mergeOverrides) {
walkWithMergeOverrides(existing, processed.result, processed.mergeOverrides);
walkWithMergeOverrides(store.get(dataId), processed.result, processed.mergeOverrides);
}
store.set(dataId, context.mergeStoreObjects(existing, processed.result));
store.merge(dataId, processed.result);
return store;

@@ -166,28 +160,11 @@ };

if (merge) {
incomingObject[name] = merge(existingValue, incomingValue, existingObject);
if (process.env.NODE_ENV !== "production") {
maybeDeepFreeze(existingValue);
}
incomingObject[name] = merge(existingValue, incomingValue);
}
});
}
var storeObjectReconciler = function (existingObject, incomingObject, property, store) {
var existing = existingObject[property];
var incoming = incomingObject[property];
if (existing !== incoming &&
this.isObject(existing) &&
this.isObject(incoming)) {
var eType = getTypenameFromStoreObject(store, existing);
var iType = getTypenameFromStoreObject(store, incoming);
if (typeof eType === 'string' &&
typeof iType === 'string' &&
eType !== iType) {
return incoming;
}
process.env.NODE_ENV === "production" ? invariant(!isReference(existing) || isReference(incoming), 56) : invariant(!isReference(existing) || isReference(incoming), "Store error: the application attempted to write an object with no provided id but the store already contains an id of " + existing.__ref + " for this object.");
if (equal(existing, incoming)) {
return existing;
}
}
return incoming;
};
export { StoreWriter };
//# sourceMappingURL=writeToStore.js.map

@@ -8,2 +8,3 @@ import { ExecutionResult, DocumentNode, FieldNode, ASTNode } from 'graphql';

field: FieldNode;
fragmentMap: FragmentMap;
}) => any;

@@ -10,0 +11,0 @@ export declare type VariableMap = {

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

if (resolve) {
resultPromise = Promise.resolve(resolve(rootValue, argumentsObjectFromField(field, variables), execContext.context, { field: field }));
resultPromise = Promise.resolve(resolve(rootValue, argumentsObjectFromField(field, variables), execContext.context, { field: field, fragmentMap: execContext.fragmentMap }));
}

@@ -233,0 +233,0 @@ }

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

@@ -51,13 +51,13 @@ "private": false,

"devDependencies": {
"@testing-library/react": "^9.1.4",
"@types/fast-json-stable-stringify": "^2.0.0",
"@types/jest": "24.0.18",
"@types/lodash": "4.14.139",
"@types/node": "12.7.5",
"@types/react": "16.9.2",
"@types/react-dom": "16.9.0",
"@testing-library/react": "9.1.4",
"@types/fast-json-stable-stringify": "2.0.0",
"@types/jest": "24.0.23",
"@types/lodash": "4.14.149",
"@types/node": "12.12.11",
"@types/react": "16.9.11",
"@types/react-dom": "16.9.4",
"bundlesize": "0.18.0",
"codecov": "3.5.0",
"fetch-mock": "^7.3.9",
"graphql": "^14.5.8",
"codecov": "3.6.1",
"fetch-mock": "7.7.3",
"graphql": "14.5.8",
"jest": "24.9.0",

@@ -67,8 +67,8 @@ "jest-junit": "8.0.0",

"prop-types": "15.7.2",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"recast": "^0.18.5",
"rimraf": "^3.0.0",
"react": "16.12.0",
"react-dom": "16.12.0",
"recast": "0.18.5",
"rimraf": "3.0.0",
"rollup": "1.21.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-invariant": "0.5.6",

@@ -75,0 +75,0 @@ "rollup-plugin-node-resolve": "5.2.0",

import { isDevelopment, isTest } from './environment.js';
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o[prop] !== null &&
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
!Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
function isObject(value) {
return value !== null && typeof value === "object";
}
function deepFreeze(value) {
var workSet = new Set([value]);
workSet.forEach(function (obj) {
if (isObject(obj)) {
if (!Object.isFrozen(obj))
Object.freeze(obj);
Object.getOwnPropertyNames(obj).forEach(function (name) {
if (isObject(obj[name]))
workSet.add(obj[name]);
});
}
});
return o;
return value;
}
function maybeDeepFreeze(obj) {
if (isDevelopment() || isTest()) {
var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
if (!symbolIsPolyfilled) {
return deepFreeze(obj);
}
deepFreeze(obj);
}

@@ -21,0 +24,0 @@ return obj;

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

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