index.js 939 B

1234567891011121314151617181920212223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.printWithReducedWhitespace = void 0;
  4. const graphql_1 = require("graphql");
  5. function printWithReducedWhitespace(ast) {
  6. const sanitizedAST = (0, graphql_1.visit)(ast, {
  7. StringValue(node) {
  8. return {
  9. ...node,
  10. value: Buffer.from(node.value, "utf8").toString("hex"),
  11. block: false,
  12. };
  13. },
  14. });
  15. const withWhitespace = (0, graphql_1.print)(sanitizedAST);
  16. const minimizedButStillHex = withWhitespace
  17. .replace(/\s+/g, " ")
  18. .replace(/([^_a-zA-Z0-9]) /g, (_, c) => c)
  19. .replace(/ ([^_a-zA-Z0-9])/g, (_, c) => c);
  20. return minimizedButStillHex.replace(/"([a-f0-9]+)"/g, (_, hex) => JSON.stringify(Buffer.from(hex, "hex").toString("utf8")));
  21. }
  22. exports.printWithReducedWhitespace = printWithReducedWhitespace;
  23. //# sourceMappingURL=index.js.map