Send requests
GraphQL requests
How to write a GraphQL query with its variables, and what Luvin sends to the server.
A GraphQL request sends a query or a mutation to a GraphQL endpoint. Use it when the API you are testing speaks GraphQL instead of REST.
Example
Section titled “Example”A public GraphQL API of countries. Create a GraphQL request, write the URL https://countries.trevorblades.com/graphql and this in the Query tab:
query Country($code: ID!) { country(code: $code) { name capital currency }}In Variables:
{ "code": "CL"}Press Send. The status is 200 OK and the Body is:
{"data":{"country":{"capital":"Santiago","currency":"CLF,CLP","name":"Chile"}}}Create a GraphQL request
Section titled “Create a GraphQL request”- In the sidebar, click New request under your collection.
- In the New request dialog, choose GraphQL.
- The request opens with the name New GraphQL query. In the sidebar it has a GQL badge.
Write the query
Section titled “Write the query”- Write the URL of the GraphQL endpoint, for example
https://api.example.com/graphql. - In the Query tab, write the query or the mutation.
- In the Variables tab, write the variables as JSON.
- Press Send (⌘/Ctrl + Enter). The response appears below, as for any HTTP request.
A query with one variable:
query Country($code: ID!) { country(code: $code) { name capital currency }}And its variables:
{ "code": "CL"}The request screen has four tabs:
| Tab | What it holds |
|---|---|
| Query | The query or the mutation. |
| Variables | A JSON object with the variables of the query. A new request starts with {}. |
| Headers | The same table as in an HTTP request, with the automatic headers. |
| Authorization | The same options as in an HTTP request. A new GraphQL request inherits the authorization of the collection. |
There is no Params tab and no Body tab: the body is built from the query and the variables.
What Luvin sends
Section titled “What Luvin sends”Luvin sends one POST to the URL, with a JSON body that holds the query and the variables:
{ "query": "query Country($code: ID!) { country(code: $code) { name capital currency } }", "variables": { "code": "CL" }}- The
Content-Typeheader isapplication/json, unless you write your own in Headers. - If the Variables tab is empty, the body has no
variables. - Environment
{{variables}}and generators are replaced in the URL, the query, the variables and the headers before sending.
To see exactly what went out, open Sent request in the response.
Read the response
Section titled “Read the response”The response area is the same as for an HTTP request: status, time and size, then Body, Headers, Cookies and Sent request.
Limits
Section titled “Limits”- A GraphQL request cannot be dragged into a workflow as a step. Only HTTP requests can.
- Pasting a cURL command into the URL field does not convert it. Use an HTTP request for that.