graphql-lint-unused-fields
v1.6.18
Published
Terminal and pipeline tool for detecting unused GraphQL fields
Maintainers
Readme
GraphQL Lint Unused Fields
🚀 Terminal and Pipeline Tool for detecting unused fields in GraphQL queries - Open source core + Specific extensions.
📦 Installation
npm install graphql-lint-unused-fields🎯 Features
- ✅ Traditional GraphQL query detection (
gql,graphqltemplate 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)
🚀 Basic Usage
CLI
# Basic usage
npx graphql-lint-unused-fields /path/to/project
# Configurable pipeline
npx graphql-lint-pipeline /path/to/project --format console,json --parallel
# With configuration file
npx graphql-lint-pipeline --config pipeline-config.jsonProgrammatic
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
# Basic analysis
npx graphql-lint-unused-fields /project
# Deep scan (more files)
npx graphql-lint-unused-fields /project --deep-scan
# No file limit
npx graphql-lint-unused-fields /project --no-limit
# Advanced analysis
npx graphql-lint-unused-fields /project --advanced
# Pipeline with multiple formats
npx graphql-lint-pipeline /project --format console,json --parallel🔧 Configuration
Create a graphql-lint.config.js file:
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🏗️ Monorepo Architecture
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
🛠️ Extensibility
For custom patterns and Clint-specific analysis, see graphql-lint-unused-fields-clint which extends this package.
📚 Documentation
- 📖 Core Package README
- 🎯 Clint Package README
- ⚙️ CLI Documentation
- 🔗 GraphQL Aliases Mapping ⭐
- 🔌 ESLint Plugin
- 📡 Hasura Schema Analysis
- 🔄 Variable Tracking
- 🚀 Pipeline Configuration ⭐
🤝 Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
📝 License
MIT - See LICENSE for details.
