Hey folks, I while ago I wrote down some ideas on how we can add support for query complexity. For this we'll need two things:
For customising costs on fields and arguments I was thinking about something like this:
import strawberry
@strawberry.type
class Query:
@strawberry.field(cost=2)
def expensive_list(self, limit: Annotated[int, strawberry.argument(cost_multiplier=1)]) -> list[str]:
return ["Item"] * limit
Here we are saying that each individual item in the expensive_list
field costs 2, and the total is a multiplication between the field cost and the limit, so the result would be:
field_cost Γ limit Γ 1
We can also have defaults like this:
class StrawberryConfig:
# Existing attributes and methods ...
default_argument_cost_multiplier: Dict[str, Union[int, float]] = {
"limit": 1,
"first": 1, # probably not needed, but worth showing as an example
"last": 1
}
default_argument_cost_multiplier
is a map between argument name and their multiplier, though I don't like the name that much.
What do you think?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too