npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-graphql-naming

v0.1.1

Published

ESLint plugin for enforcing GraphQL naming conventions based on file paths

Downloads

3

Readme

eslint-plugin-graphql-naming

ESLint plugin for enforcing GraphQL naming conventions based on file paths. Works with @graphql-eslint/eslint-plugin.

Features

  • 🔧 Auto-fixable: All rules support automatic fixing
  • 📁 File path based: Generates expected names from the file path
  • 🎯 Flexible: Supports customization via options
  • 📦 Separate rules: Individual rules for fragments, queries, and mutations

Installation

npm install eslint-plugin-graphql-naming --save-dev

Make sure you have the peer dependencies installed:

npm install @graphql-eslint/eslint-plugin graphql eslint --save-dev

Usage

ESLint Flat Config (eslint.config.js) - ESLint v9+

import graphqlNaming from 'eslint-plugin-graphql-naming'
import * as graphqlPlugin from '@graphql-eslint/eslint-plugin'

export default [
  {
    files: ['**/*.graphql', '**/*.gql'],
    languageOptions: {
      parser: graphqlPlugin,
      parserOptions: {
        schema: './schema.graphql',
      },
    },
    plugins: {
      '@graphql-eslint': graphqlPlugin,
      'graphql-naming': graphqlNaming,
    },
    rules: {
      'graphql-naming/fragment': 'error',
      'graphql-naming/operation': 'error',
      'graphql-naming/mutation': 'error',
    },
  },
]

Legacy Config (.eslintrc.js) - ESLint v8 and below

module.exports = {
  overrides: [
    {
      files: ['**/*.graphql', '**/*.gql'],
      parser: '@graphql-eslint/eslint-plugin',
      parserOptions: {
        schema: './schema.graphql',
      },
      plugins: ['@graphql-eslint', 'graphql-naming'],
      rules: {
        'graphql-naming/fragment': 'error',
        'graphql-naming/operation': 'error',
        'graphql-naming/mutation': 'error',
      },
    },
  ],
}

Rules

graphql-naming/fragment

Enforces naming convention for GraphQL Fragments.

Fragment names must follow the pattern: {Prefix}{TypeName}

Examples

# File: features/users/components/UserCard.vue

# ✅ Valid
fragment UsersUserCardUser on User {
  id
  name
}

# ✅ Valid (with suffix)
fragment UsersUserCardUserWithDetails on User {
  id
  name
  email
}

# ❌ Invalid
fragment UserCard on User {
  id
  name
}

graphql-naming/operation

Enforces naming convention for GraphQL Queries and Subscriptions.

Operation names must follow the pattern: {Prefix}{TypeName}

Examples

# File: features/users/components/UserCard.vue

# ✅ Valid
query UsersUserCardUser {
  user {
    id
    name
  }
}

# ✅ Valid subscription
subscription UsersUserCardUser {
  userUpdated {
    id
    name
  }
}

# ❌ Invalid
query GetUser {
  user {
    id
    name
  }
}

graphql-naming/mutation

Enforces naming convention for GraphQL Mutations.

Mutation names must follow the pattern: {Prefix}{TypeName}

Examples

# File: features/users/components/UserForm.vue

# ✅ Valid
mutation UsersUserFormUser {
  createUser(name: "John") {
    id
    name
  }
}

# ❌ Invalid
mutation CreateUser {
  createUser(name: "John") {
    id
    name
  }
}

Naming Convention

The expected name is calculated as: {Prefix}{TypeName}

Prefix Calculation

The prefix is derived from the file path:

  1. Directory name: The parent directory name (skipping components and [id] by default)
  2. File name: The file name without extension (up to the first .)

Both are converted to PascalCase and concatenated.

Examples

| File Path | Prefix | |-----------|--------| | features/users/components/UserCard.vue | UsersUserCard | | engine/organisms/OrderDetail/Main/Header/OrderTask.client.fragment.ts | HeaderOrderTask | | features/users/Users.vue | Users (no duplication) | | pages/[id]/EditForm.vue | IdEditForm |

TypeName

  • For fragments: The type being fragmented on (e.g., User, OrderForClient)
  • For operations: The return type of the first field in the selection set

Options

All rules accept the following options:

skipDirs

An array of directory names to skip when calculating the prefix. When the immediate parent directory matches one of these, the rule looks one level up.

Default: ['components', '[id]']

{
  rules: {
    'graphql-naming/fragment': ['error', { skipDirs: ['components', 'pages', '[id]'] }],
  },
}

Integration with Vue/React

This plugin works well with Vue SFC and React components that define GraphQL operations inline:

Vue Example

<script setup lang="ts">
import { graphql } from '@/graphql'

// File: features/users/components/UserCard.vue
// Valid name: UsersUserCardUser
const userFragment = graphql(`
  fragment UsersUserCardUser on User {
    id
    name
    avatar
  }
`)
</script>

React Example

// File: features/users/components/UserCard.tsx
// Valid name: UsersUserCardUser
const USER_QUERY = gql`
  query UsersUserCardUser {
    user {
      id
      name
    }
  }
`

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.