UNPKG

2.35 kBTypeScriptView Raw
1import type { DocumentNode } from "graphql";
2export type DocumentTransformCacheKey = ReadonlyArray<unknown>;
3type TransformFn = (document: DocumentNode) => DocumentNode;
4interface DocumentTransformOptions {
5 /**
6 * Determines whether to cache the transformed GraphQL document. Caching can speed up repeated calls to the document transform for the same input document. Set to `false` to completely disable caching for the document transform. When disabled, this option takes precedence over the [`getCacheKey`](#getcachekey) option.
7 *
8 * The default value is `true`.
9 */
10 cache?: boolean;
11 /**
12 * Defines a custom cache key for a GraphQL document that will determine whether to re-run the document transform when given the same input GraphQL document. Returns an array that defines the cache key. Return `undefined` to disable caching for that GraphQL document.
13 *
14 * > **Note:** The items in the array may be any type, but also need to be referentially stable to guarantee a stable cache key.
15 *
16 * The default implementation of this function returns the `document` as the cache key.
17 */
18 getCacheKey?: (document: DocumentNode) => DocumentTransformCacheKey | undefined;
19}
20export declare class DocumentTransform {
21 private readonly transform;
22 private cached;
23 private readonly resultCache;
24 private getCacheKey;
25 static identity(): DocumentTransform;
26 static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & {
27 left: DocumentTransform;
28 right: DocumentTransform;
29 };
30 constructor(transform: TransformFn, options?: DocumentTransformOptions);
31 /**
32 * Resets the internal cache of this transform, if it has one.
33 */
34 resetCache(): void;
35 private performWork;
36 transformDocument(document: DocumentNode): DocumentNode;
37 concat(otherTransform: DocumentTransform): DocumentTransform;
38 /**
39 * @internal
40 * Used to iterate through all transforms that are concatenations or `split` links.
41 */
42 readonly left?: DocumentTransform;
43 /**
44 * @internal
45 * Used to iterate through all transforms that are concatenations or `split` links.
46 */
47 readonly right?: DocumentTransform;
48}
49export {};
50//# sourceMappingURL=DocumentTransform.d.ts.map
\No newline at end of file