Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphql post body "Must provide query string."

I use Express-graphql middleware. I send the following request in the body line:

POST /graphql HTTP/1.1 Host: local:8083 Content-Type: application/graphql Cache-Control: no-cache Postman-Token: d71a7ea9-5502-d5fe-2e36-0ae49c635a29  {    testing {       pass(id: 1) {         idn       }     } } 

and have error

{   "errors": [     {       "message": "Must provide query string."     }   ] } 

in graphql i can send update in URL.

URL string is too short. i must send update model like

mutation {   update(id: 2, x1: "zazaza", x2: "zazaza", x3: "zazaza" ...(more more fields)...) {     idn   } } 

i think its must be in request body. How can i send 'update' query or that i'm doing wrong?

like image 573
Gopard Avatar asked Apr 18 '16 10:04

Gopard


People also ask

How do you send query as string in postman in GraphQL?

Open a new request tab in Postman and enter your GraphQL endpoint URL in the address field. Select POST from the request method dropdown list. In the Headers tab, add the Content-type of application/json . Under the Body tab, select the raw body type.

Can GraphQL be used for POST?

HTTP Methods, Headers, and BodyYour GraphQL HTTP server should handle the HTTP GET and POST methods.

Is GraphQL request always POST?

The GraphQL spec is itself transport-agnostic, however the convention adopted by the community has been to utilize POST requests. As pointed out in the comments, some libraries support GET requests. However, when doing so, the query has to be sent as a URL query parameter since GET requests can't have bodies.


2 Answers

Post request needs to manage headers info.

  1. Using Http client: Content-Type application/json

  2. Using Postman client: Content-Type application/graphql

but request body looks like string

{"query":"mutation{update(id:1,x1:\"zazaz\",x2:\"zazaz\"......){id x1 x2}}"} 
like image 200
Gopard Avatar answered Sep 23 '22 15:09

Gopard


If you are using graphql and want to test it using postman or any other Rest client do this.

In postman, select POST method and enter your URL and set Content-Type as application/graphql then pass your query in the body.

Example:

http://localhost:8080/graphql Mehtod: POST Content-Type: application/graphql Body:    query{     FindAllGames{     _id     title     company     price     year     url    }  } 

Thats it you will get the response.

enter image description here

like image 27
Prasanth Jaya Avatar answered Sep 22 '22 15:09

Prasanth Jaya