UNPKG

@stewartmcgown/apollo-response-cache

Version:

Caching and invalidation mechanisms (plugins, directives) of Apollo GraphQL

40 lines (39 loc) 1.23 kB
import { SchemaDirectiveVisitor } from 'graphql-tools'; interface PurgeCacheDirectiveProps { /** * The path to get extra nodes from result object. * * ``` * // define * const schema = makeExecutableSchema({ * schemaDirectives: { * purgeCache: PurgeCacheDirective({ extraNodesPath: '__invalid_nodes__' }), * } * }) * * type Mutation { * editArticle(id: ID!): Article! @purgeCache(type: "Article") * } * * // @purgeCache will invalidate three nodes: Article:1, Article:2 and Comment:3. * const editArticleResult = { * id: '1', * content: '...', * __invalid_nodes__: [ * { id: '2', type: 'Article' }, * { id: '3', type: 'Comment' } * ] * } * ``` */ extraNodesPath?: string; /** * Custom function to resolve type and id. * * Same as `@logCache`, see `logCache.ts` for details. **/ typeResolver?: (type: string, node: any) => string; idResolver?: (type: string, node: any) => string; } export declare const PurgeCacheDirective: ({ extraNodesPath, typeResolver, idResolver, }: PurgeCacheDirectiveProps) => typeof SchemaDirectiveVisitor; export {};