@stewartmcgown/apollo-response-cache
Version:
Caching and invalidation mechanisms (plugins, directives) of Apollo GraphQL
35 lines (34 loc) • 1.01 kB
TypeScript
import { SchemaDirectiveVisitor } from 'graphql-tools';
interface LogCacheDirectiveProps {
/**
* Custom function to resolve node type and id.
*
* ```
* // define
* const typeResolver = (type: string, result: any) => {
* if (['Node', 'Response'].indexOf(type) >= 0) {
* return result.__type
* }
* return type
* }
*
* const schema = makeExecutableSchema({
* schemaDirectives: {
* purgeCache: PurgeCacheDirective({ typeResolver }),
* }
* })
*
* type Query {
* node(input: NodeInput!): Node @logCache(type: "Node")
* }
*
* // resolved as `Article`
* const nodeResult = { id: '2', __type: 'Article' }
*
* ```
*/
typeResolver?: (type: string, node: any) => string;
idResolver?: (type: string, node: any) => string;
}
export declare const LogCacheDirective: ({ typeResolver, idResolver, }: LogCacheDirectiveProps) => typeof SchemaDirectiveVisitor;
export {};