apollo-cache
Advanced tools
Comparing version 1.1.15 to 1.1.16
@@ -51,10 +51,7 @@ (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 = []; | ||
@@ -69,3 +66,2 @@ Object.keys(obj).forEach(function (key) { | ||
}; | ||
// Recurse | ||
var nestedSelSet = selectionSetFromObj(obj[key]); | ||
@@ -112,19 +108,11 @@ if (nestedSelSet) { | ||
var ApolloCache = /** @class */ (function () { | ||
var ApolloCache = (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) { | ||
@@ -167,6 +155,2 @@ 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 { | ||
@@ -180,7 +164,4 @@ 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 = Object.assign({ __typename: __typename }, data); | ||
@@ -187,0 +168,0 @@ this.writeFragment({ |
@@ -11,13 +11,3 @@ 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; | ||
@@ -29,7 +19,2 @@ abstract removeOptimistic(id: string): void; | ||
transformForLink(document: DocumentNode): DocumentNode; | ||
/** | ||
* | ||
* @param options | ||
* @param optimistic | ||
*/ | ||
readQuery<QueryType, TVariables = any>(options: DataProxy.Query<TVariables>, optimistic?: boolean): QueryType | null; | ||
@@ -41,1 +26,2 @@ readFragment<FragmentType, TVariables = any>(options: DataProxy.Fragment<TVariables>, optimistic?: boolean): FragmentType | null; | ||
} | ||
//# sourceMappingURL=cache.d.ts.map |
import { getFragmentQueryDocument } from 'apollo-utilities'; | ||
import { justTypenameQuery, queryFromPojo, fragmentFromPojo } from './utils'; | ||
var ApolloCache = /** @class */ (function () { | ||
var ApolloCache = (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) { | ||
@@ -57,6 +49,2 @@ 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 { | ||
@@ -70,7 +58,4 @@ 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 = Object.assign({ __typename: __typename }, data); | ||
@@ -77,0 +62,0 @@ this.writeFragment({ |
export * from './cache'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -31,1 +31,2 @@ import { DataProxy } from './DataProxy'; | ||
} | ||
//# sourceMappingURL=Cache.d.ts.map |
import { DocumentNode } from 'graphql'; | ||
export declare namespace DataProxy { | ||
interface Query<TVariables> { | ||
/** | ||
* 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?: TVariables; | ||
} | ||
interface Fragment<TVariables> { | ||
/** | ||
* 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?: TVariables; | ||
} | ||
interface WriteQueryOptions<TData, TVariables> extends Query<TVariables> { | ||
/** | ||
* The data you will be writing to the store. | ||
*/ | ||
data: TData; | ||
} | ||
interface WriteFragmentOptions<TData, TVariables> extends Fragment<TVariables> { | ||
/** | ||
* The data you will be writing to the store. | ||
*/ | ||
data: TData; | ||
} | ||
interface WriteDataOptions<TData> { | ||
/** | ||
* 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: TData; | ||
@@ -66,36 +28,9 @@ 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, TVariables = any>(options: DataProxy.Query<TVariables>, 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, TVariables = any>(options: DataProxy.Fragment<TVariables>, optimistic?: boolean): FragmentType | null; | ||
/** | ||
* Writes a GraphQL query to the root query id. | ||
*/ | ||
writeQuery<TData = any, TVariables = any>(options: DataProxy.WriteQueryOptions<TData, TVariables>): 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<TData = any, TVariables = any>(options: DataProxy.WriteFragmentOptions<TData, TVariables>): 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<TData = any>(options: DataProxy.WriteDataOptions<TData>): void; | ||
} | ||
//# sourceMappingURL=DataProxy.d.ts.map |
export * from './DataProxy'; | ||
export * from './Cache'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,1 +5,2 @@ import { DocumentNode } from 'graphql'; | ||
export declare const justTypenameQuery: DocumentNode; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -45,10 +45,7 @@ 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 = []; | ||
@@ -63,3 +60,2 @@ Object.keys(obj).forEach(function (key) { | ||
}; | ||
// Recurse | ||
var nestedSelSet = selectionSetFromObj(obj[key]); | ||
@@ -66,0 +62,0 @@ if (nestedSelSet) { |
{ | ||
"name": "apollo-cache", | ||
"version": "1.1.15", | ||
"version": "1.1.16", | ||
"description": "Core abstract of Caching layer for Apollo Client", | ||
@@ -27,34 +27,19 @@ "author": "James Baxley <james@meteor.com>", | ||
"scripts": { | ||
"prepare": "npm run lint && npm run build", | ||
"coverage": "jest --coverage", | ||
"test": "jest", | ||
"lint": "tslint --type-check -p tsconfig.json src/*.ts && tslint --type-check -p tsconfig.json tests/*.ts", | ||
"lint": "tslint -c \"../../config/tslint.json\" -p tsconfig.json src/*.ts && tslint -c \"../../config/tslint.json\" -p tsconfig.json tests/*.ts", | ||
"prebuild": "npm run clean", | ||
"build": "tsc -p .", | ||
"postbuild": "npm run bundle", | ||
"bundle": "rollup -c rollup.config.js", | ||
"bundle": "../../node_modules/rollup/bin/rollup -c rollup.config.js", | ||
"watch": "tsc -w -p .", | ||
"clean": "rimraf coverage/* && rimraf lib/*", | ||
"clean": "rm -rf coverage/* && rm -rf lib/*", | ||
"prepublishOnly": "npm run clean && npm run build", | ||
"build:browser": "browserify ./lib/bundle.umd.js --i apollo-utilities -o=./lib/bundle.js && npm run minify:browser", | ||
"minify:browser": "uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.js", | ||
"filesize": "npm run build && npm run build:browser" | ||
"minify": "../../node_modules/uglify-js/bin/uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.umd.js", | ||
"filesize": "npm run minify" | ||
}, | ||
"dependencies": { | ||
"apollo-utilities": "^1.0.19" | ||
"apollo-utilities": "^1.0.20" | ||
}, | ||
"devDependencies": { | ||
"@types/graphql": "0.12.7", | ||
"@types/jest": "23.3.1", | ||
"browserify": "15.2.0", | ||
"graphql": "0.13.2", | ||
"graphql-tag": "2.9.2", | ||
"jest": "23.5.0", | ||
"rimraf": "2.6.2", | ||
"rollup": "0.64.1", | ||
"rollup-plugin-node-resolve": "3.3.0", | ||
"ts-jest": "23.1.3", | ||
"tslint": "5.11.0", | ||
"typescript": "3.0.1", | ||
"uglify-js": "3.4.7" | ||
}, | ||
"jest": { | ||
@@ -72,3 +57,4 @@ "transform": { | ||
"testURL": "http://localhost" | ||
} | ||
}, | ||
"gitHead": "40cccc16db43e190f341794f74e495bd8e390a82" | ||
} |
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
61213
0
38
1038
Updatedapollo-utilities@^1.0.20