Skip to content

A Jest transformer for importing GraphQL queries from separate files, similar to the graphql-tag loader for Webpack.

License

Notifications You must be signed in to change notification settings

hamidyfine/jest-graphql-transformer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

npm install --save-dev jest-graphql-transformer

or

yarn add --dev jest-graphql-transformer

🔧 Usage

✅ Configure Jest to Use the Transformer

📌 In package.json

Add the following to your Jest configuration:

"jest": {
  "transform": {
    "\\.(gql|graphql)$": "jest-graphql-transformer",
    ".*": "babel-jest"
  }
}

📌 Or in jest.config.js / jest.config.ts

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:

export default {
  transform: {
    '\\.(gql|graphql)$': 'jest-graphql-transformer',
    '.*': 'babel-jest', // Keep Babel for other files
  },
};

📜 License

MIT License © 2024 hamidyfine

About

A Jest transformer for importing GraphQL queries from separate files, similar to the graphql-tag loader for Webpack.

Topics

Resources

License

Stars

Watchers

Forks