On this page

Usage with custom GraphQL rules

Usage with custom GraphQL rules — GraphQL ESLint documentation.

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'
    }
  }
]