S
S
Stepgor2020-07-09 19:52:23
Node.js
Stepgor, 2020-07-09 19:52:23

How to formulate the request body to Graphql using npm request?

There is a fetch post request in which the body is:

"{\"operationName\":\"add\",\"variables\":{\"id\":\"AAAAAAAAAA\",\"lang\":\"en\"},\"query\ ":\"GRAPHQL QUERY\"}"

How to convert this body to request-npm? Tried formData, form, qs but nothing worked

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-07-10
@Robur

Let's leave the question why are you torturing yourself in the presence of the coolest and most convenient libraries for working with graphql behind the scenes.
How to do it - create a valid HTTP request according to the specification. Too lazy to dig, but in my opinion there is just a post-request with a query in the form of json in the request body.

How to convert this body to request-npm?

no need, first try sending body as body
but nothing worked

Nothing at all? even the computer wouldn't boot up and the display wouldn't turn on? or all such did not work something more specific than "nothing"?
Tried formData, form, qs,

Brute-force programming is a job for the immortals. If you do not have thousands of years of life ahead of you, but less, like everyone else, then the most effective way is to read how it should be , then see what is wrong with you and fix
Take postman and make this request in it. As soon as it works - you will have an example of what needs to be done in request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question