UNPKG

@matters/apollo-response-cache

Version:

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

43 lines (42 loc) 1.26 kB
import { GraphQLSchema } from 'graphql'; interface PurgeCacheDirectiveOption { /** * 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: (directiveName?: string) => { typeDef: string; transformer: (schema: GraphQLSchema, options: PurgeCacheDirectiveOption) => GraphQLSchema; }; export {};