A Jest transformer that allows GraphQL queries in separate files, similar to the graphql-tag
loader for Webpack, but adapted for Jest, which does not support Webpack loaders. This package provides the same transformation within Jest, enabling seamless GraphQL query imports.
Install the package using npm or yarn:
npm install --save-dev jest-graphql-transformer
or
yarn add --dev jest-graphql-transformer
Add the following to your Jest configuration:
"jest": {
"transform": {
"\\.(gql|graphql)$": "jest-graphql-transformer",
".*": "babel-jest"
}
}
export default {
transform: {
'\\.(gql|graphql)$': 'jest-graphql-transformer',
},
};
Once you define the transform
property, Jest's default transformations will be overridden.
If you need Babel for other files, make sure to include it:
export default {
transform: {
'\\.(gql|graphql)$': 'jest-graphql-transformer',
'.*': 'babel-jest', // Keep Babel for other files
},
};
MIT License © 2024 hamidyfine