Socket
Socket
Sign inDemoInstall

@apollo/client

Package Overview
Dependencies
Maintainers
1
Versions
575
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.53 to 3.0.0-beta.54

8

cache/inmemory/readFromStore.js

@@ -95,2 +95,10 @@ import { __assign } from 'tslib';

var selectionSet = _a.selectionSet, objectOrReference = _a.objectOrReference, context = _a.context;
if (isReference(objectOrReference) &&
!context.policies.rootTypenamesById[objectOrReference.__ref] &&
!context.store.has(objectOrReference.__ref)) {
return {
result: {},
missing: [missingFromInvariant(process.env.NODE_ENV === "production" ? new InvariantError(46) : new InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object"), context)],
};
}
var fragmentMap = context.fragmentMap, variables = context.variables, policies = context.policies, store = context.store;

@@ -97,0 +105,0 @@ var objectsToMerge = [];

63

cache/inmemory/writeToStore.js
import { __assign } from 'tslib';
import { InvariantError } from 'ts-invariant';
import { InvariantError, invariant } from 'ts-invariant';
import { createFragmentMap, getFragmentFromSelection } from '../../utilities/graphql/fragments.js';
import { isReference, makeReference, getTypenameFromResult, isField, resultKeyNameFromField } from '../../utilities/graphql/storeUtils.js';
import { getOperationDefinition, getDefaultValues, getFragmentDefinitions } from '../../utilities/graphql/getFromAST.js';
import { equal } from '@wry/equality';
import { shouldInclude, hasDirectives } from '../../utilities/graphql/directives.js';
import { cloneDeep } from '../../utilities/common/cloneDeep.js';
import { makeProcessedFieldsMerger } from './helpers.js';
import { fieldNameFromStoreName, makeProcessedFieldsMerger } from './helpers.js';

@@ -102,3 +103,3 @@ var StoreWriter = (function () {

!hasDirectives(["defer", "client"], selection)) {
throw process.env.NODE_ENV === "production" ? new InvariantError(46) : new InvariantError("Missing field '" + resultFieldKey + "' in " + JSON.stringify(result, null, 2).substring(0, 100));
throw process.env.NODE_ENV === "production" ? new InvariantError(50) : new InvariantError("Missing field '" + resultFieldKey + "' in " + JSON.stringify(result, null, 2).substring(0, 100));
}

@@ -114,8 +115,16 @@ }

if ("string" === typeof dataId) {
var entityRef = makeReference(dataId);
var entityRef_1 = makeReference(dataId);
if (out.shouldApplyMerges) {
mergedFields = policies.applyMerges(entityRef, mergedFields, context);
mergedFields = policies.applyMerges(entityRef_1, mergedFields, context);
}
if (process.env.NODE_ENV !== "production") {
Object.keys(mergedFields).forEach(function (storeFieldName) {
var fieldName = fieldNameFromStoreName(storeFieldName);
if (!policies.hasMergeFunction(typename, fieldName)) {
warnAboutDataLoss(entityRef_1, mergedFields, storeFieldName, context.store);
}
});
}
context.store.merge(dataId, mergedFields);
return entityRef;
return entityRef_1;
}

@@ -141,4 +150,46 @@ return mergedFields;

}());
var warnings = new Set();
function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
var getChild = function (objOrRef) {
var child = store.getFieldValue(objOrRef, storeFieldName);
return typeof child === "object" && child;
};
var existing = getChild(existingRef);
if (!existing)
return;
var incoming = getChild(incomingObj);
if (!incoming)
return;
if (isReference(existing))
return;
if (equal(existing, incoming))
return;
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
return;
}
var parentType = store.getFieldValue(existingRef, "__typename") ||
store.getFieldValue(incomingObj, "__typename");
var fieldName = fieldNameFromStoreName(storeFieldName);
var typeDotName = parentType + "." + fieldName;
if (warnings.has(typeDotName))
return;
warnings.add(typeDotName);
var childTypenames = [];
if (!Array.isArray(existing) &&
!Array.isArray(incoming)) {
[existing, incoming].forEach(function (child) {
var typename = store.getFieldValue(child, "__typename");
if (typeof typename === "string" &&
!childTypenames.includes(typename)) {
childTypenames.push(typename);
}
});
}
process.env.NODE_ENV === "production" || invariant.warn("Cache data may be lost when replacing the " + fieldName + " field of a " + parentType + " object.\n\nTo address this problem (which is not a bug in Apollo Client), " + (childTypenames.length
? "either ensure all objects of type " +
childTypenames.join(" and ") + " have IDs, or "
: "") + "define a custom merge function for the " + typeDotName + " field, so InMemoryCache can safely merge these objects:\n\n existing: " + JSON.stringify(existing).slice(0, 1000) + "\n incoming: " + JSON.stringify(incoming).slice(0, 1000) + "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n");
}
export { StoreWriter };
//# sourceMappingURL=writeToStore.js.map

4

package.json
{
"name": "@apollo/client",
"version": "3.0.0-beta.53",
"version": "3.0.0-beta.54",
"description": "A fully-featured caching GraphQL client.",

@@ -79,3 +79,3 @@ "private": false,

"rxjs": "6.5.3",
"ts-jest": "26.0.0",
"ts-jest": "26.1.0",
"tsc-watch": "3.0.1",

@@ -82,0 +82,0 @@ "typescript": "3.9.3"

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

function isReference(obj) {
return obj && typeof obj === 'object' && typeof obj.__ref === 'string';
return Boolean(obj && typeof obj === 'object' && typeof obj.__ref === 'string');
}

@@ -12,0 +12,0 @@ function isStringValue(value) {

@@ -134,3 +134,3 @@ 'use strict';

function isReference(obj) {
return obj && typeof obj === 'object' && typeof obj.__ref === 'string';
return Boolean(obj && typeof obj === 'object' && typeof obj.__ref === 'string');
}

@@ -137,0 +137,0 @@ function isStringValue(value) {

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