Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-cache

Package Overview
Dependencies
Maintainers
4
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-cache - npm Package Compare versions

Comparing version 1.1.6 to 1.1.7

2

CHANGELOG.md
### vNext
## 1.1.6
- Improve code coverage

@@ -4,0 +6,0 @@ - Map coverage to original source

@@ -51,7 +51,10 @@ (function (global, factory) {

obj === null) {
// No selection set here
return null;
}
if (Array.isArray(obj)) {
// GraphQL queries don't include arrays
return selectionSetFromObj(obj[0]);
}
// Now we know it's an object
var selections = [];

@@ -66,2 +69,3 @@ Object.keys(obj).forEach(function (key) {

};
// Recurse
var nestedSelSet = selectionSetFromObj(obj[key]);

@@ -116,11 +120,19 @@ if (nestedSelSet) {

};
var ApolloCache = (function () {
var ApolloCache = /** @class */ (function () {
function ApolloCache() {
}
// optional API
ApolloCache.prototype.transformDocument = function (document) {
return document;
};
// experimental
ApolloCache.prototype.transformForLink = function (document) {
return document;
};
// DataProxy API
/**
*
* @param options
* @param optimistic
*/
ApolloCache.prototype.readQuery = function (options, optimistic) {

@@ -163,2 +175,6 @@ if (optimistic === void 0) { optimistic = false; }

var typenameResult = null;
// Since we can't use fragments without having a typename in the store,
// we need to make sure we have one.
// To avoid overwriting an existing typename, we need to read it out first
// and generate a fake one if none exists.
try {

@@ -172,4 +188,7 @@ typenameResult = this.read({

catch (e) {
// Do nothing, since an error just means no typename exists
}
// tslint:disable-next-line
var __typename = (typenameResult && typenameResult.__typename) || '__ClientData';
// Add a type here to satisfy the inmemory cache
var dataToWrite = __assign({ __typename: __typename }, data);

@@ -176,0 +195,0 @@ this.writeFragment({

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

abstract reset(): Promise<void>;
/**
* Replaces existing state in the cache (if any) with the values expressed by
* `serializedState`.
*
* Called when hydrating a cache (server side rendering, or offline storage),
* and also (potentially) during hot reloads.
*/
abstract restore(serializedState: TSerialized): ApolloCache<TSerialized>;
/**
* Exposes the cache's complete state, in a serializable format for later restoration.
*/
abstract extract(optimistic?: boolean): TSerialized;

@@ -19,2 +29,7 @@ abstract removeOptimistic(id: string): void;

transformForLink(document: DocumentNode): DocumentNode;
/**
*
* @param options
* @param optimistic
*/
readQuery<QueryType>(options: DataProxy.Query, optimistic?: boolean): QueryType | null;

@@ -21,0 +36,0 @@ readFragment<FragmentType>(options: DataProxy.Fragment, optimistic?: boolean): FragmentType | null;

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

import { justTypenameQuery, queryFromPojo, fragmentFromPojo } from './utils';
var ApolloCache = (function () {
var ApolloCache = /** @class */ (function () {
function ApolloCache() {
}
// optional API
ApolloCache.prototype.transformDocument = function (document) {
return document;
};
// experimental
ApolloCache.prototype.transformForLink = function (document) {
return document;
};
// DataProxy API
/**
*
* @param options
* @param optimistic
*/
ApolloCache.prototype.readQuery = function (options, optimistic) {

@@ -58,2 +66,6 @@ if (optimistic === void 0) { optimistic = false; }

var typenameResult = null;
// Since we can't use fragments without having a typename in the store,
// we need to make sure we have one.
// To avoid overwriting an existing typename, we need to read it out first
// and generate a fake one if none exists.
try {

@@ -67,4 +79,7 @@ typenameResult = this.read({

catch (e) {
// Do nothing, since an error just means no typename exists
}
// tslint:disable-next-line
var __typename = (typenameResult && typenameResult.__typename) || '__ClientData';
// Add a type here to satisfy the inmemory cache
var dataToWrite = __assign({ __typename: __typename }, data);

@@ -71,0 +86,0 @@ this.writeFragment({

import { DocumentNode } from 'graphql';
export declare namespace DataProxy {
interface Query {
/**
* The GraphQL query shape to be used constructed using the `gql` template
* string tag from `graphql-tag`. The query will be used to determine the
* shape of the data to be read.
*/
query: DocumentNode;
/**
* Any variables that the GraphQL query may depend on.
*/
variables?: any;
}
interface Fragment {
/**
* The root id to be used. This id should take the same form as the
* value returned by your `dataIdFromObject` function. If a value with your
* id does not exist in the store, `null` will be returned.
*/
id: string;
/**
* A GraphQL document created using the `gql` template string tag from
* `graphql-tag` with one or more fragments which will be used to determine
* the shape of data to read. If you provide more then one fragment in this
* document then you must also specify `fragmentName` to select a single.
*/
fragment: DocumentNode;
/**
* The name of the fragment in your GraphQL document to be used. If you do
* not provide a `fragmentName` and there is only one fragment in your
* `fragment` document then that fragment will be used.
*/
fragmentName?: string;
/**
* Any variables that your GraphQL fragments depend on.
*/
variables?: any;
}
interface WriteQueryOptions extends Query {
/**
* The data you will be writing to the store.
*/
data: any;
}
interface WriteFragmentOptions extends Fragment {
/**
* The data you will be writing to the store.
*/
data: any;
}
interface WriteDataOptions {
/**
* The data you will be writing to the store.
* It also takes an optional id property.
* The id is used to write a fragment to an existing object in the store.
*/
data: any;

@@ -28,8 +66,36 @@ id?: string;

}
/**
* A proxy to the normalized data living in our store. This interface allows a
* user to read and write denormalized data which feels natural to the user
* whilst in the background this data is being converted into the normalized
* store format.
*/
export interface DataProxy {
/**
* Reads a GraphQL query from the root query id.
*/
readQuery<QueryType>(options: DataProxy.Query, optimistic?: boolean): QueryType | null;
/**
* Reads a GraphQL fragment from any arbitrary id. If there are more then
* one fragments in the provided document then a `fragmentName` must be
* provided to select the correct fragment.
*/
readFragment<FragmentType>(options: DataProxy.Fragment, optimistic?: boolean): FragmentType | null;
/**
* Writes a GraphQL query to the root query id.
*/
writeQuery(options: DataProxy.WriteQueryOptions): void;
/**
* Writes a GraphQL fragment to any arbitrary id. If there are more then
* one fragments in the provided document then a `fragmentName` must be
* provided to select the correct fragment.
*/
writeFragment(options: DataProxy.WriteFragmentOptions): void;
/**
* Sugar for writeQuery & writeFragment.
* Writes data to the store without passing in a query.
* If you supply an id, the data will be written as a fragment to an existing object.
* Otherwise, the data is written to the root of the store.
*/
writeData(options: DataProxy.WriteDataOptions): void;
}

@@ -45,7 +45,10 @@ export function queryFromPojo(obj) {

obj === null) {
// No selection set here
return null;
}
if (Array.isArray(obj)) {
// GraphQL queries don't include arrays
return selectionSetFromObj(obj[0]);
}
// Now we know it's an object
var selections = [];

@@ -60,2 +63,3 @@ Object.keys(obj).forEach(function (key) {

};
// Recurse
var nestedSelSet = selectionSetFromObj(obj[key]);

@@ -62,0 +66,0 @@ if (nestedSelSet) {

13

package.json
{
"name": "apollo-cache",
"version": "1.1.6",
"version": "1.1.7",
"description": "Core abstract of Caching layer for Apollo Client",

@@ -41,9 +41,9 @@ "author": "James Baxley <james@meteor.com>",

"dependencies": {
"apollo-utilities": "^1.0.10"
"apollo-utilities": "^1.0.11"
},
"devDependencies": {
"@types/graphql": "0.12.4",
"@types/graphql": "0.12.5",
"@types/jest": "21.1.10",
"browserify": "15.2.0",
"graphql": "0.13.1",
"graphql": "0.13.2",
"graphql-tag": "2.8.0",

@@ -53,3 +53,3 @@ "jest": "20.0.4",

"rollup": "0.56.4",
"rollup-plugin-node-resolve": "3.0.2",
"rollup-plugin-node-resolve": "3.3.0",
"ts-jest": "20.0.14",

@@ -70,5 +70,4 @@ "tslint": "5.9.1",

"json"
],
"mapCoverage": true
]
}
}

@@ -5,7 +5,4 @@ import resolve from 'rollup-plugin-node-resolve';

export default Object.assign(
{
plugins: [resolve()],
},
build('apollo.cache.core'),
);
export default build('apollo.cache.core', {
plugins: [resolve()],
});

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