UNPKG

@graphql-tools/jest-transform

Version:

Jest Plugin to load and parse imported GraphQL files

26 lines (25 loc) 753 B
import loader from '@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: loader.call({ cacheable() { }, query: config, }, input), }; } } let transformer; function defaultTransformer() { return transformer || (transformer = new GraphQLTransformer()); } export function process(...args) { return defaultTransformer().process(...args); } const transformerFactory = { process, }; export default transformerFactory;