Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>GraphQL Query Cost CalculatorNew to Visual Studio Code? Get it now.
GraphQL Query Cost Calculator

GraphQL Query Cost Calculator

AnonymousTokyo

|
1 install
| (0) | Free
Analyze GraphQL query complexity and estimate execution costs
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

GraphQL Query Cost Calculator

A Visual Studio Code extension that helps developers analyze GraphQL query complexity and estimate execution costs before sending queries to the server.

Features

  • Query Cost Analysis: Automatically calculates the cost of GraphQL queries based on field depth, list operations, and complexity.
  • Visual Cost Explorer: Visualizes query cost breakdown in an interactive treemap and bar chart.
  • Optimization Suggestions: Provides actionable recommendations to reduce query complexity and cost.
  • Cost Breakdown: Shows detailed cost information for each field in the query.
  • Integration with VS Code: Right-click on any GraphQL query file to analyze costs.

Use Cases

  • API Cost Optimization: Identify and optimize expensive GraphQL queries before they hit production.
  • API Usage Planning: Understand the server resources your queries will consume.
  • API Provider Pricing: Help API providers estimate and charge for query costs.
  • Performance Tuning: Identify bottlenecks in your GraphQL operations.

Installation

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
  3. Search for "GraphQL Query Cost Calculator"
  4. Click Install

Usage

Analyzing Query Cost

  1. Open any GraphQL query file (.graphql, .gql) or a file containing GraphQL queries
  2. Right-click in the editor and select "Calculate GraphQL Query Cost"
  3. Alternatively, use the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and select "Calculate GraphQL Query Cost"
  4. The cost analysis will appear in the GraphQL Cost Explorer view in the Explorer sidebar

Viewing Detailed Cost Analysis

  1. After calculating query cost, click on "Show GraphQL Cost Explorer" in the notification
  2. Alternatively, use the Command Palette and select "Show GraphQL Cost Explorer"
  3. The detailed cost visualization will open in a new tab, showing:
    • Total cost and complexity
    • Cost breakdown by field
    • Cost distribution treemap
    • Optimization suggestions

Configuration

You can customize the extension's behavior in VS Code settings:

{
  "graphqlCostCalculator.schemaPath": "/path/to/schema.graphql",
  "graphqlCostCalculator.costFactors": {
    "defaultCost": 1,
    "depthFactor": 1.5,
    "listFactor": 2,
    "connectionFactor": 3
  },
  "graphqlCostCalculator.apiEndpoint": "https://your-graphql-api.com/graphql"
}

Configuration Options

  • schemaPath: Path to your GraphQL schema file (optional)
  • costFactors: Custom cost factors for different query operations
    • defaultCost: Base cost for any field
    • depthFactor: Multiplier for nested fields (exponential with depth)
    • listFactor: Multiplier for list fields
    • connectionFactor: Multiplier for connection fields (pagination)
  • apiEndpoint: GraphQL API endpoint for schema introspection (if no local schema provided)

How It Works

This extension uses a combination of static analysis and heuristics to estimate the cost of GraphQL queries:

  1. Query Parsing: The query is parsed into an AST (Abstract Syntax Tree).
  2. Field Analysis: Each field is analyzed for:
    • Nesting depth
    • List operations
    • Connection patterns
    • Known expensive operations
  3. Cost Calculation: Costs are calculated using configurable factors and weights.
  4. Optimization Analysis: The query structure is analyzed to generate optimization suggestions.

Advanced Features

  • Support for Fragments: Fragment spreads and inline fragments are properly analyzed.
  • Operation Type Adjustment: Mutations and subscriptions have different cost models than queries.
  • Treemap Visualization: Interactive treemap shows the relative cost of different parts of your query.
  • Cost Comparison: Save historical query costs to compare optimization improvements.

Contributing

Contributions are welcome! See CONTRIBUTING.md for details.

License

This extension is licensed under the MIT License. See LICENSE for details.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft