What’s the advantages of pre-fetching the GraphQL schema when we can manually pass data to request body?

What’s the advantages of pre-fetching the GraphQL schema when we can manually pass data to request body?


0

Foreword: I am completely new to GraphQL so I am just trying to figure out what is the best practice when working with it

So I need to call a GraphQL API written in Nestjs (more specifically, from a Rails server).
There is this nice gem graphql-client that makes a Client to communicate with GraphQL API.
In order for it to work, it needs a Schema before initializing the Client. It also suggest that we should fetch the schema and dump it into a file before initializing the Client

I also notice that, when I paste the GraphQL URL to postman, it pre-fetch the schema.

A quick code snippet worked. But later I found out that I can just use an API gem (like HTTParty) and make a POST request with correct body in order to call the GraphQL API

I thought: "maybe I should investigate how other JS tools work with GraphQL because Rails may behave differently". I then read this article. In short, we can just use an API library (like axios) to make request to the GraphQL server, without the need or pre-fetching schema.

My questions is: Why do we need to pre-fetch the schema before making request? What is the advantages of that? If there is any articles I should read in order to have a better understanding of this, please kindly provide me.


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *