当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

openapi-to-graphql

授权协议 MIT License
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 慕河
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

OpenAPI-to-GraphQL

Translate APIs described by OpenAPI Specifications (OAS) or Swagger into GraphQL.

Overview of translation

Getting started

OpenAPI-to-GraphQL can be used in two ways:

CLI

The Command Line Interface (CLI) provides a convenient way to start a GraphQL server wrapping an API for a given OpenAPI Specification:

  1. Install the OpenAPI-to-GraphQL CLI using:
    npm i -g openapi-to-graphql-cli
  2. Then, run the OpenAPI-to-GraphQL command and point it to an OpenAPI Specification:
    openapi-to-graphql <OAS JSON file path or remote url> [options]

For further details, refer to the openapi-to-graphql-cli documentation.

Library

Use OpenAPI-to-GraphQL as a library in your application to generate GraphQL schemas.

  1. Install OpenAPI-to-GraphQL as a dependency:
    npm i -s openapi-to-graphql
  2. Require OpenAPI-to-GraphQL and use the createGraphQLSchema function:
    const { createGraphQLSchema } = require("openapi-to-graphql");
    // load or construct OAS (const oas = ...)
    const { schema, report } = await createGraphQLSchema(oas);

For further details, refer to the openapi-to-graphql documentation.

Tutorials

Here are some guides to further help you get started:

  • CLI + Loopback tutorial: Learn how to quickly spin up GraphQL wrappers using the OpenAPI-to-GraphQL CLI.
  • Library tutorial: Learn how to use OpenAPI-to-GraphQL as a library, and how to improve the resulting GraphQL wrappers using OAS link definitions.
  • LoopBack tutorial: Learn how to use OpenAPI-to-GraphQL to create GraphQL wrappers for APIs created with LoopBack 4.
  • Subscriptions tutorial: Learn how to create a GraphQL API that supports subscription operations - including how to set up the API server that creates a PubSub instance wrapping a MQTT client.

Characteristics

  • Data-centricThe GraphQL interface is created around the data definitions in the given OAS, not around the endpoints, leading to a natural use of GraphQL.

    Example of data-centric design
  • Nested dataLinks defined in the OAS are used to create nested data structures, allowing for (deeply) nested queries.

    Example of links resolution
  • Automatic query resolutionAutomatically generated resolvers translate (nested) GraphQL queries to API requests. Request results are translated back to GraphQL responses.

    Example of query resolution
  • MutationsNon-safe, non-idempotent API operations (e.g., POST, PUT, DELETE) are translated to GraphQL mutations. Input payload is type-checked.

    Example of mutation
  • SubscriptionsGraphQL subscriptions allow clients to receive a stream of events, such as updates whenever data changes on the GraphQL server. OpenAPI-to-GraphQL can create subscriptions based on callback objects defined in the OAS.

    Example of subscription
  • AuthenticationOpenAPI-to-GraphQL currently supports authentication via API Key and basic auth. OpenAPI-to-GraphQL wraps secured endpoints into a viewer, which takes the API key / credentials as input.

    Example of authentication
  • API SanitationParts of an API that not compatible with GraphQL are automatically sanitized. For example, API parameters and data definition names with unsupported characters (e.g., -, ., ,, :, ;...) are removed. GraphQL queries are desanitized to correctly invoke the REST API and the responses are resanitized to create GraphQL-compliant results.

    Example of sanitation
  • Custom request options Provide headers and query parameters to send with every API request. This allows, for example, to handle authentication or tag requests from GraphQL.

  • Swagger and OpenAPI 3 support OpenAPI-to-GraphQL can handle both Swagger (OpenAPI specification 2.0) as well as OpenAPI specification 3.

Development

OpenAPI-to-GraphQL is written in TypeScript. Within each of OpenAPI-to-GraphQL's packages, all source code is contained in the src folder. Use npm run build or npm test to transpile the source files into the final library in the lib folder. Entry-point for the library is index.js in lib.

Research

Our research paper, "Generating GraphQL-Wrappers for REST(-like) APIs", can be found here. The paper describes the challenges of building OpenAPI-to-GraphQL and an experiment in which we evaluated OpenAPI-to-GraphQL against 959 publicly available OAS, provided by APIs.guru, and successfully created GraphQL interfaces for 89.5% of them.

To run the experiment, in the openapi-to-graphql package, load APIs.guru specifications, found here, into the /tmp folder:

npm run guru-load

Then, run tests:

npm run guru-test <number of APIs to test at most>

Similar projects

  • swagger-to-graphql turns a given Swagger (OpenAPI Specification 2.0) into a GraphQL interface, which resolves against the original API. GraphQL schema is based on endpoints, not on data definitions. No links are considered.

  • json-to-graphql turns given JSON objects / arrays into a GraphQL schema. resolve functions need to be provided by the user.

  • StackOverflow discussion points to the above projects.

License

MIT

  • 1. Query query = 'query MyQuery {Book(id: 1) {id, name, ver}}' payload_query = {'query': query} response_query = requests.post('http://127.0.0.1:8001/graphql', headers=headers,

  • 1、开放API 什么是API? API(Application Programming Interface,应用程序接口)是一些预先定义的接口(如函数、HTTP接口),或指软件系统不同组成部分衔接的约定。用来提供应用程序与开发人员基于某软件或硬件得以访问的一组例程,而又无需访问源码,或理解内部工作机制的细节。 什么是SDK? 软件开发工具包,SDK是一系列文件的组合,包括lib、dll、.h、文档

  • 为什么需要openapi?  现在的互联网充满了一个又一个信息孤岛和大量的碎片化的数据,用户想知道一些资讯,必须在不同的网站上跑来跑去.比如看电影,首先去google map查看周围的电影院,然后去大众点评网查看对这家电影院的评论,然后去电影院的网站上看看今天有什么电影上映。然后支付网站进行电子购票.整个过程非常繁琐,数据之间没有关联.充斥着大量的异构系统.  为了解决这些问题.我们引入了open

  • 什么是openapi?  在互联网时代,把网站的服务封装成一系列计算机易识别的数据接口开放出去,供第三方开发者使用,这种行为就叫做开放网站的API,与之对应的,所开放的API就被称作openAPI。 举个例子: 现在的互联网充满了一个又一个信息孤岛和大量的碎片化的数据,用户想知道一些资讯,必须在不同的网站上跑来跑去.比如看电影,首先去google map查看周围的电影院,然后去大众点评网查看对这家

  • QQ开放平台代码示例   腾讯开放平台 http://open.qq.com/tools?act=openapi_debug   测试类: TestOpenApiV3   package demo; import java.util.*; import com.qq.open.OpenApiV3; import com.qq.open.ErrorCode; import com.qq.

 相关资料
  • OpenAI Gym is a toolkit for developing and comparing reinforcement learning algorithms. It makes no assumptions about the structure of your agent, and is compatible with any numerical computation libr

  • 可以通过 OpenAPI Generator,在给定 OpenAPI 规范(v2, v3)的情况下自动生成 API 客户端库、server stubs、文档以及配置。 目前支持以下语言/框架: Languages/Frameworks API clients ActionScript, Ada, Apex, Bash, C# (.net 2.0, 3.5 or later), C++ (cppre

  • Build, Validate, Route, Authenticate, and Mock using OpenAPI definitions. OpenAPI Backend is a Framework-agnostic middleware tool for building beautiful APIs with OpenAPI Specification. Features Build

  • OpenAPI-CodeGen Node.js-based codegen for OpenAPI documents. This project was initially a 24-hour hackathon. The local model adaptor code is entirely original and has been reverse-engineered from the

  • Directory of API definitions in OpenAPI(fka Swagger) 2.0 and 3.x formats. API access to collection: Go! - We also have an RSS Feed Our goal is to create the most comprehensive, standards-compliant and

  • OpenAPI Specification 的目标是为 REST API 定义一个标准的、与语言无关的接口,允许人和计算机在不访问源代码、文档或通过网络的情况下发现和理解服务的功能。 通过 OpenAPI 的正确定义,消费者可以用最简答的方式理解远程服务并与其交互,消除了调用服务时的猜测。 OpenAPI不需要重写现有的API。它不需要将任何软件绑定到服务,所描述的服务甚至可能不是您的。然而,它要