pricing

package
v0.1.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pricing provides cost calculation for GraphQL queries based on computational complexity. This package can be easily removed if the pricing model needs to be changed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CostBreakdown

type CostBreakdown struct {
	Name          string          `json:"name"`
	Cost          uint64          `json:"cost"`
	Description   string          `json:"description,omitempty"`
	SubBreakdowns []CostBreakdown `json:"subBreakdowns,omitempty"`
}

CostBreakdown provides detailed information about how cost was calculated

type CostCalculator

type CostCalculator struct {
	// contains filtered or unexported fields
}

CostCalculator analyzes GraphQL queries and calculates credit costs

func NewCostCalculator

func NewCostCalculator(config PricingConfig) *CostCalculator

NewCostCalculator creates a new CostCalculator with the given configuration

func (*CostCalculator) CalculateQueryCost

func (c *CostCalculator) CalculateQueryCost(ctx context.Context, operation *ast.OperationDefinition, variables map[string]interface{}) (*CostBreakdown, error)

CalculateQueryCost analyzes a GraphQL operation and returns cost with detailed breakdown

type PricingConfig

type PricingConfig struct {
	BaseCosts              map[string]uint64 `yaml:"base_costs"`
	AggregationCosts       map[string]uint64 `yaml:"aggregation_costs"`
	TimeRangeCosts         map[string]uint64 `yaml:"time_range_costs"`
	IntervalCosts          map[string]uint64 `yaml:"interval_costs"`
	SignalCountCostDivisor uint64            `yaml:"signal_count_cost_divisor"`
}

PricingConfig contains configuration for the pricing calculator

func DefaultPricingConfig

func DefaultPricingConfig() *PricingConfig

DefaultPricingConfig returns the default pricing configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL