Convert an OpenAPI specification to a GraphQL schema
Follow this tutorial to learn how to convert an OpenAPI specification to a GraphQL schema.
Our Self-Service APIs are stored as OpenAPI specs in this repository. In this tutorial, we will use the City Search API spec as an example and convert it to a GraphQL schema using openapi-to-graphql. While there are many similar tools available, the underlying principle remains the same.
The goal is to create a GraphQL schema and then utilise this schema for your GraphQL wrapper, regardless of the programming language your GraphQL server is written in.
Pre-requisites
Before you begin, you need to:
- Have Node.js installed on your machine.
Install the openapi-to-graphql tool
Download the required OpenAPI schema
Navigate to the amadeus-open-api-specification repository and download the required specification for your API. Alternatively, you can visit the Developers portal and download the specification from the page of a specific API.
Convert
For example, let's download the City Search API OpenAPI specification to the same directory where we run our project. We will then specify the name for the output file - schema.graphql
and execute the following command:
Access the generated schema
The schema is now created as schema.graphql
. For the City Search API, the contents will appear like this:
Import the schema to your code
Depending on the server that we use, we will now need to reference this schema. For example, in Node.js, you can use the Apollo Server library to create a GraphQL server: