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

<p>In this short article, let&rsquo;s look at how we could create a simple graphQL query that fetches data from a RESTful endpoint. We&rsquo;ll use Node.js and Apollo Server for this purpose.</p> <p>In this article, we&rsquo;ll look at a simple&nbsp;<code>Users</code>&nbsp;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.</p> <h2>More content at&nbsp;<a href="https://plainenglish.io/" rel="noopener ugc nofollow" target="_blank">PlainEnglish.io</a>.</h2> <p><em>Sign up for our&nbsp;</em><a href="http://newsletter.plainenglish.io/" rel="noopener ugc nofollow" target="_blank"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on&nbsp;</em><a href="https://twitter.com/inPlainEngHQ" rel="noopener ugc nofollow" target="_blank"><strong><em>Twitter</em></strong></a>,&nbsp;<a href="https://www.linkedin.com/company/inplainenglish/" rel="noopener ugc nofollow" target="_blank"><strong><em>LinkedIn</em></strong></a><strong><em>,&nbsp;</em></strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw" rel="noopener ugc nofollow" target="_blank"><strong><em>YouTube</em></strong></a><strong><em>, and</em></strong><em>&nbsp;</em><a href="https://discord.gg/GtDtUAvyhW" rel="noopener ugc nofollow" target="_blank"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p> <h2>Looking to scale awareness and adoption for your tech startup? Check out&nbsp;<a href="https://circuit.ooo/?utm=publication-post-cta" rel="noopener ugc nofollow" target="_blank">Circuit</a>.</h2> <p>This might come in handy if you&rsquo;d want to give the consuming client more control over which fields are to be projected in the response.</p> <p>Without further ado, let&rsquo;s get started:</p> <h1>Initialize The GraphQL Project:</h1> <p>Let&rsquo;s create a new directory named&nbsp;<code>gserver</code>&nbsp;and then change the directory by typing&nbsp;<code>cd gserver</code>.</p> <p>Now let&rsquo;s initiate the project with&nbsp;<code>yarn init -y</code></p> <h2>Add Dependencies:</h2> <p>Our primary dependencies are graphQL and apollo-server packages. So let&rsquo;s add them to the project</p> <p><a href="https://javascript.plainenglish.io/create-a-graphql-query-with-a-rest-endpoint-as-a-data-source-fc21ae95a441">Click Here</a></p>