CostEstimation

class Object
trait Matchable
class Any

Type members

Classlikes

A directive that can be applied to both fields and types to flag them as targets for cost analysis. This allows a simple estimation to be applied which can be used to prevent overly expensive queries from being executed

A directive that can be applied to both fields and types to flag them as targets for cost analysis. This allows a simple estimation to be applied which can be used to prevent overly expensive queries from being executed

case class GQLCost(cost: Double, multipliers: List[String]) extends GQLDirective

Value members

Concrete methods

def maxCost(maxCost: Double)(f: Field => Double): ValidationWrapper[Any]

Computes the estimated cost of executing the query using the provided function and compares it to the maxCost parameter which determines the maximum allowable cost for a query.

Computes the estimated cost of executing the query using the provided function and compares it to the maxCost parameter which determines the maximum allowable cost for a query.

Value parameters:
f

The field cost estimate function

maxCost

The maximum allowable cost for executing a query

def maxCostOrError(maxCost: Double)(f: Field => Double)(error: Double => ValidationError): ValidationWrapper[Any]

More powerful version of maxCost which allow you to also specify the error that is returned when the cost exceeds the maximum cost.

More powerful version of maxCost which allow you to also specify the error that is returned when the cost exceeds the maximum cost.

Value parameters:
error

A function that will be provided the total estimated cost and must return the error that will be returned

f

The function used to evaluate the cost of a single field

maxCost

The total cost allowed for any one query

def maxCostZIO[R](maxCost: Double)(f: Field => URIO[R, Double]): ValidationWrapper[R]

More powerful version of maxCost which allows the field computation function to specify a function which returns an effectful computation for the cost of a field.

More powerful version of maxCost which allows the field computation function to specify a function which returns an effectful computation for the cost of a field.

Value parameters:
f

The function used to evaluate the cost of a single field returning an effect which will result in the field cost as a double

maxCost

The total cost allowed for any one query

def queryCost(f: Field => Double): Wrapper[Any]

Computes the estimated cost of the query based on the provided field cost function and adds it as an extension to the GraphQLResponse. This is useful for tracking the overall cost of a query either when you are trying to dial in a correct heuristic or when you want to inform users of your graph how expensive their queries are.

Computes the estimated cost of the query based on the provided field cost function and adds it as an extension to the GraphQLResponse. This is useful for tracking the overall cost of a query either when you are trying to dial in a correct heuristic or when you want to inform users of your graph how expensive their queries are.

See also:

queryCostWith, queryCostZIO

def queryCostWith[R](f: Field => Double)(p: Double => URIO[R, Any]): Wrapper[R]

Computes the estimated cost of the query based on the provided field cost function and passes it to the second function which can run an arbitrary side effect with the result.

Computes the estimated cost of the query based on the provided field cost function and passes it to the second function which can run an arbitrary side effect with the result.

See also:

queryCost

def queryCostZIO[R](f: Field => URIO[R, Double]): Wrapper[R]

A more powerful version of queryCost which allows the field cost computation to return an effect instead of a plain value when computing the cost estimate.

A more powerful version of queryCost which allows the field cost computation to return an effect instead of a plain value when computing the cost estimate.

Value parameters:
f

The field cost estimate function

See also:

queryCostZIOWith for a more powerful version

def queryCostZIOWith[R](f: Field => URIO[R, Double])(p: Double => URIO[R, Any]): Wrapper[R]

A more powerful version of queryCostZIO that allows the total result of the query to be pushed into a separate effect. This is useful when you want to compute the cost of the query but you already have your own system for recording the cost.

A more powerful version of queryCostZIO that allows the total result of the query to be pushed into a separate effect. This is useful when you want to compute the cost of the query but you already have your own system for recording the cost.

Value parameters:
f

The field cost estimate function

p

A function which receives the total estimated cost of executing the query and can

def queryCostZIOWrapperState[R](costWrapper: Ref[Double] => Wrapper[R])(p: (Double, GraphQLResponse[CalibanError]) => URIO[R, GraphQLResponse[CalibanError]]): Wrapper[R]

The most powerful version of queryCost that allows maximum freedom in how the wrapper is defined. The function accepts a function that will take a Ref that can be used for book keeping to track the current cost of the query, and returns a wrapper. Normally this wrapper is a validation wrapper because it should be run before execution for the purposes of cost estimation. However, the API provides the flexibility to redefine that. The second parameter of the function will receive the final cost estimate of the query as well as the current graphql response, it returns an effect that produces a potentially modified response.

The most powerful version of queryCost that allows maximum freedom in how the wrapper is defined. The function accepts a function that will take a Ref that can be used for book keeping to track the current cost of the query, and returns a wrapper. Normally this wrapper is a validation wrapper because it should be run before execution for the purposes of cost estimation. However, the API provides the flexibility to redefine that. The second parameter of the function will receive the final cost estimate of the query as well as the current graphql response, it returns an effect that produces a potentially modified response.

Value parameters:
costWrapper

User provided function that will result in a wrapper that may be used when computing the cost of a query

p

The response transforming function which receives the cost estimate as well as the response value.

See also:

queryCostZIOWith, queryCostZIO, queryCost

Concrete fields

final val COST_DIRECTIVE_NAME: "cost"
final val COST_EXTENSION_NAME: "queryCost"
val costDirective: Field => Double

Computes field cost by examining the @cost directive. This can be used in conjunction with queryCost or maxCost In order to compute the estimated cost of executing a query.

Computes field cost by examining the @cost directive. This can be used in conjunction with queryCost or maxCost In order to compute the estimated cost of executing a query.

Note:

This will be executed before the actual resolvers are called, which allows you to stop potentially expensive queries from being run, but may also require more work on the developer part to determine the correct heuristic for estimating field cost.

lazy val queryCost: Wrapper[Any]

Computes the estimated cost of the query based on the default cost estimation (backed by the @GQLCost directive) and adds it as an extension to the GraphQLResponse. This is useful for tracking the overall cost of a query either when you are trying to dial in a correct heuristic or when you want to inform users of your graph how expensive their queries are.

Computes the estimated cost of the query based on the default cost estimation (backed by the @GQLCost directive) and adds it as an extension to the GraphQLResponse. This is useful for tracking the overall cost of a query either when you are trying to dial in a correct heuristic or when you want to inform users of your graph how expensive their queries are.

See also:

queryCostWith, queryCostZIO