Socket
Socket
Sign inDemoInstall

apollo-cache-inmemory

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-cache-inmemory - npm Package Compare versions

Comparing version 0.2.0-rc.1 to 0.2.0-rc.2

README.md

2

CHANGELOG.md

@@ -5,2 +5,4 @@ # Change log

- `readQuery` and `readFragment` return now the result instead of `Cache.DiffResult` [PR #2320](https://github.com/apollographql/apollo-client/pull/2320)
### 0.2.0-rc.1

@@ -7,0 +9,0 @@ - move to named export to be consistent with rest of apollo ecosystem

6

lib/inMemoryCache.d.ts

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

extract(optimistic?: boolean): NormalizedCache;
read<T>(query: Cache.ReadOptions): Cache.DiffResult<T>;
read<T>(query: Cache.ReadOptions): T;
write(write: Cache.WriteOptions): void;

@@ -25,4 +25,4 @@ diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;

transformDocument(document: DocumentNode): DocumentNode;
readQuery<QueryType>(options: DataProxy.Query, optimistic?: boolean): Cache.DiffResult<QueryType>;
readFragment<FragmentType>(options: DataProxy.Fragment, optimistic?: boolean): Cache.DiffResult<FragmentType> | null;
readQuery<QueryType>(options: DataProxy.Query, optimistic?: boolean): QueryType;
readFragment<FragmentType>(options: DataProxy.Fragment, optimistic?: boolean): FragmentType | null;
writeQuery(options: DataProxy.WriteQueryOptions): void;

@@ -29,0 +29,0 @@ writeFragment(options: DataProxy.WriteFragmentOptions): void;

@@ -5,4 +5,4 @@ import { IdValue } from 'apollo-utilities';

export declare const ID_KEY: string | symbol;
export declare function readQueryFromStore<QueryType>(options: ReadQueryOptions): Cache.DiffResult<QueryType>;
export declare function readQueryFromStore<QueryType>(options: ReadQueryOptions): QueryType;
export declare function diffQueryAgainstStore<T>({store, query, variables, previousResult, returnPartialData, rootId, fragmentMatcherFunction, config}: DiffQueryAgainstStoreOptions): Cache.DiffResult<T>;
export declare function assertIdValue(idValue: IdValue): void;
{
"name": "apollo-cache-inmemory",
"version": "0.2.0-rc.1",
"version": "0.2.0-rc.2",
"description": "Core abstract of Caching layer for Apollo Client",

@@ -38,5 +38,5 @@ "author": "James Baxley <james@meteor.com>",

"dependencies": {
"apollo-cache": "^0.2.0-rc.0",
"apollo-utilities": "^0.2.0-rc.0",
"graphql-anywhere": "^4.0.0-rc.0"
"apollo-cache": "^0.2.0-rc.1",
"apollo-utilities": "^0.2.0-rc.1",
"graphql-anywhere": "^4.0.0-rc.1"
},

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

@@ -39,3 +39,2 @@ import { DataProxy } from 'apollo-cache';

});
expect(

@@ -192,2 +191,29 @@ proxy.readQuery({

});
it('will read some data from the store with null variables', () => {
const proxy = createCache({
initialState: {
apollo: {
data: {
ROOT_QUERY: {
'field({"literal":false,"value":null})': 1,
},
},
},
},
});
expect(
proxy.readQuery({
query: gql`
query($literal: Boolean, $value: Int) {
a: field(literal: $literal, value: $value)
}
`,
variables: {
literal: false,
value: null,
},
}),
).toEqual({ a: 1 });
});
});

@@ -704,2 +730,29 @@

});
it('will write some data to the store with variables where some are null', () => {
const proxy = createCache();
proxy.writeQuery({
data: {
a: 1,
b: 2,
},
query: gql`
query($literal: Boolean, $value: Int) {
a: field(literal: true, value: 42)
b: field(literal: $literal, value: $value)
}
`,
variables: {
literal: false,
value: null,
},
});
expect((proxy as InMemoryCache).extract()).toEqual({
ROOT_QUERY: {
'field({"literal":true,"value":42})': 1,
'field({"literal":false,"value":null})': 2,
},
});
});
});

@@ -995,3 +1048,30 @@

});
it('writes data that can be read back', () => {
const proxy = createCache({
config: { addTypename: true },
});
const readWriteFragment = gql`
fragment aFragment on query {
getSomething {
id
}
}
`;
const data = {
__typename: 'query',
getSomething: { id: '123', __typename: 'Something' },
};
proxy.writeFragment({
data,
id: 'query',
fragment: readWriteFragment,
});
const result = proxy.readFragment({
fragment: readWriteFragment,
id: 'query',
});
expect(result).toEqual(data);
});
it('will write some data to the store with variables', () => {

@@ -998,0 +1078,0 @@ const proxy = createCache({

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

public read<T>(query: Cache.ReadOptions): Cache.DiffResult<T> {
public read<T>(query: Cache.ReadOptions): T {
if (query.rootId && typeof this.data[query.rootId] === 'undefined') {

@@ -185,3 +185,3 @@ return null;

optimistic: boolean = false,
): Cache.DiffResult<QueryType> {
): QueryType {
return this.read({

@@ -197,3 +197,3 @@ query: options.query,

optimistic: boolean = false,
): Cache.DiffResult<FragmentType> | null {
): FragmentType | null {
return this.read({

@@ -200,0 +200,0 @@ query: this.transformDocument(

@@ -49,6 +49,6 @@ import graphqlAnywhere, { Resolver, ExecInfo } from 'graphql-anywhere';

options: ReadQueryOptions,
): Cache.DiffResult<QueryType> {
): QueryType {
const optsPatch = { returnPartialData: false };
return diffQueryAgainstStore({
return diffQueryAgainstStore<QueryType>({
...options,

@@ -55,0 +55,0 @@ ...optsPatch,

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