-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathcache.ts
28 lines (26 loc) · 889 Bytes
/
cache.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { ExecutionResult } from 'graphql';
import type { Maybe, PromiseOrValue } from '@envelop/core';
export type CacheEntityRecord = {
typename: string;
id?: number | string;
};
/**
* Interface for implementing a cache that will be used for `useResponseCache`.
*/
export type Cache = {
/** set a cache response */
set(
/** id/hash of the operation */
id: string,
/** the result that should be cached */
data: ExecutionResult,
/** array of entity records that were collected during execution */
entities: Iterable<CacheEntityRecord>,
/** how long the operation should be cached */
ttl: number,
): PromiseOrValue<void>;
/** get a cached response */
get(id: string): PromiseOrValue<Maybe<ExecutionResult>>;
/** invalidate operations via typename or id */
invalidate(entities: Iterable<CacheEntityRecord>): PromiseOrValue<void>;
};