Usage with custom GraphQL rules
Note
Check out the official example for ESLint Flat Config .
Custom GraphQL Rule
my-rule.js
export const rule = {
  create(context) {
    return {
      OperationDefinition(node) {
        if (!node.name?.value) {
          context.report({
            node,
            message: 'Oops, name is required!',
          });
        }
      },
    };
  },
};ESLint Flat Config
eslint.config.js
import graphqlPlugin from '@graphql-eslint/eslint-plugin';
import { rule } from './my-rule.js';
 
export default [
  {
    files: ['**/*.graphql'],
    languageOptions: {
      parser: graphqlPlugin.parser,
    },
    plugins: {
      '@internal': {
        rules: {
          'my-rule': rule,
        },
      },
    },
    rules: {
      '@internal/my-rule': 'error',
    },
  },
];💡
Tip
Check out the custom rules guide to learn how to create your own rules.
Last updated on