What is @graphql-eslint/eslint-plugin?
@graphql-eslint/eslint-plugin is an ESLint plugin that provides linting rules for GraphQL schema and operations. It helps developers enforce best practices, catch errors early, and maintain consistency in their GraphQL code.
What are @graphql-eslint/eslint-plugin's main functionalities?
Linting GraphQL Schema
This feature allows you to lint your GraphQL schema files. The example configuration enforces rules to ensure that all type names are known and warns about deprecated fields.
module.exports = {
'plugins': ['@graphql-eslint'],
'overrides': [
{
'files': ['*.graphql'],
'parser': '@graphql-eslint/eslint-plugin',
'rules': {
'@graphql-eslint/known-type-names': 'error',
'@graphql-eslint/no-deprecated': 'warn'
}
}
]
};
Linting GraphQL Operations
This feature allows you to lint GraphQL operations within your JavaScript files. The example configuration enforces rules to ensure that there are no unused fields and that the 'id' field is used when available.
module.exports = {
'plugins': ['@graphql-eslint'],
'overrides': [
{
'files': ['*.js'],
'processor': '@graphql-eslint/graphql',
'rules': {
'@graphql-eslint/no-unused-fields': 'error',
'@graphql-eslint/require-id-when-available': 'warn'
}
}
]
};
Custom Rules
This feature allows you to define custom linting rules for your GraphQL code. The example configuration shows how to set up a custom rule with specific options.
module.exports = {
'plugins': ['@graphql-eslint'],
'rules': {
'@graphql-eslint/custom-rule': [
'error',
{
'ruleOption': 'value'
}
]
}
};
Other packages similar to @graphql-eslint/eslint-plugin
eslint-plugin-graphql
eslint-plugin-graphql is another ESLint plugin that provides GraphQL linting capabilities. It focuses on validating GraphQL queries and schema definitions within JavaScript files. Compared to @graphql-eslint/eslint-plugin, it has fewer built-in rules and less flexibility for custom rules.
graphql-schema-linter
graphql-schema-linter is a standalone tool for linting GraphQL schemas. It provides a set of rules to enforce best practices and catch common errors in schema definitions. Unlike @graphql-eslint/eslint-plugin, it does not integrate directly with ESLint and is used as a separate command-line tool.
graphql-eslint
graphql-eslint is a package that provides a set of ESLint rules for GraphQL. It is similar to @graphql-eslint/eslint-plugin but focuses more on providing a comprehensive set of rules for both schema and operations. It also offers better integration with various GraphQL tools and libraries.
GraphQL-ESLint
Documentation
https://the-guild.dev/graphql/eslint
Contributions
Contributions, issues and feature requests are very welcome. If you are using this package and fixed
a bug for yourself, please consider submitting a PR!
And if this is your first time contributing to this project, please do read our
Contributor Workflow Guide
before you get started off.
Code of Conduct
Help us keep GraphQL ESLint open and inclusive. Please read and follow our
Code of Conduct as adopted
from Contributor Covenant.
License
Released under the MIT license.