为REST(类似)API生成GraphQL-Wrappers
Generating GraphQL-Wrappers for REST(-like) APIs
摘要:
GraphQL是一种查询语言,它是一种基于此的范例,用于实现客户端-服务器交互的Web应用程序编程接口(API)。使用GraphQL,客户端在类型化查询中定义精确的嵌套数据需求,这些需求由服务器针对(可能是多个)后端系统(如数据库,对象存储或其他API)解决。客户端在单个请求中只接收他们关心的数据。然而,现有REST(类)API的提供者需要实现额外的GraphQL接口来实现这些优势。我们在这里评估为现有REST(类)API自动生成GraphQL包装器的可行性。包装器在接收到GraphQL查询时,将其转换为针对目标API的请求。我们讨论了创建这样的包装器的挑战,包括处理数据卫生,身份验证,或处理嵌套查询。此外,我们提出了一个原型实现OASGraph。OASGraph将描述现有REST(类)Web API的OpenAPI规范(OAS)作为输入,并为其生成GraphQL包装器。我们通过运行OASGraph以及现有的开源替代方案,对959个公开可用的OAS进行评估。这个实验表明,OASGraph优于现有的替代方案,能够为89.5%的API创建GraphQL包装器-然而,在许多情况下存在局限性。随后对OASGraph产生的错误和警告的分析表明,在评估的OAS中缺少或模糊的信息阻碍了创建完整的包装器。最后,我们展示了IBM Watson Language Translator API的一个用例,该用例表明,对OAS的小更改允许OASGraph生成更符合习惯、更具表达力的GraphQL包装器。
英文摘要:
GraphQL is a query language and thereupon-based paradigm for implementing web Application Programming Interfaces (APIs) for client-server interactions. Using GraphQL, clients define precise, nested data-requirements in typed queries, which are resolved by servers against (possibly multiple) backend systems, like databases, object storages, or other APIs. Clients receive only the data they care about, in a single request. However, providers of existing REST(-like) APIs need to implement additional GraphQL interfaces to enable these advantages. We here assess the feasibility of automatically generating GraphQL wrappers for existing REST(-like) APIs. A wrapper, upon receiving GraphQL queries, translates them to requests against the target API. We discuss the challenges for creating such wrappers, including dealing with data sanitation, authentication, or handling nested queries. We furthermore present a prototypical implementation of OASGraph. OASGraph takes as input an OpenAPI Specification (OAS) describing an existing REST(-like) web API and generates a GraphQL wrapper for it. We evaluate OASGraph by running it, as well as an existing open source alternative, against 959 publicly available OAS. This experiment shows that OASGraph outperforms the existing alternative and is able to create a GraphQL wrapper for 89.5% of the APIs -- however, with limitations in many cases. A subsequent analysis of errors and warnings produced by OASGraph shows that missing or ambiguous information in the assessed OAS hinders creating complete wrappers. Finally, we present a use case of the IBM Watson Language Translator API that shows that small changes to an OAS allow OASGraph to generate more idiomatic and more expressive GraphQL wrappers.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。