apollo-cache-core
Advanced tools
Comparing version 0.2.0-alpha.7 to 0.2.0-alpha.8
@@ -5,7 +5,9 @@ import { DocumentNode } from 'graphql'; | ||
export declare abstract class ApolloCache implements DataProxy { | ||
abstract read<T>(query: Cache.ReadOptions): Cache.DiffResult<T>; | ||
abstract write(write: Cache.WriteOptions): void; | ||
abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>; | ||
abstract watch(watch: Cache.WatchOptions): () => void; | ||
abstract evict(query: Cache.EvictOptions): Cache.EvictionResult; | ||
abstract getData(): any; | ||
abstract reset(): Promise<void>; | ||
abstract transformDocument(document: DocumentNode): DocumentNode; | ||
abstract diffQuery<T>(query: Cache.DiffQueryOptions): Cache.DiffResult<T>; | ||
abstract read<T>(query: Cache.ReadOptions): Cache.DiffResult<T>; | ||
abstract writeResult(write: Cache.WriteResult): void; | ||
abstract removeOptimistic(id: string): void; | ||
@@ -15,7 +17,7 @@ abstract getOptimisticData(): any; | ||
abstract recordOptimisticTransaction(transaction: Transaction, id: string): void; | ||
abstract watch(watch: Cache.WatchOptions): () => void; | ||
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; | ||
writeQuery(options: Cache.WriteQueryOptions): void; | ||
writeFragment(options: Cache.WriteFragmentOptions): void; | ||
readQuery<QueryType>(options: DataProxy.ReadQueryOptions, optimistic?: boolean): Cache.DiffResult<QueryType>; | ||
readFragment<FragmentType>(options: DataProxy.ReadFragmentOptions, optimistic?: boolean): Cache.DiffResult<FragmentType> | null; | ||
} |
@@ -7,19 +7,5 @@ "use strict"; | ||
} | ||
ApolloCache.prototype.writeQuery = function (options) { | ||
this.writeResult({ | ||
dataId: 'ROOT_QUERY', | ||
result: options.data, | ||
document: options.query, | ||
variables: options.variables, | ||
}); | ||
ApolloCache.prototype.transformDocument = function (document) { | ||
return document; | ||
}; | ||
ApolloCache.prototype.writeFragment = function (options) { | ||
var document = apollo_utilities_1.getFragmentQueryDocument(options.fragment, options.fragmentName); | ||
this.writeResult({ | ||
dataId: options.id, | ||
result: options.data, | ||
document: document, | ||
variables: options.variables, | ||
}); | ||
}; | ||
ApolloCache.prototype.readQuery = function (options, optimistic) { | ||
@@ -35,5 +21,4 @@ if (optimistic === void 0) { optimistic = false; } | ||
if (optimistic === void 0) { optimistic = false; } | ||
var document = apollo_utilities_1.getFragmentQueryDocument(options.fragment, options.fragmentName); | ||
return this.read({ | ||
query: document, | ||
query: apollo_utilities_1.getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
variables: options.variables, | ||
@@ -44,2 +29,18 @@ rootId: options.id, | ||
}; | ||
ApolloCache.prototype.writeQuery = function (options) { | ||
this.write({ | ||
dataId: 'ROOT_QUERY', | ||
result: options.data, | ||
query: options.query, | ||
variables: options.variables, | ||
}); | ||
}; | ||
ApolloCache.prototype.writeFragment = function (options) { | ||
this.write({ | ||
dataId: options.id, | ||
result: options.data, | ||
variables: options.variables, | ||
query: apollo_utilities_1.getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
}); | ||
}; | ||
return ApolloCache; | ||
@@ -46,0 +47,0 @@ }()); |
@@ -1,15 +0,8 @@ | ||
import { DocumentNode } from 'graphql'; | ||
import { DataProxy } from './DataProxy'; | ||
export declare namespace Cache { | ||
interface DiffQueryOptions { | ||
query: DocumentNode; | ||
variables: any; | ||
returnPartialData?: boolean; | ||
previousResult?: any; | ||
optimistic: boolean; | ||
type WatchCallback = (newData: any) => void; | ||
interface EvictionResult { | ||
success: Boolean; | ||
} | ||
export import DiffResult = DataProxy.DiffResult; | ||
interface ReadOptions { | ||
query: DocumentNode; | ||
variables: any; | ||
interface ReadOptions extends DataProxy.Query { | ||
rootId?: string; | ||
@@ -19,20 +12,19 @@ previousResult?: any; | ||
} | ||
export import ReadQueryOptions = DataProxy.ReadQueryOptions; | ||
export import ReadFragmentOptions = DataProxy.ReadFragmentOptions; | ||
interface WriteResult { | ||
interface WriteOptions extends DataProxy.Query { | ||
dataId: string; | ||
result: any; | ||
document: DocumentNode; | ||
variables?: Object; | ||
} | ||
interface DiffOptions extends ReadOptions { | ||
returnPartialData?: boolean; | ||
} | ||
interface WatchOptions extends ReadOptions { | ||
callback: WatchCallback; | ||
} | ||
interface EvictOptions extends DataProxy.Query { | ||
rootId?: string; | ||
} | ||
export import DiffResult = DataProxy.DiffResult; | ||
export import WriteQueryOptions = DataProxy.WriteQueryOptions; | ||
export import WriteFragmentOptions = DataProxy.WriteFragmentOptions; | ||
interface WatchOptions { | ||
query: DocumentNode; | ||
variables: any; | ||
rootId?: string; | ||
previousResult?: any; | ||
optimistic: boolean; | ||
callback: (newData: any) => void; | ||
} | ||
export import Fragment = DataProxy.Fragment; | ||
} |
import { DocumentNode } from 'graphql'; | ||
export declare namespace DataProxy { | ||
interface ReadQueryOptions { | ||
interface Query { | ||
query: DocumentNode; | ||
variables?: Object; | ||
} | ||
interface ReadFragmentOptions { | ||
interface Fragment { | ||
id: string; | ||
@@ -13,24 +13,18 @@ fragment: DocumentNode; | ||
} | ||
interface WriteQueryOptions { | ||
interface WriteQueryOptions extends Query { | ||
data: any; | ||
query: DocumentNode; | ||
variables?: Object; | ||
} | ||
interface WriteFragmentOptions { | ||
interface WriteFragmentOptions extends Fragment { | ||
data: any; | ||
id: string; | ||
fragment: DocumentNode; | ||
fragmentName?: string; | ||
variables?: Object; | ||
} | ||
type DiffResult<T> = { | ||
result?: T; | ||
isMissing?: boolean; | ||
complete?: boolean; | ||
}; | ||
} | ||
export interface DataProxy { | ||
readQuery<QueryType>(options: DataProxy.ReadQueryOptions): DataProxy.DiffResult<QueryType>; | ||
readFragment<FragmentType>(options: DataProxy.ReadFragmentOptions): DataProxy.DiffResult<FragmentType> | null; | ||
readQuery<QueryType>(options: DataProxy.Query, optimistic?: boolean): DataProxy.DiffResult<QueryType>; | ||
readFragment<FragmentType>(options: DataProxy.Fragment, optimistic?: boolean): DataProxy.DiffResult<FragmentType> | null; | ||
writeQuery(options: DataProxy.WriteQueryOptions): void; | ||
writeFragment(options: DataProxy.WriteFragmentOptions): void; | ||
} |
{ | ||
"name": "apollo-cache-core", | ||
"version": "0.2.0-alpha.7", | ||
"version": "0.2.0-alpha.8", | ||
"description": "Core abstract of Caching layer for Apollo Client", | ||
@@ -5,0 +5,0 @@ "author": "James Baxley <james@meteor.com>", |
import { DocumentNode } from 'graphql'; | ||
import { getFragmentQueryDocument } from 'apollo-utilities'; | ||
@@ -10,17 +9,17 @@ | ||
export abstract class ApolloCache implements DataProxy { | ||
// required to implement | ||
// core API | ||
public abstract read<T>(query: Cache.ReadOptions): Cache.DiffResult<T>; | ||
public abstract write(write: Cache.WriteOptions): void; | ||
public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>; | ||
public abstract watch(watch: Cache.WatchOptions): () => void; | ||
public abstract evict(query: Cache.EvictOptions): Cache.EvictionResult; | ||
public abstract getData(): any; | ||
public abstract reset(): Promise<void>; | ||
public abstract transformDocument(document: DocumentNode): DocumentNode; | ||
public abstract diffQuery<T>( | ||
query: Cache.DiffQueryOptions, | ||
): Cache.DiffResult<T>; | ||
public abstract read<T>(query: Cache.ReadOptions): Cache.DiffResult<T>; | ||
public abstract writeResult(write: Cache.WriteResult): void; | ||
// optimistic API | ||
public abstract removeOptimistic(id: string): void; | ||
public abstract getOptimisticData(): any; | ||
// transactional API | ||
public abstract performTransaction(transaction: Transaction): void; | ||
@@ -32,28 +31,9 @@ public abstract recordOptimisticTransaction( | ||
public abstract watch(watch: Cache.WatchOptions): () => void; | ||
public writeQuery(options: Cache.WriteQueryOptions): void { | ||
this.writeResult({ | ||
dataId: 'ROOT_QUERY', | ||
result: options.data, | ||
document: options.query, | ||
variables: options.variables, | ||
}); | ||
// optional API | ||
public transformDocument(document: DocumentNode): DocumentNode { | ||
return document; | ||
} | ||
public writeFragment(options: Cache.WriteFragmentOptions): void { | ||
let document = getFragmentQueryDocument( | ||
options.fragment, | ||
options.fragmentName, | ||
); | ||
this.writeResult({ | ||
dataId: options.id, | ||
result: options.data, | ||
document, | ||
variables: options.variables, | ||
}); | ||
} | ||
public readQuery<QueryType>( | ||
options: DataProxy.ReadQueryOptions, | ||
options: DataProxy.Query, | ||
optimistic: boolean = false, | ||
@@ -69,11 +49,7 @@ ): Cache.DiffResult<QueryType> { | ||
public readFragment<FragmentType>( | ||
options: DataProxy.ReadFragmentOptions, | ||
options: DataProxy.Fragment, | ||
optimistic: boolean = false, | ||
): Cache.DiffResult<FragmentType> | null { | ||
let document = getFragmentQueryDocument( | ||
options.fragment, | ||
options.fragmentName, | ||
); | ||
return this.read({ | ||
query: document, | ||
query: getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
variables: options.variables, | ||
@@ -84,2 +60,20 @@ rootId: options.id, | ||
} | ||
public writeQuery(options: Cache.WriteQueryOptions): void { | ||
this.write({ | ||
dataId: 'ROOT_QUERY', | ||
result: options.data, | ||
query: options.query, | ||
variables: options.variables, | ||
}); | ||
} | ||
public writeFragment(options: Cache.WriteFragmentOptions): void { | ||
this.write({ | ||
dataId: options.id, | ||
result: options.data, | ||
variables: options.variables, | ||
query: getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
}); | ||
} | ||
} |
@@ -1,19 +0,10 @@ | ||
import { DocumentNode } from 'graphql'; // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved | ||
import { DataProxy } from './DataProxy'; | ||
export namespace Cache { | ||
export interface DiffQueryOptions { | ||
query: DocumentNode; | ||
variables: any; | ||
returnPartialData?: boolean; | ||
previousResult?: any; | ||
optimistic: boolean; | ||
export type WatchCallback = (newData: any) => void; | ||
export interface EvictionResult { | ||
success: Boolean; | ||
} | ||
export import DiffResult = DataProxy.DiffResult; | ||
export interface ReadOptions { | ||
query: DocumentNode; | ||
variables: any; | ||
export interface ReadOptions extends DataProxy.Query { | ||
rootId?: string; | ||
@@ -24,25 +15,23 @@ previousResult?: any; | ||
export import ReadQueryOptions = DataProxy.ReadQueryOptions; | ||
export import ReadFragmentOptions = DataProxy.ReadFragmentOptions; | ||
export interface WriteResult { | ||
export interface WriteOptions extends DataProxy.Query { | ||
dataId: string; | ||
result: any; | ||
document: DocumentNode; | ||
variables?: Object; | ||
} | ||
export import WriteQueryOptions = DataProxy.WriteQueryOptions; | ||
export interface DiffOptions extends ReadOptions { | ||
returnPartialData?: boolean; | ||
} | ||
export import WriteFragmentOptions = DataProxy.WriteFragmentOptions; | ||
export interface WatchOptions extends ReadOptions { | ||
callback: WatchCallback; | ||
} | ||
export interface WatchOptions { | ||
query: DocumentNode; | ||
variables: any; | ||
export interface EvictOptions extends DataProxy.Query { | ||
rootId?: string; | ||
previousResult?: any; | ||
optimistic: boolean; | ||
callback: (newData: any) => void; | ||
} | ||
export import DiffResult = DataProxy.DiffResult; | ||
export import WriteQueryOptions = DataProxy.WriteQueryOptions; | ||
export import WriteFragmentOptions = DataProxy.WriteFragmentOptions; | ||
export import Fragment = DataProxy.Fragment; | ||
} |
import { DocumentNode } from 'graphql'; // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved | ||
export namespace DataProxy { | ||
export interface ReadQueryOptions { | ||
export interface Query { | ||
/** | ||
@@ -18,3 +18,3 @@ * The GraphQL query shape to be used constructed using the `gql` template | ||
export interface ReadFragmentOptions { | ||
export interface Fragment { | ||
/** | ||
@@ -48,3 +48,3 @@ * The root id to be used. This id should take the same form as the | ||
export interface WriteQueryOptions { | ||
export interface WriteQueryOptions extends Query { | ||
/** | ||
@@ -54,17 +54,5 @@ * The data you will be writing to the store. | ||
data: any; | ||
/** | ||
* 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 written. | ||
*/ | ||
query: DocumentNode; | ||
/** | ||
* Any variables that the GraphQL query may depend on. | ||
*/ | ||
variables?: Object; | ||
} | ||
export interface WriteFragmentOptions { | ||
export interface WriteFragmentOptions extends Fragment { | ||
/** | ||
@@ -74,28 +62,2 @@ * The data you will be writing to the store. | ||
data: any; | ||
/** | ||
* The root id to be used. This id should take the same form as the value | ||
* returned by your `dataIdFromObject` function. | ||
*/ | ||
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 write. 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?: Object; | ||
} | ||
@@ -105,3 +67,3 @@ | ||
result?: T; | ||
isMissing?: boolean; | ||
complete?: boolean; | ||
}; | ||
@@ -121,3 +83,4 @@ } | ||
readQuery<QueryType>( | ||
options: DataProxy.ReadQueryOptions, | ||
options: DataProxy.Query, | ||
optimistic?: boolean, | ||
): DataProxy.DiffResult<QueryType>; | ||
@@ -131,3 +94,4 @@ | ||
readFragment<FragmentType>( | ||
options: DataProxy.ReadFragmentOptions, | ||
options: DataProxy.Fragment, | ||
optimistic?: boolean, | ||
): DataProxy.DiffResult<FragmentType> | null; | ||
@@ -134,0 +98,0 @@ |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
18328
430