How to request a GraphQL API with Fetch or Axios
This article provides a comprehensive guide on how to request a GraphQL API using Fetch or Axios. It begins by explaining that GraphQL is just a query language and popular implementations leverage existing JSON standards for requests and responses over HTTP. The key components of a GraphQL request are the endpoint, headers, and request body in JSON format. The JSON body contains three objects: operationName (optional), query (the actual GraphQL query), and variables (an optional object used to pass dynamic values). The article then provides an example of a basic GraphQL query and demonstrates how to make a GraphQL API request using Fetch or Axios in JavaScript. It also explains how to handle errors in the response object. The author recommends checking out their open source tutorial on Introduction to GraphQL for those new to the technology.
Company
Hasura
Date published
Nov. 2, 2021
Author(s)
Praveen Durairaju
Word count
662
Hacker News points
None found.
Language
English