Using Apollo to Query GraphQL from Node.js
The Apollo client library within a Node.js Express app can provide a middleman to a third-party endpoint, abstracting GraphQL queries and mutations without requiring direct access from the frontend JavaScript app. An Express application can use this middleman to forward requests to the third-party endpoint, handling authentication with custom headers as needed. The example uses the Apollo client library to create an HTTP link that injects node-fetch, providing a solution for scenarios where CORS headers are not provided by the third-party endpoint. The code also demonstrates how to generate valid JWT tokens and attach them to custom headers using the jsonwebtoken package. With this setup, requests can be sent to the Express application to retrieve data from the third-party endpoint.
Company
Vonage
Date published
Nov. 3, 2020
Author(s)
Michael Jolley
Word count
1361
Language
English
Hacker News points
None found.