@graphql-mesh/plugin-http-cache
Version:
35 lines (34 loc) • 1.29 kB
text/typescript
import CachePolicy from 'http-cache-semantics';
import type { GatewayPlugin } from '@graphql-hive/gateway';
import type { KeyValueCache, Logger } from '@graphql-mesh/types';
interface CacheEntry {
policy: CachePolicy.CachePolicyObject;
response: CachePolicy.Response;
body: string;
}
export interface HTTPCachePluginOptions {
/**
* If the following patterns match the request URL, the response will be cached. (Any of: String, URLPatternObj)
*/
matches?: (string | URLPatternObj)[];
/**
* If the following patterns match the request URL, the response will not be cached. (Any of: String, URLPatternObj)
*/
ignores?: (string | URLPatternObj)[];
policyOptions?: CachePolicy.Options | ((request: CachePolicy.Request, response: CachePolicy.Response) => CachePolicy.Options);
logger?: Logger;
cache?: KeyValueCache<CacheEntry>;
}
export interface URLPatternObj {
protocol?: string;
username?: string;
password?: string;
hostname?: string;
port?: string;
pathname?: string;
search?: string;
hash?: string;
baseURL?: string;
}
export default function useHTTPCache<TContext extends Record<string, any>>({ cache, matches, ignores, logger, }: HTTPCachePluginOptions): GatewayPlugin<TContext>;
export {};