Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Nov 16, 2023
1 parent d5d8cb1 commit 29bf59d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utilities/graphql/print.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import type { ASTNode } from "graphql";
import { print as origPrint } from "graphql";
import { WeakCache } from "@wry/caches"
import { WeakCache } from "@wry/caches";

let printCache!: WeakCache<ASTNode, string>;
export const print = Object.assign(
(ast: ASTNode) => {
let result = printCache.get(ast);

if (!result) {
printCache.set(ast, result = origPrint(ast));
printCache.set(ast, (result = origPrint(ast)));
}
return result;
},
{
reset() {
printCache = new WeakCache<ASTNode, string>(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */);
printCache = new WeakCache<
ASTNode,
string
>(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */);
},
}
);
Expand Down

0 comments on commit 29bf59d

Please sign in to comment.