forked from apollographql/apollo-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mutate update function DataProxy/ApolloCache changes
This commit gives the mutate `update` function direct access to the cache, instead of using a scaled down `DataProxy`. While the `DataProxy` approach helped in the past as a way to batch cache updates, it is no longer necessary. We are only ever passing a cache instance into `update`, which means limiting the type to be a `DataProxy` gives us no additional advantages. The only other `DataProxy` implementor in the AC codebase is `ApolloClient`, which is never passed to the `update` function. This commit also exposes optional `identify` and `modify` API elements in `ApolloCache`. Since `update` now has access to the full `ApolloCache` instance passed in, `identify` and `modify` can be used in the update function. Note that the `ApolloCache` implementations of `identify` and `modify` do nothing of value; they should be overridden by `ApolloCache` subclasses that are interested in using them, like `InMemoryCache` does. By including them in `ApolloCache` as basically no-op methods, we're avoiding forcing alternative cache implementations that subclass `ApolloCache` to have to support them.
- Loading branch information
Showing
13 changed files
with
108 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { SelectionSetNode } from 'graphql'; | ||
|
||
import { | ||
isReference, | ||
StoreValue, | ||
StoreObject, | ||
Reference | ||
} from '../../../utilities/graphql/storeUtils'; | ||
import { FragmentMap } from '../../../utilities/graphql/fragments'; | ||
|
||
// The Readonly<T> type only really works for object types, since it marks | ||
// all of the object's properties as readonly, but there are many cases when | ||
// a generic type parameter like TExisting might be a string or some other | ||
// primitive type, in which case we need to avoid wrapping it with Readonly. | ||
// SafeReadonly<string> collapses to just string, which makes string | ||
// assignable to SafeReadonly<any>, whereas string is not assignable to | ||
// Readonly<any>, somewhat surprisingly. | ||
export type SafeReadonly<T> = T extends object ? Readonly<T> : T; | ||
|
||
export type Modifier<T> = (value: T, details: { | ||
DELETE: any; | ||
fieldName: string; | ||
storeFieldName: string; | ||
isReference: typeof isReference; | ||
toReference( | ||
object: StoreObject, | ||
selectionSet?: SelectionSetNode, | ||
fragmentMap?: FragmentMap, | ||
): Reference; | ||
readField<V = StoreValue>( | ||
fieldName: string, | ||
objOrRef?: StoreObject | Reference, | ||
): SafeReadonly<V>; | ||
}) => T; | ||
|
||
export type Modifiers = { | ||
[fieldName: string]: Modifier<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters