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.47 to 3.0.0-beta.48

8

cache/inmemory/inMemoryCache.js

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

policies: _this.policies,
reader: _this.storeReader = new StoreReader({
addTypename: _this.addTypename,
policies: _this.policies,
}),
});
_this.storeReader = new StoreReader({
addTypename: _this.addTypename,
policies: _this.policies,
});
var cache = _this;

@@ -46,0 +46,0 @@ var maybeBroadcastWatch = cache.maybeBroadcastWatch;

@@ -87,2 +87,3 @@ import { InlineFragmentNode, FragmentDefinitionNode, SelectionSetNode, FieldNode } from "graphql";

variables: Record<string, any>;
varString: string;
toReference: ToReferenceFunction;

@@ -89,0 +90,0 @@ getFieldValue: FieldValueGetter;

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

import { SelectionSetNode } from 'graphql';
import { Reference, StoreObject } from '../../utilities/graphql/storeUtils';
import { Cache } from '../core/types/Cache';
import { DiffQueryAgainstStoreOptions, ReadQueryOptions } from './types';
import { DiffQueryAgainstStoreOptions, ReadQueryOptions, NormalizedCache } from './types';
import { Policies } from './policies';

@@ -21,5 +23,9 @@ import { MissingFieldError } from '../core/types/common';

diffQueryAgainstStore<T>({ store, query, rootId, variables, returnPartialData, }: DiffQueryAgainstStoreOptions): Cache.DiffResult<T>;
isFresh(result: Record<string, any>, store: NormalizedCache, parent: StoreObject | Reference, selectionSet: SelectionSetNode, varString: string): boolean;
private executeSelectionSet;
private execSelectionSetImpl;
private knownResults;
private executeSubSelectedArray;
private execSubSelectedArrayImpl;
}
//# sourceMappingURL=readFromStore.d.ts.map

@@ -22,18 +22,20 @@ import { __assign } from 'tslib';

this.config = config;
this.config = __assign({ addTypename: true }, config);
var _a = this, executeSelectionSet = _a.executeSelectionSet, executeSubSelectedArray = _a.executeSubSelectedArray;
this.executeSelectionSet = wrap(function (options) {
return executeSelectionSet.call(_this, options);
}, {
makeCacheKey: function (_a) {
var selectionSet = _a.selectionSet, objectOrReference = _a.objectOrReference, context = _a.context;
if (supportsResultCaching(context.store)) {
return context.store.makeCacheKey(selectionSet, context.varString, isReference(objectOrReference)
? objectOrReference.__ref
: objectOrReference);
this.executeSelectionSet = wrap(function (options) { return _this.execSelectionSetImpl(options); }, {
keyArgs: function (options) {
return [
options.context.store,
options.selectionSet,
options.objectOrReference,
options.context.varString,
];
},
makeCacheKey: function (store, selectionSet, parent, varString) {
if (supportsResultCaching(store)) {
return store.makeCacheKey(selectionSet, isReference(parent) ? parent.__ref : parent, varString);
}
}
});
this.knownResults = new WeakMap();
this.executeSubSelectedArray = wrap(function (options) {
return executeSubSelectedArray.call(_this, options);
return _this.execSubSelectedArrayImpl(options);
}, {

@@ -47,2 +49,3 @@ makeCacheKey: function (_a) {

});
this.config = __assign({ addTypename: true }, config);
}

@@ -81,3 +84,13 @@ StoreReader.prototype.readQueryFromStore = function (options) {

};
StoreReader.prototype.executeSelectionSet = function (_a) {
StoreReader.prototype.isFresh = function (result, store, parent, selectionSet, varString) {
if (supportsResultCaching(store) &&
this.knownResults.get(result) === selectionSet) {
var latest = this.executeSelectionSet.peek(store, selectionSet, parent, varString);
if (latest && result === latest.result) {
return true;
}
}
return false;
};
StoreReader.prototype.execSelectionSetImpl = function (_a) {
var _this = this;

@@ -90,3 +103,3 @@ var selectionSet = _a.selectionSet, objectOrReference = _a.objectOrReference, context = _a.context;

result: {},
missing: [missingFromInvariant(process.env.NODE_ENV === "production" ? new InvariantError(47) : new InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object"), context)],
missing: [missingFromInvariant(process.env.NODE_ENV === "production" ? new InvariantError(48) : new InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object"), context)],
};

@@ -123,3 +136,3 @@ }

if (!addTypenameToDocument.added(selection)) {
getMissing().push(missingFromInvariant(process.env.NODE_ENV === "production" ? new InvariantError(48) : new InvariantError("Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
getMissing().push(missingFromInvariant(process.env.NODE_ENV === "production" ? new InvariantError(49) : new InvariantError("Can't find field '" + selection.name.value + "' on " + (isReference(objectOrReference)
? objectOrReference.__ref + " object"

@@ -160,3 +173,3 @@ : "object " + JSON.stringify(objectOrReference, null, 2))), context));

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

@@ -172,5 +185,6 @@ if (policies.fragmentMatches(fragment, typename)) {

}
this.knownResults.set(finalResult.result, selectionSet);
return finalResult;
};
StoreReader.prototype.executeSubSelectedArray = function (_a) {
StoreReader.prototype.execSubSelectedArrayImpl = function (_a) {
var _this = this;

@@ -224,3 +238,3 @@ var field = _a.field, array = _a.array, context = _a.context;

if (value && typeof value === "object") {
process.env.NODE_ENV === "production" ? invariant(!isReference(value), 50) : invariant(!isReference(value), "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), 51) : 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);

@@ -227,0 +241,0 @@ }

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

import { NormalizedCache } from './types';
import { StoreReader } from './readFromStore';
export interface WriteContext extends ReadMergeContext {

@@ -15,6 +16,7 @@ readonly store: NormalizedCache;

export interface StoreWriterConfig {
reader?: StoreReader;
policies: Policies;
}
export declare class StoreWriter {
private policies;
private config;
constructor(config: StoreWriterConfig);

@@ -21,0 +23,0 @@ writeQueryToStore({ query, result, dataId, store, variables, }: {

import { __assign } from 'tslib';
import { InvariantError } from 'ts-invariant';
import { createFragmentMap, getFragmentFromSelection } from '../../utilities/graphql/fragments.js';
import { makeReference, getTypenameFromResult, isField, resultKeyNameFromField } from '../../utilities/graphql/storeUtils.js';
import { getTypenameFromResult, isField, resultKeyNameFromField, makeReference } from '../../utilities/graphql/storeUtils.js';
import { getOperationDefinition, getDefaultValues, getFragmentDefinitions } from '../../utilities/graphql/getFromAST.js';

@@ -13,7 +13,7 @@ import { shouldInclude, hasDirectives } from '../../utilities/graphql/directives.js';

function StoreWriter(config) {
this.policies = config.policies;
this.config = config;
}
StoreWriter.prototype.writeQueryToStore = function (_a) {
var query = _a.query, result = _a.result, _b = _a.dataId, dataId = _b === void 0 ? 'ROOT_QUERY' : _b, _c = _a.store, store = _c === void 0 ? new EntityStore.Root({
policies: this.policies,
policies: this.config.policies,
}) : _c, variables = _a.variables;

@@ -23,2 +23,3 @@ var operationDefinition = getOperationDefinition(query);

var merger = makeProcessedFieldsMerger();
variables = __assign(__assign({}, getDefaultValues(operationDefinition)), variables);
this.processSelectionSet({

@@ -28,3 +29,3 @@ result: result || Object.create(null),

selectionSet: operationDefinition.selectionSet,
typename: this.policies.rootTypenamesById[dataId],
typename: this.config.policies.rootTypenamesById[dataId],
context: {

@@ -36,3 +37,4 @@ store: store,

},
variables: __assign(__assign({}, getDefaultValues(operationDefinition)), variables),
variables: variables,
varString: JSON.stringify(variables),
fragmentMap: createFragmentMap(getFragmentDefinitions(query)),

@@ -50,5 +52,5 @@ toReference: store.toReference,

} : _b;
var policies = this.policies;
var _c = this.config, policies = _c.policies, reader = _c.reader;
var mergedFields = Object.create(null);
var _c = policies.identify(result, selectionSet, context.fragmentMap), id = _c[0], keyObject = _c[1];
var _d = policies.identify(result, selectionSet, context.fragmentMap), id = _d[0], keyObject = _d[1];
dataId = dataId || id;

@@ -60,5 +62,9 @@ if (keyObject) {

var sets = context.written[dataId] || (context.written[dataId] = []);
var ref = makeReference(dataId);
if (sets.indexOf(selectionSet) >= 0)
return makeReference(dataId);
return ref;
sets.push(selectionSet);
if (reader && reader.isFresh(result, context.store, ref, selectionSet, context.varString)) {
return ref;
}
}

@@ -96,3 +102,3 @@ typename = typename ||

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

@@ -123,3 +129,3 @@ }

if (Array.isArray(value)) {
return value.map(function (item, i) { return _this.processFieldValue(item, field, context, out); });
return value.map(function (item) { return _this.processFieldValue(item, field, context, out); });
}

@@ -126,0 +132,0 @@ return this.processSelectionSet({

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

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

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

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

});
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new InvariantError(14) : new InvariantError('QueryManager stopped while query was in flight'));
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new InvariantError(15) : new InvariantError('QueryManager stopped while query was in flight'));
};

@@ -64,4 +64,4 @@ QueryManager.prototype.cancelPendingFetches = function (error) {

case 0:
process.env.NODE_ENV === "production" ? invariant(mutation, 15) : 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', 16) : 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, 16) : 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', 17) : 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.generateMutationId();

@@ -276,7 +276,7 @@ mutation = this.transform(mutation).document;

var _this = this;
process.env.NODE_ENV === "production" ? invariant(options.query, 17) : invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
process.env.NODE_ENV === "production" ? invariant(options.query, 18) : 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', 18) : invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.');
process.env.NODE_ENV === "production" ? invariant(!options.returnPartialData, 19) : invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.');
process.env.NODE_ENV === "production" ? invariant(!options.pollInterval, 20) : invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.');
process.env.NODE_ENV === "production" ? invariant(options.query.kind === 'Document', 19) : invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.');
process.env.NODE_ENV === "production" ? invariant(!options.returnPartialData, 20) : invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.');
process.env.NODE_ENV === "production" ? invariant(!options.pollInterval, 21) : invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.');
var queryId = this.generateQueryId();

@@ -307,3 +307,3 @@ return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });

QueryManager.prototype.clearStore = function () {
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new InvariantError(21) : new InvariantError('Store reset while query was in flight (not completed in link chain)'));
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new InvariantError(22) : new InvariantError('Store reset while query was in flight (not completed in link chain)'));
this.queries.forEach(function (queryInfo) {

@@ -310,0 +310,0 @@ if (queryInfo.observableQuery) {

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

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

"graphql-tag": "^2.10.2",
"optimism": "^0.11.5",
"optimism": "^0.12.1",
"symbol-observable": "^1.2.0",

@@ -50,0 +50,0 @@ "ts-invariant": "^0.4.4",

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

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

@@ -52,8 +52,8 @@ else {

var directiveName = directive.name.value;
process.env.NODE_ENV === "production" ? invariant(directiveArguments && directiveArguments.length === 1, 39) : invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
process.env.NODE_ENV === "production" ? invariant(directiveArguments && directiveArguments.length === 1, 42) : 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', 40) : 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', 43) : 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'), 41) : invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 44) : invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");

@@ -60,0 +60,0 @@ result.push({ 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(42) : new InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
throw process.env.NODE_ENV === "production" ? new InvariantError(38) : 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, 43) : 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, 39) : 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, 44) : invariant(fragment, "No fragment named " + selection.name.value + ".");
process.env.NODE_ENV === "production" ? invariant(fragment, 40) : invariant(fragment, "No fragment named " + selection.name.value + ".");
return fragment;

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

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

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

@@ -60,8 +60,8 @@ else {

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

@@ -79,3 +79,3 @@ result.push({ directive: directive, ifArgument: ifArgument });

if (definition.kind === 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(42) : new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(38) : new tsInvariant.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.');

@@ -88,3 +88,3 @@ }

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

@@ -126,3 +126,3 @@ }

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

@@ -129,0 +129,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 too big to display

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