A powerful VS Code extension that analyzes GraphQL query complexity in real-time, helping developers write efficient queries and prevent expensive operations from reaching production.
- π Real-time Complexity Analysis: See complexity scores as you type GraphQL queries
β οΈ Intelligent Warnings: Get notified when queries exceed complexity thresholds- π Code Lens Integration: Complexity scores displayed directly in the editor
- π― Configurable Thresholds: Customize complexity limits for your specific needs
- π Schema Auto-loading: Automatically fetches and caches your GraphQL schema
- π§ Zero Configuration: Works out of the box with sensible defaults
- ποΈ Clean Architecture: Modular codebase with separation of concerns
- π Type Safety: Built with TypeScript for reliability and maintainability
- β‘ Performance Optimized: Efficient caching and minimal resource usage
- π οΈ Developer Friendly: Comprehensive error handling and debugging support
-
Install the Extension
# From VS Code Marketplace code --install-extension yashar-zolmajdi.graphql-complexity-vscode -
Open a GraphQL File
- Create or open any
.graphqlfile - The extension activates automatically
- Create or open any
-
Configure Your GraphQL Endpoint (Optional)
{ "graphqlComplexity.endpoint": "https://api.example.com/graphql", "graphqlComplexity.maxThreshold": 1000, "graphqlComplexity.scalarCost": 1 } -
Start Writing Queries
- Complexity scores appear above your queries
- Warnings show when thresholds are exceeded
- VS Code: Version 1.80.0 or higher
- GraphQL Endpoint: A running GraphQL server with introspection enabled
- Network Access: To fetch schema introspection (can be configured for local development)
Configure the extension through VS Code settings:
| Setting | Default | Description |
|---|---|---|
graphqlComplexity.endpoint |
http://localhost:4000/graphql |
GraphQL endpoint URL for schema introspection |
graphqlComplexity.maxThreshold |
1000 |
Maximum allowed complexity score |
graphqlComplexity.scalarCost |
1 |
Cost assigned to scalar fields |
{
"graphqlComplexity.endpoint": "https://api.github.com/graphql",
"graphqlComplexity.maxThreshold": 500,
"graphqlComplexity.scalarCost": 2
}The extension calculates query complexity using a depth-first approach:
- Schema Introspection: Fetches your GraphQL schema automatically
- AST Analysis: Parses queries into Abstract Syntax Trees
- Complexity Calculation: Assigns costs based on field depth and types
- Real-time Feedback: Updates complexity scores as you type
query GetUser {
user(id: "123") {
# Cost: 1
name # Cost: 1
posts {
# Cost: 1 * number of posts
title # Cost: 1 per post
comments {
# Cost: 1 * posts * comments
content # Cost: 1 per comment
}
}
}
}
# Total complexity varies based on data size- Node.js 18+
- pnpm (recommended) or npm
- VS Code
-
Clone the Repository
git clone https://github.com/yasharzolmajdi/graphql-complexity-vscode.git cd graphql-complexity-vscode -
Install Dependencies
pnpm install
-
Build the Extension
pnpm build # or npm run build -
Run in Development Mode
- Press
F5in VS Code to open a new Extension Development Host window - Or use the "Run Extension" launch configuration
- Press
src/
βββ extension.ts # Main extension entry point
βββ config/ # Configuration management
β βββ index.ts
β βββ manager.ts
βββ schema/ # GraphQL schema handling
β βββ index.ts
β βββ loader.ts
β βββ complexity-calculator.ts
βββ diagnostics/ # VS Code diagnostics
β βββ index.ts
β βββ manager.ts
βββ providers/ # VS Code providers
β βββ index.ts
β βββ code-lens.ts
β βββ document-manager.ts
βββ types/ # Type definitions
βββ index.ts
βββ config.ts
See ARCHITECTURE.md for detailed architecture documentation.
# Build the extension
pnpm build
# Watch for changes during development
pnpm watch
# Lint the code
pnpm lint
# Fix linting issues
pnpm lint:fix
# Format the code
pnpm format
# Check formatting
pnpm format:check
# Run all checks (lint + format + build)
pnpm check
# Package for distribution
vsce packageThis project uses modern development tools:
- TypeScript 5.8+: Strong typing and latest language features
- ESLint 9+: Modern flat config with TypeScript rules
- Prettier 3+: Consistent code formatting
- esbuild: Fast TypeScript compilation and bundling
- Husky: Git hooks for code quality
- lint-staged: Pre-commit linting and formatting
- VS Code: Built-in debugging and testing support
Testing framework setup is planned for future releases. The extension currently uses:
- Manual testing in Extension Development Host
- Real GraphQL endpoints for integration testing
- TypeScript compiler for static analysis
We welcome contributions! Please see our Contributing Guide for details.
- π Report Bugs: Open an issue with reproduction steps
- π‘ Suggest Features: Share your ideas for improvements
- π Improve Documentation: Help make our docs clearer
- π§ Submit Code: Fix bugs or implement new features
- π§ͺ Write Tests: Help us maintain code quality
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and commit:
git commit -m 'Add amazing feature' - Push to your branch:
git push origin feature/amazing-feature - Open a Pull Request
See CHANGELOG.md for a detailed history of changes.
- β¨ Initial release with modern ES modules architecture
- π Real-time complexity analysis using graphql-validation-complexity
β οΈ Configurable warning thresholds (default: 10)- π Code lens integration for inline complexity display
- π― Schema auto-loading with introspection caching
- π οΈ Modern TypeScript 5.8+ with ESLint flat config
- β‘ Fast esbuild compilation and bundling
- Schema Caching: Schema is cached until VS Code restart (manual refresh command planned)
- Large Schemas: Performance may be impacted with very large schemas (optimization planned)
- Authentication: Currently no support for authenticated endpoints (headers support planned)
- Custom Directives: Limited support for custom GraphQL directives
- Error Recovery: Schema errors may require extension reload
See our Issues page for the latest status and planned improvements.
- graphql-validation-complexity - Core complexity analysis library
- GraphQL Request - GraphQL client library
- VS Code GraphQL - GraphQL language support
This project is licensed under the MIT License - see the LICENSE file for details.
- GraphQL Foundation for the amazing GraphQL ecosystem
- VS Code Team for the excellent extension API
- graphql-validation-complexity for the complexity calculation engine
Made with β€οΈ by Yashar Zolmajdi
If you find this extension helpful, please consider:
- β Starring the repository
- π Leaving a review on the VS Code Marketplace
- π Reporting issues or suggesting improvements
- π€ Contributing to the project
Have questions or need help? Open an issue or reach out on Twitter.