Offer a way to calculate and limit the total cost of a query
See original GitHub issueWhen offering a public API there’s the problem of malicious clients preparing intentionally expensive queries. For example one could abuse mutually related objects to arbitrarily make a query more expensive: book
-> author
-> books
-> author
-> books
-> …and so on.
I’d like to request a method to evaluate the estimated cost of query before actually executing any resolvers and a way to prevent execution of queries with the estimate cost above a certain threshold (ideally in a programmatic fashion so we could for example vary the limits depending on the currently logged in user’s role).
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to Create a Calculation Query in Microsoft Access
In this tutorial, we will teach you how to create a calculation query in Microsoft access.Don't forget to check out our site ...
Read more >Estimate storage and query costs | BigQuery - Google Cloud
Estimate costs of queries with Cloud console Query Validator, bq command-line tool, dryRun in APIs, Google Cloud Pricing Calculator, and the client libraries....
Read more >What Is The Cost In PostgreSQL EXPLAIN Query - ScaleGrid
It picks the plan with the lowest overall cost, based on some configurable constants and some statistics it has gathered.
Read more >Mysql query to calculate total cost - Stack Overflow
if the holidays were not adjacent (like 04-27 to 04-29 ), do you want one record or two in the resultset? · With...
Read more >Calculate query charges for Amazon Redshift Spectrum
How do I calculate the Redshift Spectrum query usage or cost, and what are some best practices to reduce the charges?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah sorry I missed that part. As far as I know there isn’t an “official” way of doing this but I’ve been playing around with then new backends feature that @syrusakbary introduced in graphql-core (https://github.com/graphql-python/graphql-core/pull/185) and I think this would be a great use case for it.
You should be able to do something like this with graphql-core 2.1rc:
Then when you’re executing the following query it will bail out before trying to execute the query:
I think there is a lot more that could be done here (like being able to assign complexity values to each field) but hopefully this helps you for now.
Middleware is a poor fit because middleware is executed for each and every field resolver. For anyone interested, here’s how we solved it in our codebase:
https://github.com/saleor/saleor/blob/fa288358ab8dfecb0f862c12edbc512ad0f3f000/saleor/graphql/views.py#L296-L302