Translate APIs described by OpenAPI Specifications (OAS) or Swagger into GraphQL.
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:
- Install the OpenAPI-to-GraphQL CLI using:npm i -g openapi-to-graphql-cli
- 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.
- Install OpenAPI-to-GraphQL as a dependency:npm i -s openapi-to-graphql
- 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.