Querying with GraphQL

Postman can make HTTP calls using GraphQL, an open-source data query and manipulation language for APIs, in addition to REST.

There are a few ways for you to author and send a GraphQL query using Postman:

Using Postman's built-in support for GraphQL

Postman has built-in support for sending GraphQL queries in the request body, using GraphQL variables, importing GraphQL schemas, and enabling GraphQL query autocompletion.

Sending GraphQL queries in the request body

  1. Open a new request tab in Postman and enter your GraphQL endpoint URL in the address field.
  2. Select POST from the request method dropdown list.
  3. Under the Body tab, select the GraphQL body type.
  4. Enter your GraphQL query in the Query editor. This editor enables you to author and edit both queries and variables separately.

Select the GraphQL body type

Using GraphQL variables

  1. Enter your GraphQL variables in the GraphQL variables editor.
  2. In the Query editor, declare your GraphQL variable in your GraphQL query. For more information on how to use GraphQL variables, see the GraphQL variables documentation.

Using GraphQL variables

You can also use Postman variables as data inputs for GraphQL variables using {{variable}} syntax.

Importing GraphQL schemas

To enable autocompletion, you need to add a GraphQL schema. To create or import a GraphQL schema into Postman:

  1. Select APIs in the left sidebar, then select + to create a new API.
  2. Enter a name and version for your API.
  3. Choose GraphQL from the Schema type dropdown list.
  4. Choose either JSON or GraphQL SDL from the Schema Format dropdown list.

    You can optionally select the Import tab to import an API specification directly from either a local file or a GitHub or Bitbucket repo. If you don't import a schema, Postman will populate your API with a sample specification you can edit at any time.

  5. Select Create API. Create a new API
  6. Open the new API's version page and navigate to the Definition tab. Type or paste your GraphQL schema in the editor.

Edit the API schema

Enabling GraphQL query autocompletion

Once you create or import a GraphQL schema as described above, you can enable autocompletion within the GraphQL query editor.

  1. Return to your GraphQL body. Select your schema from the dropdown list. You may need to refresh by selecting the Refresh icon refresh icon.
  2. Begin editing your query. Postman will now suggest autocomplete options from the data within your new GraphQL schema.

GraphQL autocomplete

Using JSON in the request body

  1. Open a new request tab in Postman and enter your GraphQL endpoint URL in the address field.
  2. Select POST from the request method dropdown list.
  3. In the Headers tab, add the Content-type of application/json.
  4. Under the Body tab, select the raw body type. Choose JSON from the format dropdown list.
  5. Construct your query in the request body using proper JSON formatting.

GraphQL JSON request body

Using a GraphQL content type header

  1. Open a new request tab in Postman and enter your GraphQL endpoint URL in the address field.
  2. Select POST from the request method dropdown list.
  3. In the Headers tab, add the Content-type of application/graphql. Set the content-type header
  4. Under the Body tab, select the raw body type. Choose Text from the format dropdown list.
  5. Construct your query in the request body using standard GraphQL formatting.

GraphQL query request body

Importing the query as a cURL request

  1. Select Import in the upper left.
  2. Select Raw text.
  3. Paste your cURL command in the text field, then Continue. Your cURL command must contain a GraphQL endpoint URL and must specify the POST request method. Import GraphQL request via cURL
  4. Select Import.
  5. The request will open in a new tab with the GraphQL endpoint URL you specified and the POST request method.

GraphQL response

Last modified: 2022/01/16