# Learning GraphQL Query Costs (Extended Version)

arXiv: https://arxiv.org/abs/2108.11139 · HTML: https://mlsanity.com/paper/2108.11139/

## Key facts

- No citing papers in the map yet (data through 14 Oct 2026).
- Builds on 9 of its 27 references that are in the map.
- First posted on arXiv 25 Aug 2021.

## Builds on (most cited first, 9 of 9)

- [graph2vec: Learning Distributed Representations of Graphs](https://mlsanity.com/paper/1707.05005/) (2017)
- [A Survey of Machine Learning for Big Code and Naturalness](https://mlsanity.com/paper/1709.06182/) (2017)
- [Learning to Represent Programs with Graphs](https://mlsanity.com/paper/1711.00740/) (2017)
- [Plan-Structured Deep Neural Network Models for Query Performance Prediction](https://mlsanity.com/paper/1902.00132/) (2019)
- [Lale: Consistent Automated Machine Learning](https://mlsanity.com/paper/2007.01977/) (2020)
- [Migrating to GraphQL: A Practical Assessment](https://mlsanity.com/paper/1906.07535/) (2019)
- [REST vs GraphQL: A Controlled Experiment](https://mlsanity.com/paper/2003.04761/) (2020)
- [An Empirical Study of GraphQL Schemas](https://mlsanity.com/paper/1907.13012/) (2019)
- [A Principled Approach to GraphQL Query Cost Analysis](https://mlsanity.com/paper/2009.05632/) (2020)

## Abstract (arXiv)

GraphQL is a query language for APIs and a runtime for executing those queries, fetching the requested data from existing microservices, REST APIs, databases, or other sources. Its expressiveness and its flexibility have made it an attractive candidate for API providers in many industries, especially through the web. A major drawback to blindly servicing a client's query in GraphQL is that the cost of a query can be unexpectedly large, creating computation and resource overload for the provider, and API rate-limit overages and infrastructure overload for the client. To mitigate these drawbacks, it is necessary to efficiently estimate the cost of a query before executing it. Estimating query cost is challenging, because GraphQL queries have a nested structure, GraphQL APIs follow different design conventions, and the underlying data sources are hidden. Estimates based on worst-case static query analysis have had limited success because they tend to grossly overestimate cost. We propose a machine-learning approach to efficiently and accurately estimate the query cost. We also demonstrate the power of this approach by testing it on query-response data from publicly available commercial APIs. Our framework is efficient and predicts query costs with high accuracy, consistently outperforming the static analysis by a large margin.
