apollo-cache-inmemory
Advanced tools
Comparing version 1.2.2 to 1.2.3
# CHANGELOG | ||
### 1.2.3 | ||
- Added optional generics to cache manipulation methods (typescript). | ||
[PR #3541](https://github.com/apollographql/apollo-client/pull/3541) | ||
- Restore non-enumerability of `resultFields[ID_KEY]`. | ||
[PR #3544](https://github.com/apollographql/apollo-client/pull/3544) | ||
- Cache query documents transformed by InMemoryCache. | ||
[PR #3553](https://github.com/apollographql/apollo-client/pull/3553) | ||
### 1.2.2 | ||
@@ -4,0 +13,0 @@ |
@@ -717,3 +717,8 @@ (function (global, factory) { | ||
} | ||
resultFields[ID_KEY] = idValue.id; | ||
Object.defineProperty(resultFields, ID_KEY, { | ||
enumerable: false, | ||
configurable: true, | ||
writable: false, | ||
value: idValue.id, | ||
}); | ||
return resultFields; | ||
@@ -838,2 +843,3 @@ } | ||
_this.watches = []; | ||
_this.typenameDocumentCache = new WeakMap(); | ||
// Set this while in a transaction to prevent broadcasts... | ||
@@ -964,4 +970,9 @@ // don't forget to turn it back on! | ||
InMemoryCache.prototype.transformDocument = function (document) { | ||
if (this.addTypename) | ||
return apolloUtilities.addTypenameToDocument(document); | ||
if (this.addTypename) { | ||
var result = this.typenameDocumentCache.get(document); | ||
if (!result) { | ||
this.typenameDocumentCache.set(document, (result = apolloUtilities.addTypenameToDocument(document))); | ||
} | ||
return result; | ||
} | ||
return document; | ||
@@ -968,0 +979,0 @@ }; |
@@ -11,2 +11,3 @@ import { DocumentNode } from 'graphql'; | ||
private addTypename; | ||
private typenameDocumentCache; | ||
private silenceBroadcast; | ||
@@ -26,7 +27,7 @@ constructor(config?: ApolloReducerConfig); | ||
transformDocument(document: DocumentNode): DocumentNode; | ||
readQuery<QueryType>(options: DataProxy.Query, optimistic?: boolean): QueryType; | ||
readFragment<FragmentType>(options: DataProxy.Fragment, optimistic?: boolean): FragmentType | null; | ||
writeQuery(options: DataProxy.WriteQueryOptions): void; | ||
writeFragment(options: DataProxy.WriteFragmentOptions): void; | ||
readQuery<QueryType, TVariables = any>(options: DataProxy.Query<TVariables>, optimistic?: boolean): QueryType; | ||
readFragment<FragmentType, TVariables = any>(options: DataProxy.Fragment<TVariables>, optimistic?: boolean): FragmentType | null; | ||
writeQuery<TData = any, TVariables = any>(options: DataProxy.WriteQueryOptions<TData, TVariables>): void; | ||
writeFragment<TData = any, TVariables = any>(options: DataProxy.WriteFragmentOptions<TData, TVariables>): void; | ||
protected broadcastWatches(): void; | ||
} |
@@ -50,2 +50,3 @@ var __extends = (this && this.__extends) || (function () { | ||
_this.watches = []; | ||
_this.typenameDocumentCache = new WeakMap(); | ||
// Set this while in a transaction to prevent broadcasts... | ||
@@ -176,4 +177,9 @@ // don't forget to turn it back on! | ||
InMemoryCache.prototype.transformDocument = function (document) { | ||
if (this.addTypename) | ||
return addTypenameToDocument(document); | ||
if (this.addTypename) { | ||
var result = this.typenameDocumentCache.get(document); | ||
if (!result) { | ||
this.typenameDocumentCache.set(document, (result = addTypenameToDocument(document))); | ||
} | ||
return result; | ||
} | ||
return document; | ||
@@ -180,0 +186,0 @@ }; |
@@ -225,3 +225,8 @@ var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
} | ||
resultFields[ID_KEY] = idValue.id; | ||
Object.defineProperty(resultFields, ID_KEY, { | ||
enumerable: false, | ||
configurable: true, | ||
writable: false, | ||
value: idValue.id, | ||
}); | ||
return resultFields; | ||
@@ -228,0 +233,0 @@ } |
{ | ||
"name": "apollo-cache-inmemory", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Core abstract of Caching layer for Apollo Client", | ||
@@ -43,5 +43,5 @@ "author": "James Baxley <james@meteor.com>", | ||
"dependencies": { | ||
"apollo-cache": "^1.1.9", | ||
"apollo-utilities": "^1.0.13", | ||
"graphql-anywhere": "^4.1.11" | ||
"apollo-cache": "^1.1.10", | ||
"apollo-utilities": "^1.0.14", | ||
"graphql-anywhere": "^4.1.12" | ||
}, | ||
@@ -48,0 +48,0 @@ "peerDependencies": { |
@@ -150,3 +150,3 @@ import { assign, omit } from 'lodash'; | ||
nullField: null, | ||
'numberField({"intArg":5,"floatArg":3.14})': 5, | ||
'numberField({"floatArg":3.14,"intArg":5})': 5, | ||
'stringField({"arg":"This is a string!"})': 'Heyo', | ||
@@ -224,3 +224,3 @@ }, | ||
nullField: null, | ||
'numberField({"intArg":0,"floatArg":3.14})': 5, | ||
'numberField({"floatArg":3.14,"intArg":0})': 5, | ||
'stringField({"arg":"This is a default string!"})': 'Heyo', | ||
@@ -227,0 +227,0 @@ }, |
@@ -176,3 +176,3 @@ import { cloneDeep, assign, omit } from 'lodash'; | ||
nullField: null, | ||
'numberField({"intArg":5,"floatArg":3.14})': 5, | ||
'numberField({"floatArg":3.14,"intArg":5})': 5, | ||
'stringField({"arg":"This is a string!"})': 'Heyo', | ||
@@ -219,3 +219,3 @@ }, | ||
nullField: null, | ||
'numberField({"intArg":5,"floatArg":3.14})': 5, | ||
'numberField({"floatArg":3.14,"intArg":5})': 5, | ||
'stringField({"arg":"This is a default string!"})': 'Heyo', | ||
@@ -1193,13 +1193,13 @@ }, | ||
'5': { | ||
'some_mutation({"input":{"id":"5","arr":[1,{"a":"b"}],"obj":{"a":"b"},"num":5.5,"nil":null,"bo":true}})': { | ||
id: 'id', | ||
'some_mutation({"input":{"arr":[1,{"a":"b"}],"bo":true,"id":"5","nil":null,"num":5.5,"obj":{"a":"b"}}})': { | ||
generated: false, | ||
id: '5', | ||
type: 'id', | ||
}, | ||
'some_mutation_with_variables({"input":{"arr":[1,{"a":"b"}],"bo":true,"id":"5","nil":null,"num":5.5,"obj":{"a":"b"}}})': { | ||
generated: false, | ||
id: '5', | ||
generated: false, | ||
}, | ||
'some_mutation_with_variables({"input":{"id":"5","arr":[1,{"a":"b"}],"obj":{"a":"b"},"num":5.5,"nil":null,"bo":true}})': { | ||
type: 'id', | ||
id: '5', | ||
generated: false, | ||
}, | ||
id: 'id', | ||
}, | ||
@@ -1206,0 +1206,0 @@ }); |
@@ -46,2 +46,3 @@ import { DocumentNode } from 'graphql'; | ||
private addTypename: boolean; | ||
private typenameDocumentCache = new WeakMap<DocumentNode, DocumentNode>(); | ||
@@ -208,8 +209,17 @@ // Set this while in a transaction to prevent broadcasts... | ||
public transformDocument(document: DocumentNode): DocumentNode { | ||
if (this.addTypename) return addTypenameToDocument(document); | ||
if (this.addTypename) { | ||
let result = this.typenameDocumentCache.get(document); | ||
if (!result) { | ||
this.typenameDocumentCache.set( | ||
document, | ||
(result = addTypenameToDocument(document)), | ||
); | ||
} | ||
return result; | ||
} | ||
return document; | ||
} | ||
public readQuery<QueryType>( | ||
options: DataProxy.Query, | ||
public readQuery<QueryType, TVariables = any>( | ||
options: DataProxy.Query<TVariables>, | ||
optimistic: boolean = false, | ||
@@ -224,4 +234,4 @@ ): QueryType { | ||
public readFragment<FragmentType>( | ||
options: DataProxy.Fragment, | ||
public readFragment<FragmentType, TVariables = any>( | ||
options: DataProxy.Fragment<TVariables>, | ||
optimistic: boolean = false, | ||
@@ -239,3 +249,5 @@ ): FragmentType | null { | ||
public writeQuery(options: DataProxy.WriteQueryOptions): void { | ||
public writeQuery<TData = any, TVariables = any>( | ||
options: DataProxy.WriteQueryOptions<TData, TVariables>, | ||
): void { | ||
this.write({ | ||
@@ -249,3 +261,5 @@ dataId: 'ROOT_QUERY', | ||
public writeFragment(options: DataProxy.WriteFragmentOptions): void { | ||
public writeFragment<TData = any, TVariables = any>( | ||
options: DataProxy.WriteFragmentOptions<TData, TVariables>, | ||
): void { | ||
this.write({ | ||
@@ -252,0 +266,0 @@ dataId: options.id, |
@@ -318,3 +318,8 @@ import graphqlAnywhere, { Resolver, ExecInfo } from 'graphql-anywhere'; | ||
resultFields[ID_KEY] = idValue.id; | ||
Object.defineProperty(resultFields, ID_KEY, { | ||
enumerable: false, | ||
configurable: true, | ||
writable: false, | ||
value: idValue.id, | ||
}); | ||
@@ -321,0 +326,0 @@ return resultFields; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
427314
9346
Updatedapollo-cache@^1.1.10
Updatedapollo-utilities@^1.0.14
Updatedgraphql-anywhere@^4.1.12