Discussion NodeJS

openapi-to-graphql

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:

  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.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *