arch: move web folder into api & move api to top level
This commit is contained in:
33
frontend/src/shared/utils/cache.ts
Normal file
33
frontend/src/shared/utils/cache.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { DataProxy } from '@apollo/client';
|
||||
import { DocumentNode } from 'graphql';
|
||||
|
||||
type UpdateCacheFn<T> = (cache: T) => T;
|
||||
|
||||
export function updateApolloCache<T>(
|
||||
client: DataProxy,
|
||||
document: DocumentNode,
|
||||
update: UpdateCacheFn<T>,
|
||||
variables?: object,
|
||||
) {
|
||||
let queryArgs: DataProxy.Query<any>;
|
||||
if (variables) {
|
||||
queryArgs = {
|
||||
query: document,
|
||||
variables,
|
||||
};
|
||||
} else {
|
||||
queryArgs = {
|
||||
query: document,
|
||||
};
|
||||
}
|
||||
const cache: T | null = client.readQuery(queryArgs);
|
||||
if (cache) {
|
||||
const newCache = update(cache);
|
||||
client.writeQuery({
|
||||
...queryArgs,
|
||||
data: newCache,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default updateApolloCache;
|
Reference in New Issue
Block a user