Skip to content

Latest commit

 

History

History
52 lines (30 loc) · 2.1 KB

cli_loopback.md

File metadata and controls

52 lines (30 loc) · 2.1 KB

OpenAPI-to-GraphQL Quickstart tutorial

The purpose of this tutorial is to show how easy it is to use OpenAPI-to-GraphQL CLI.

With just a single command line instruction, openapi-to-graphql <OAS JSON file path or remote url>, you can get a GraphQL server running.

Please note that while the CLI tool will satisfy most needs, it does not offer the flexibility or functionality of OpenAPI-to-GraphQL's intended usage, as an integrated library. See the README.md for more information.

Video demo

OpenAPI-to-GraphQL

Do it yourself

Make sure you have installed Node.js

Before you install OpenAPI-to-GraphQL, make sure to download and install Node.js (version 8.9.x or higher), a JavaScript runtime.

To install Node.js, click here.

Install OpenAPI-to-GraphQL

OpenAPI-to-GraphQL can be used either as a library, or via its Command Line Interface (CLI). To install the CLI tool, run the following command.

npm i -g openapi-to-graphql-cli

Save or locate the OAS

OpenAPI-to-GraphQL relies on the OpenAPI Specification (OAS) of an existing API to create a GraphQL interface around that API. OpenAPI-to-GraphQL can also retrieve a web-hosted OAS.

If you are using LoopBack, you can simply copy the URL location of the web-hosted OAS, which should be located at http://localhost:3001/openapi.json after starting the API.

# in the LoopBack project folder:
npm start

If you want to generate a GraphQL interface for another API, make sure that API is running and proceed in the same way or save the OAS.

Start GraphQL server

Once OpenAPI-to-GraphQL is installed and the OAS is obtained, you can create and start the GraphQL server. The created GraphQL server is then accessible by default at http://localhost:3000/graphql.

You can specify a local file containing the OAS specification or a remote url such as http://localhost:3001/openapi.json.

openapi-to-graphql <OAS JSON file path or remote url>