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.5 to 1.1.6

1

CHANGELOG.md
### vNext
- Improve code coverage
- Map coverage to original source

@@ -4,0 +5,0 @@

2

lib/bundle.umd.js

@@ -158,3 +158,3 @@ (function (global, factory) {

var id = _a.id, data = _a.data;
if (id) {
if (typeof id !== 'undefined') {
var typenameResult = null;

@@ -161,0 +161,0 @@ try {

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

var id = _a.id, data = _a.data;
if (id) {
if (typeof id !== 'undefined') {
var typenameResult = null;

@@ -58,0 +58,0 @@ try {

{
"name": "apollo-cache",
"version": "1.1.5",
"version": "1.1.6",
"description": "Core abstract of Caching layer for Apollo Client",

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

"dependencies": {
"apollo-utilities": "^1.0.9"
"apollo-utilities": "^1.0.10"
},

@@ -44,0 +44,0 @@ "devDependencies": {

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

import gql from 'graphql-tag';
import { ApolloCache as Cache } from '../cache';

@@ -6,9 +8,143 @@

describe('abstract cache', () => {
it('implements readQuery which by default runs the read method', () => {
const test = new TestCache();
test.read = jest.fn();
describe('transformDocument', () => {
it('returns the document', () => {
const test = new TestCache();
expect(test.transformDocument('a')).toBe('a');
});
});
test.readQuery({});
expect(test.read).toBeCalled();
describe('transformForLink', () => {
it('returns the document', () => {
const test = new TestCache();
expect(test.transformForLink('a')).toBe('a');
});
});
describe('readQuery', () => {
it('runs the read method', () => {
const test = new TestCache();
test.read = jest.fn();
test.readQuery({});
expect(test.read).toBeCalled();
});
it('defaults optimistic to false', () => {
const test = new TestCache();
test.read = ({ optimistic }) => optimistic;
expect(test.readQuery({})).toBe(false);
expect(test.readQuery({}, true)).toBe(true);
});
});
describe('readFragment', () => {
it('runs the read method', () => {
const test = new TestCache();
test.read = jest.fn();
const fragment = {
id: 'frag',
fragment: gql`
fragment a on b {
name
}
`,
};
test.readFragment(fragment);
expect(test.read).toBeCalled();
});
it('defaults optimistic to false', () => {
const test = new TestCache();
test.read = ({ optimistic }) => optimistic;
const fragment = {
id: 'frag',
fragment: gql`
fragment a on b {
name
}
`,
};
expect(test.readFragment(fragment)).toBe(false);
expect(test.readFragment(fragment, true)).toBe(true);
});
});
describe('writeQuery', () => {
it('runs the write method', () => {
const test = new TestCache();
test.write = jest.fn();
test.writeQuery({});
expect(test.write).toBeCalled();
});
});
describe('writeFragment', () => {
it('runs the write method', () => {
const test = new TestCache();
test.write = jest.fn();
const fragment = {
id: 'frag',
fragment: gql`
fragment a on b {
name
}
`,
};
test.writeFragment(fragment);
expect(test.write).toBeCalled();
});
});
describe('writeData', () => {
it('either writes a fragment or a query', () => {
const test = new TestCache();
test.read = jest.fn();
test.writeFragment = jest.fn();
test.writeQuery = jest.fn();
test.writeData({});
expect(test.writeQuery).toBeCalled();
test.writeData({ id: 1 });
expect(test.read).toBeCalled();
expect(test.writeFragment).toBeCalled();
// Edge case for falsey id
test.writeData({ id: 0 });
expect(test.read).toHaveBeenCalledTimes(2);
expect(test.writeFragment).toHaveBeenCalledTimes(2);
});
it('suppresses read errors', () => {
const test = new TestCache();
test.read = () => {
throw new Error();
};
test.writeFragment = jest.fn();
expect(() => test.writeData({ id: 1 })).not.toThrow();
expect(test.writeFragment).toBeCalled();
});
it('reads __typename from typenameResult or defaults to __ClientData', () => {
const test = new TestCache();
test.read = () => ({ __typename: 'a' });
let res;
test.writeFragment = obj =>
(res = obj.fragment.definitions[0].typeCondition.name.value);
test.writeData({ id: 1 });
expect(res).toBe('a');
test.read = () => ({});
test.writeData({ id: 1 });
expect(res).toBe('__ClientData');
});
});
});

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

public writeData({ id, data }: Cache.WriteDataOptions): void {
if (id) {
if (typeof id !== 'undefined') {
let typenameResult = null;

@@ -108,0 +108,0 @@ // Since we can't use fragments without having a typename in the store,

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