一句话:提出线性时间、可证正确的 GraphQL 查询代价静态分析,无需执行即可给出紧致的代价上界。
GraphQL 兼具查询语言与运行时,客户端能简洁地请求极大量数据,过复杂的查询会造成高昂开销甚至影响服务可用性;而现有 API 管理手段不足以估计查询代价。本文提出一种线性时间的 GraphQL 查询代价静态分析,无需执行查询即可度量代价,可部署于独立 API 管理层并适配任意 GraphQL 后端;不同于已有静态方法,它支持影响代价的常见 GraphQL 约定,并基于形式化的 GraphQL 语义证明了正确性。作者在两个商业 GraphQL API 上构建查询—响应语料进行评测:该分析持续给出相对真实响应足够紧致的代价上界,而现有静态分析因不支持这些约定而高估或低估。
The landscape of web APIs is evolving to meet new client requirements and to facilitate how providers fulfill them. A recent web API model is GraphQL, which is both a query language and a runtime. Using GraphQL, client queries express the data they want to retrieve or mutate, and servers respond with exactly those data or changes. GraphQL’s expressiveness is risky for service providers because clients can succinctly request stupendous amounts of data, and responding to overly complex queries can be costly or disrupt service availability. Recent empirical work has shown that many service providers are at risk. Using traditional API management methods is not sufficient, and practitioners lack principled means of estimating and measuring the cost of the GraphQL queries they receive. In this work, we present a linear-time GraphQL query analysis that can measure the cost of a query without executing it. Our approach can be applied in a separate API management layer and used with arbitrary GraphQL backends. In contrast to existing static approaches, our analysis supports common GraphQL conventions that affect query cost, and our analysis is provably correct based on our formal specification of GraphQL semantics. We demonstrate the potential of our approach using a novel GraphQL query-response corpus for two commercial GraphQL APIs. Our query analysis consistently obtains upper cost bounds, tight enough relative to the true response sizes to be actionable for service providers. In contrast, existing static GraphQL query analyses exhibit over-estimates and under-estimates because they fail to support GraphQL conventions.
DOI 原文 ·
@inproceedings{paperbot5867,
title = {A principled approach to GraphQL query cost analysis},
author = {Alan Cha and Erik Wittern and Guillaume Baudart and James C. Davis and Louis Mandel and Jim A. Laredo},
booktitle = {FSE},
year = {2020},
doi = {10.1145/3368089.3409670}
}