@graphql-tools/jest-transform
Version:
Jest Plugin to load and parse imported GraphQL files
30 lines (29 loc) • 945 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.process = process;
const tslib_1 = require("tslib");
const webpack_loader_1 = tslib_1.__importDefault(require("@graphql-tools/webpack-loader"));
class GraphQLTransformer {
process(input, _filePath, jestConfig) {
const config = jestConfig.config.globals?.['graphql'] || {};
// call directly the webpack loader with a mocked context
// as the loader leverages `this.cacheable()`
return {
code: webpack_loader_1.default.call({
cacheable() { },
query: config,
}, input),
};
}
}
let transformer;
function defaultTransformer() {
return transformer || (transformer = new GraphQLTransformer());
}
function process(...args) {
return defaultTransformer().process(...args);
}
const transformerFactory = {
process,
};
exports.default = transformerFactory;