https://github.com/hamidyfine/jest-graphql-transformer
A Jest transformer for importing GraphQL queries from separate files, similar to the graphql-tag loader for Webpack.
https://github.com/hamidyfine/jest-graphql-transformer
graphql jest jest-transform jest-transformer translation
Last synced: 5 months ago
JSON representation
A Jest transformer for importing GraphQL queries from separate files, similar to the graphql-tag loader for Webpack.
- Host: GitHub
- URL: https://github.com/hamidyfine/jest-graphql-transformer
- Owner: hamidyfine
- License: mit
- Created: 2025-02-28T12:27:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-01T17:02:48.000Z (over 1 year ago)
- Last Synced: 2025-10-29T23:18:54.937Z (9 months ago)
- Topics: graphql, jest, jest-transform, jest-transformer, translation
- Homepage: https://www.apollographql.com/docs/react/integrations/webpack#jest
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-graphql-transformer
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.
---
## 🚀 Installation
Install the package using **npm** or **yarn**:
```sh
npm install --save-dev jest-graphql-transformer
```
or
```sh
yarn add --dev jest-graphql-transformer
```
---
## 🔧 Usage
### ✅ Configure Jest to Use the Transformer
#### 📌 **In `package.json`**
Add the following to your Jest configuration:
```json
"jest": {
"transform": {
"\\.(gql|graphql)$": "jest-graphql-transformer",
".*": "babel-jest"
}
}
```
#### 📌 **Or in `jest.config.js` / `jest.config.ts`**
```javascript
export default {
transform: {
'\\.(gql|graphql)$': 'jest-graphql-transformer',
},
};
```
### ⚠️ **Note:**
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:
```javascript
export default {
transform: {
'\\.(gql|graphql)$': 'jest-graphql-transformer',
'.*': 'babel-jest', // Keep Babel for other files
},
};
```
---
## 📜 License
MIT License © 2024 [hamidyfine](https://github.com/hamidyfine)