@apollo/client
Advanced tools
Comparing version 3.0.0-beta.24 to 3.0.0-beta.25
@@ -20,2 +20,3 @@ import { DocumentNode } from 'graphql'; | ||
readQuery<QueryType, TVariables = any>(options: DataProxy.Query<TVariables>, optimistic?: boolean): QueryType | null; | ||
private getFragmentDoc; | ||
readFragment<FragmentType, TVariables = any>(options: DataProxy.Fragment<TVariables>, optimistic?: boolean): FragmentType | null; | ||
@@ -22,0 +23,0 @@ writeQuery<TData = any, TVariables = any>(options: Cache.WriteQueryOptions<TData, TVariables>): void; |
@@ -1,9 +0,25 @@ | ||
import { __makeTemplateObject } from 'tslib'; | ||
import { getFragmentQueryDocument } from '../../utilities/graphql/fragments.js'; | ||
import { wrap } from 'optimism'; | ||
import { fragmentFromPojo, queryFromPojo } from './utils.js'; | ||
import gql from 'graphql-tag'; | ||
var justTypenameQuery = gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["query { __typename }"], ["query { __typename }"]))); | ||
var justTypenameQuery = { | ||
kind: "Document", | ||
definitions: [{ | ||
kind: "OperationDefinition", | ||
operation: "query", | ||
selectionSet: { | ||
kind: "SelectionSet", | ||
selections: [{ | ||
kind: "Field", | ||
name: { | ||
kind: "Name", | ||
value: "__typename", | ||
}, | ||
}], | ||
}, | ||
}], | ||
}; | ||
var ApolloCache = (function () { | ||
function ApolloCache() { | ||
this.getFragmentDoc = wrap(getFragmentQueryDocument); | ||
} | ||
@@ -27,3 +43,3 @@ ApolloCache.prototype.transformDocument = function (document) { | ||
return this.read({ | ||
query: getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
query: this.getFragmentDoc(options.fragment, options.fragmentName), | ||
variables: options.variables, | ||
@@ -47,3 +63,3 @@ rootId: options.id, | ||
variables: options.variables, | ||
query: getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
query: this.getFragmentDoc(options.fragment, options.fragmentName), | ||
}); | ||
@@ -78,5 +94,4 @@ }; | ||
}()); | ||
var templateObject_1; | ||
export { ApolloCache }; | ||
//# sourceMappingURL=cache.js.map |
@@ -5,5 +5,5 @@ export { Transaction, ApolloCache } from './core/cache'; | ||
export { Reference, isReference, makeReference, } from '../utilities/graphql/storeUtils'; | ||
export { InMemoryCache, InMemoryCacheConfig, } from './inmemory/inMemoryCache'; | ||
export { defaultDataIdFromObject } from './inmemory/policies'; | ||
export { InMemoryCache, InMemoryCacheConfig, LocalVar, } from './inmemory/inMemoryCache'; | ||
export { defaultDataIdFromObject, TypePolicies, TypePolicy, FieldPolicy, FieldReadFunction, FieldMergeFunction, PossibleTypesMap, } from './inmemory/policies'; | ||
export * from './inmemory/types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,3 +5,3 @@ export { ApolloCache } from './core/cache'; | ||
export { InMemoryCache, } from './inmemory/inMemoryCache'; | ||
export { defaultDataIdFromObject } from './inmemory/policies'; | ||
export { defaultDataIdFromObject, } from './inmemory/policies'; | ||
//# sourceMappingURL=index.js.map |
@@ -10,5 +10,5 @@ import { KeyTrie } from 'optimism'; | ||
toObject(): NormalizedCacheObject; | ||
has(dataId: string, fieldName?: string): boolean; | ||
get(dataId: string): StoreObject; | ||
has(dataId: string): boolean; | ||
get(dataId: string, fieldName: string): StoreValue; | ||
private lookup; | ||
merge(dataId: string, incoming: StoreObject): void; | ||
@@ -32,4 +32,4 @@ delete(dataId: string, fieldName?: string): boolean; | ||
constructor(caching: boolean); | ||
depend(dataId: string, storeFieldName?: string): void; | ||
dirty(dataId: string, storeFieldName?: string): void; | ||
depend(dataId: string, storeFieldName: string): void; | ||
dirty(dataId: string, storeFieldName: string): void; | ||
readonly keyMaker: KeyTrie<object>; | ||
@@ -36,0 +36,0 @@ } |
@@ -20,4 +20,4 @@ import { __assign, __extends } from 'tslib'; | ||
}; | ||
EntityStore.prototype.has = function (dataId, fieldName) { | ||
return this.get(dataId, fieldName) !== void 0; | ||
EntityStore.prototype.has = function (dataId) { | ||
return this.lookup(dataId, true) !== void 0; | ||
}; | ||
@@ -28,4 +28,2 @@ EntityStore.prototype.get = function (dataId, fieldName) { | ||
var storeObject = this.data[dataId]; | ||
if (!fieldName) | ||
return storeObject; | ||
if (storeObject && hasOwn.call(storeObject, fieldName)) { | ||
@@ -39,7 +37,12 @@ return storeObject[fieldName]; | ||
}; | ||
EntityStore.prototype.lookup = function (dataId, dependOnExistence) { | ||
if (dependOnExistence) | ||
this.group.depend(dataId, "__exists"); | ||
return hasOwn.call(this.data, dataId) ? this.data[dataId] : | ||
this instanceof Layer ? this.parent.lookup(dataId, dependOnExistence) : void 0; | ||
}; | ||
EntityStore.prototype.merge = function (dataId, incoming) { | ||
var _this = this; | ||
var existing = this.get(dataId); | ||
var merged = new DeepMerger(storeObjectReconciler) | ||
.merge(existing, incoming, this); | ||
var existing = this.lookup(dataId); | ||
var merged = new DeepMerger(storeObjectReconciler).merge(existing, incoming, this); | ||
if (merged !== existing) { | ||
@@ -49,3 +52,4 @@ this.data[dataId] = merged; | ||
if (this.group.caching) { | ||
this.group.dirty(dataId); | ||
if (!existing) | ||
this.group.dirty(dataId, "__exists"); | ||
Object.keys(incoming).forEach(function (storeFieldName) { | ||
@@ -61,13 +65,8 @@ if (!existing || incoming[storeFieldName] !== existing[storeFieldName]) { | ||
var _this = this; | ||
var storeObject = this.get(dataId); | ||
var storeObject = this.lookup(dataId); | ||
if (storeObject) { | ||
fieldName = fieldName && fieldNameFromStoreName(fieldName); | ||
var storeNamesToDelete_1 = []; | ||
Object.keys(storeObject).forEach(function (storeFieldName) { | ||
if (storeObject[storeFieldName] !== void 0 && | ||
(!fieldName || fieldName === fieldNameFromStoreName(storeFieldName))) { | ||
storeNamesToDelete_1.push(storeFieldName); | ||
} | ||
}); | ||
if (storeNamesToDelete_1.length) { | ||
var storeNamesToDelete = Object.keys(storeObject).filter(function (storeFieldName) { return storeObject[storeFieldName] !== void 0 && | ||
(!fieldName || fieldName === fieldNameFromStoreName(storeFieldName)); }); | ||
if (storeNamesToDelete.length) { | ||
var canDelete_1 = this instanceof EntityStore.Root; | ||
@@ -83,20 +82,19 @@ var remove_1 = function (obj, key) { | ||
delete this.refs[dataId]; | ||
var fieldsToDirty_1 = Object.create(null); | ||
var fieldsToDirty_1 = new Set(); | ||
if (fieldName) { | ||
var cleaned_1 = this.data[dataId] = __assign({}, storeObject); | ||
storeNamesToDelete_1.forEach(function (storeFieldName) { | ||
storeNamesToDelete.forEach(function (storeFieldName) { | ||
remove_1(cleaned_1, storeFieldName); | ||
}); | ||
fieldsToDirty_1[fieldName] = true; | ||
fieldsToDirty_1.add(fieldName); | ||
} | ||
else { | ||
remove_1(this.data, dataId); | ||
storeNamesToDelete_1.forEach(function (storeFieldName) { | ||
var fieldName = fieldNameFromStoreName(storeFieldName); | ||
fieldsToDirty_1[fieldName] = true; | ||
storeNamesToDelete.forEach(function (storeFieldName) { | ||
fieldsToDirty_1.add(fieldNameFromStoreName(storeFieldName)); | ||
}); | ||
fieldsToDirty_1.add("__exists"); | ||
} | ||
if (this.group.caching) { | ||
this.group.dirty(dataId); | ||
Object.keys(fieldsToDirty_1).forEach(function (fieldName) { | ||
fieldsToDirty_1.forEach(function (fieldName) { | ||
_this.group.dirty(dataId, fieldName); | ||
@@ -219,7 +217,3 @@ }); | ||
function makeDepKey(dataId, storeFieldName) { | ||
var parts = [dataId]; | ||
if (typeof storeFieldName === "string") { | ||
parts.push(fieldNameFromStoreName(storeFieldName)); | ||
} | ||
return JSON.stringify(parts); | ||
return JSON.stringify([dataId, fieldNameFromStoreName(storeFieldName)]); | ||
} | ||
@@ -226,0 +220,0 @@ (function (EntityStore) { |
import { __extends, __assign } from 'tslib'; | ||
import { addTypenameToDocument } from '../../utilities/graphql/transform.js'; | ||
import { wrap, dep } from 'optimism'; | ||
import { ApolloCache } from '../core/cache.js'; | ||
import './fixPolyfills.js'; | ||
import { wrap, dep } from 'optimism'; | ||
import { EntityStore, supportsResultCaching } from './entityStore.js'; | ||
@@ -68,8 +68,8 @@ import { StoreReader } from './readFromStore.js'; | ||
InMemoryCache.prototype.read = function (options) { | ||
if (typeof options.rootId === 'string' && | ||
!this.data.has(options.rootId)) { | ||
var store = options.optimistic ? this.optimisticData : this.data; | ||
if (typeof options.rootId === 'string' && !store.has(options.rootId)) { | ||
return null; | ||
} | ||
return this.storeReader.readQueryFromStore({ | ||
store: options.optimistic ? this.optimisticData : this.data, | ||
store: store, | ||
query: options.query, | ||
@@ -76,0 +76,0 @@ variables: options.variables, |
@@ -16,3 +16,3 @@ import { InlineFragmentNode, FragmentDefinitionNode, SelectionSetNode, FieldNode } from "graphql"; | ||
}) => ReturnType<IdGetter>; | ||
declare type TypePolicy = { | ||
export declare type TypePolicy = { | ||
keyFields?: KeySpecifier | KeyFieldsFunction | false; | ||
@@ -31,6 +31,6 @@ queryType?: true; | ||
}) => ReturnType<IdGetter>; | ||
export declare type FieldPolicy<TValue> = { | ||
export declare type FieldPolicy<TExisting, TIncoming = TExisting, TReadResult = TExisting> = { | ||
keyArgs?: KeySpecifier | KeyArgsFunction | false; | ||
read?: FieldReadFunction<TValue>; | ||
merge?: FieldMergeFunction<TValue>; | ||
read?: FieldReadFunction<TExisting, TReadResult>; | ||
merge?: FieldMergeFunction<TExisting, TIncoming>; | ||
}; | ||
@@ -51,4 +51,4 @@ export declare type FieldValueGetter = ReturnType<Policies["makeFieldValueGetter"]>; | ||
} | ||
declare type FieldReadFunction<TExisting, TResult = TExisting> = (existing: Readonly<TExisting> | undefined, options: FieldFunctionOptions) => TResult; | ||
declare type FieldMergeFunction<TExisting> = (existing: Readonly<TExisting> | undefined, incoming: Readonly<StoreValue>, options: FieldFunctionOptions) => TExisting; | ||
export declare type FieldReadFunction<TExisting, TReadResult = TExisting> = (existing: Readonly<TExisting> | undefined, options: FieldFunctionOptions) => TReadResult; | ||
export declare type FieldMergeFunction<TExisting, TIncoming = TExisting> = (existing: Readonly<TExisting> | undefined, incoming: Readonly<TIncoming>, options: FieldFunctionOptions) => TExisting; | ||
export declare function defaultDataIdFromObject(object: StoreObject): string; | ||
@@ -55,0 +55,0 @@ export declare type PossibleTypesMap = { |
@@ -12,4 +12,3 @@ import { DocumentNode } from 'graphql'; | ||
export interface NormalizedCache { | ||
has(dataId: string, fieldName?: string): boolean; | ||
get(dataId: string): StoreObject; | ||
has(dataId: string): boolean; | ||
get(dataId: string, fieldName: string): StoreValue; | ||
@@ -16,0 +15,0 @@ merge(dataId: string, incoming: StoreObject): void; |
@@ -21,3 +21,2 @@ export { default as Observable } from 'zen-observable'; | ||
export { ApolloClient } from './ApolloClient.js'; | ||
export { default as gql } from 'graphql-tag'; | ||
export { ApolloCache } from './cache/core/cache.js'; | ||
@@ -31,2 +30,3 @@ export { Cache } from './cache/core/types/Cache.js'; | ||
export { concat } from './link/core/concat.js'; | ||
export { default as gql } from 'graphql-tag'; | ||
export { getApolloContext, resetApolloContext } from './react/context/ApolloContext.js'; | ||
@@ -33,0 +33,0 @@ export { ApolloProvider } from './react/context/ApolloProvider.js'; |
{ | ||
"name": "@apollo/client", | ||
"version": "3.0.0-beta.24", | ||
"version": "3.0.0-beta.25", | ||
"description": "A fully-featured caching GraphQL client.", | ||
@@ -44,3 +44,3 @@ "private": false, | ||
"graphql-tag": "^2.10.1", | ||
"optimism": "^0.11.3", | ||
"optimism": "^0.11.5", | ||
"symbol-observable": "^1.2.0", | ||
@@ -47,0 +47,0 @@ "ts-invariant": "^0.4.4", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
2044922
19647
Updatedoptimism@^0.11.5