
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
eslint-plugin-relay
Advanced tools
eslint-plugin-relay is an ESLint plugin that provides linting rules for Relay, a JavaScript framework for building data-driven React applications. It helps ensure that your Relay code follows best practices and is free of common errors.
GraphQL Template Literal Linting
This feature ensures that GraphQL template literals are correctly formatted and syntactically valid. The rule checks for common mistakes in GraphQL queries embedded in JavaScript code.
/* eslint relay/graphql-syntax: 'error' */
const query = graphql`
query UserQuery {
user(id: "4") {
name
}
}
`;
Compat Mode
This feature helps in transitioning to Relay Modern by ensuring that variables used in compat mode are correctly handled. It warns about potential issues when using older Relay Classic fragments with Relay Modern.
/* eslint relay/compat-uses-vars: 'warn' */
const fragment = graphql`
fragment UserFragment on User {
id
name
}
`;
No Unused Variables
This rule checks for unused variables in GraphQL queries, helping to keep the code clean and efficient by ensuring that all declared variables are used in the query.
/* eslint relay/no-unused-variables: 'error' */
const query = graphql`
query UserQuery($id: ID!) {
user(id: $id) {
name
}
}
`;
eslint-plugin-graphql is a similar package that provides ESLint rules for GraphQL. It supports various GraphQL clients, including Relay, Apollo, and Lokka. While eslint-plugin-relay is specifically tailored for Relay, eslint-plugin-graphql offers broader support for different GraphQL clients, making it more versatile for projects that use multiple GraphQL libraries.
graphql-eslint is another package that offers a comprehensive set of ESLint rules for GraphQL. It provides more extensive linting capabilities for GraphQL schemas and operations, and it can be used with various GraphQL clients. Compared to eslint-plugin-relay, graphql-eslint offers a wider range of rules and is suitable for projects that require detailed GraphQL linting beyond just Relay.
eslint-plugin-relay
is a plugin for ESLint to catch common problems in code using Relay early.
npm i --save-dev eslint-plugin-relay
"relay"
to your eslint plugins
section."relay/graphql-syntax": "error"
to your eslint rules
section, see the example for all rules.Example .eslintrc.js:
module.exports = {
// Other eslint properties here
rules: {
'relay/graphql-syntax': 'error',
'relay/compat-uses-vars': 'warn',
'relay/graphql-naming': 'error',
'relay/generated-flow-types': 'warn',
'relay/no-future-added-value': 'warn',
'relay/unused-fields': 'warn'
},
plugins: ['relay']
};
You can also enable all the recommended or strict rules at once.
Add plugin:relay/recommended
or plugin:relay/strict
in extends
:
{
"extends": [
"plugin:relay/recommended"
]
}
We actively welcome pull requests, learn how to contribute.
eslint-plugin-relay
is MIT licensed.
FAQs
ESLint plugin for Relay.
The npm package eslint-plugin-relay receives a total of 158,701 weekly downloads. As such, eslint-plugin-relay popularity was classified as popular.
We found that eslint-plugin-relay demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.