OASGraph (git, npm library, npm CLI) began with a simple idea. In response to the quickly growing popularity of GraphQL, we wondered: “How can we make GraphQL more accessible?” Now, that dream is a reality with the release of OASGraph, a tool that can wrap RESTful APIs defined with Open API Specification (OAS) with GraphQL.
Perhaps you are an API provider who wants to dive into GraphQL without the overhead needed to develop a GraphQL interface from scratch. This tool is for people like you, and we wanted to make the process of creating a GraphQL API as easy as possible. To do so, we start with a preexisting RESTful API and its OAS. With OASGraph, we can get you started instantly. For each operation in the OAS, OASGraph will create a GraphQL object which will resolve on the original REST API. If the OAS contains link objects, OASGraph will create additional fields that will enable the powerful nested queries that make GraphQL famous. Along with these features, OASGraph automatically sanitizes the API, provides outlets for authentication and OAuth, and supports custom request options.
We decided to work with LoopBack to help us open source OASGraph. LoopBack, an easy-to-use CLI-based API-creation tool with OAS support, seemed like a match made in heaven. With this partnership, LoopBack users can seamlessly produce GraphQL interfaces for their APIs. That said, OASGraph is not limited to LoopBack APIs! OASGraph can create a GraphQL interface for any RESTful APIs with a valid OAS. To get the best results, add link objects in the OAS so OASGraph can identify relationships between different objects and support nested queries.
Please visit our Github repository where you can find multiple tutorials to get started:
If you want to get started right away, just install the module, run the CLI tool, and go to http://localhost:3001/graphql, where you will find a server hosting your GraphQL interface. It’s as easy as pie!
# Install the module $ npm i -g oasgraph-cli # Create a GraphQL server $ oasgraph <OAS JSON file path or remote url> [port number]
If you like what you see, incorporate the library function
createGraphQlSchema(oas) directly into your projects. And now that we’re open source, feel free to help us improve OASGraph!