Terminal and pipeline tool for detecting unused GraphQL fields
npm install graphql-lint-unused-fieldsš Terminal and Pipeline Tool for detecting unused fields in GraphQL queries - Open source core + Specific extensions.

``bash`
npm install graphql-lint-unused-fields
- ā
Traditional GraphQL query detection (gql, graphql template literals)
- ā
Complete GraphQL alias mapping š
- ā
Field usage analysis in TypeScript/JavaScript
- ā
React support (JSX, hooks, destructuring)
- ā
Cross-file analysis for tracking between files
- ā
Integrated CLI for CI/CD usage
- ā
Configurable pipeline with customizable steps
- ā
Multiple output formats (console, json, eslint)
- ā
Configuration via file (JSON/YAML)
`bashBasic usage
npx graphql-lint-unused-fields /path/to/project
$3
`typescript
import { UnusedFieldsLinter } from "graphql-lint-unused-fields";const linter = new UnusedFieldsLinter();
const result = await linter.analyze("/path/to/project");
console.log(
Unused fields: ${result.unusedFields.length});
`šļø CLI Options
`bash
Basic analysis
npx graphql-lint-unused-fields /projectDeep scan (more files)
npx graphql-lint-unused-fields /project --deep-scanNo file limit
npx graphql-lint-unused-fields /project --no-limitAdvanced analysis
npx graphql-lint-unused-fields /project --advancedPipeline with multiple formats
npx graphql-lint-pipeline /project --format console,json --parallel
`š§ Configuration
Create a
graphql-lint.config.js file:`javascript
module.exports = {
// File patterns to include
include: ["src/*/.{ts,tsx,js,jsx}"], // Patterns to exclude
exclude: ["node_modules/", "/.test."],
// Advanced analysis
advanced: true,
// File limit (0 = no limit)
maxFiles: 1000,
};
`š Example Output
`
š GRAPHQL LINT - ANALYSIS RESULTš GENERAL STATISTICS:
šÆ Queries analyzed: 42
š Fields found: 156
ā
Fields in use: 142 (91%)
ā Unused fields: 14 (9%)
šØ These are the unused fields in your GraphQL queries:
š¹ GetUser (3 unused fields) [/path/to/file.ts]
⢠email (line 15:10)
š File: /path/to/file.ts
Path: user ā email
⢠phone (line 16:12)
š File: /path/to/file.ts
Path: user ā phone
``This package is part of a monorepo with two main packages:
- graphql-lint-unused-fields (this package) - Open source core tool
- graphql-lint-unused-fields-clint - Clint-specific extension
For custom patterns and Clint-specific analysis, see graphql-lint-unused-fields-clint which extends this package.
- š Core Package README
- šÆ Clint Package README
- āļø CLI Documentation
- š GraphQL Aliases Mapping ā
- š ESLint Plugin
- š” Hasura Schema Analysis
- š Variable Tracking
- š Pipeline Configuration ā
Contributions are welcome! See CONTRIBUTING.md for guidelines.
MIT - See LICENSE for details.