Create a GraphQL Query With a REST Endpoint As a Data Source

In this short article, let’s look at how we could create a simple graphQL query that fetches data from a RESTful endpoint. We’ll use Node.js and Apollo Server for this purpose.

In this article, we’ll look at a simple Users resource as an example. The aim of this write-up is just to outline the steps and configurations required to create a query that utilizes an existing REST endpoint as its data source, using the apollo graphQL server.

More content at PlainEnglish.io.

Sign up for our free weekly newsletter. Follow us on TwitterLinkedInYouTube, and Discord.

Looking to scale awareness and adoption for your tech startup? Check out Circuit.

This might come in handy if you’d want to give the consuming client more control over which fields are to be projected in the response.

Without further ado, let’s get started:

Initialize The GraphQL Project:

Let’s create a new directory named gserver and then change the directory by typing cd gserver.

Now let’s initiate the project with yarn init -y

Add Dependencies:

Our primary dependencies are graphQL and apollo-server packages. So let’s add them to the project

Click Here