index.d.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { ResponsePath } from 'graphql';
  2. import { ApolloServerPlugin } from "apollo-server-plugin-base";
  3. export interface CacheControlFormat {
  4. version: 1;
  5. hints: ({
  6. path: (string | number)[];
  7. } & CacheHint)[];
  8. }
  9. export interface CacheHint {
  10. maxAge?: number;
  11. scope?: CacheScope;
  12. }
  13. export declare enum CacheScope {
  14. Public = "PUBLIC",
  15. Private = "PRIVATE"
  16. }
  17. export interface CacheControlExtensionOptions {
  18. defaultMaxAge?: number;
  19. calculateHttpHeaders?: boolean;
  20. stripFormattedExtensions?: boolean;
  21. }
  22. declare module 'graphql/type/definition' {
  23. interface GraphQLResolveInfo {
  24. cacheControl: {
  25. setCacheHint: (hint: CacheHint) => void;
  26. cacheHint: CacheHint;
  27. };
  28. }
  29. }
  30. declare module 'apollo-server-types' {
  31. interface GraphQLRequestContext<TContext> {
  32. overallCachePolicy?: Required<CacheHint> | undefined;
  33. }
  34. }
  35. declare type MapResponsePathHints = Map<ResponsePath, CacheHint>;
  36. export declare const plugin: (options?: CacheControlExtensionOptions) => ApolloServerPlugin;
  37. declare function computeOverallCachePolicy(hints: MapResponsePathHints): Required<CacheHint> | undefined;
  38. declare function addHint(hints: MapResponsePathHints, path: ResponsePath, hint: CacheHint): void;
  39. export declare const __testing__: {
  40. addHint: typeof addHint;
  41. computeOverallCachePolicy: typeof computeOverallCachePolicy;
  42. };
  43. export {};
  44. //# sourceMappingURL=index.d.ts.map