Make an HTTP call with GraphQL

Postman's GraphQL client is tailored for making GraphQL requests, but you can also create GraphQL requests using Postman's HTTP request interface. The HTTP request interface might be better for some use cases, like working with legacy systems or projects that include both GraphQL and non-GraphQL APIs.

Use Postman's HTTP request for GraphQL

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

Send GraphQL queries in the HTTP request body

  1. Select New > HTTP and enter a GraphQL endpoint URL in the URL box.

  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. The editor enables you to write and edit queries and variables separately.

  5. Select Send.

    Select the GraphQL body type

Use GraphQL variables

  1. Enter your GraphQL variables in the GraphQL variables editor.

  2. In the Query editor, declare the GraphQL variable in your 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.

Import GraphQL schemas

To enable autocompletion while writing queries, your request needs a GraphQL schema. When you enter a GraphQL endpoint URL in the URL box, Postman automatically fetches the GraphQL schema using introspection. When Postman successfully auto-fetches a schema, a notification appears next to the schema selection list. If your schema has changed, select the refresh icon Refresh icon to pull in the changes.

GraphQL auto-fetch schema

You also have the option to manually import a schema into your request. After creating or importing a GraphQL API into your workspace, you can use that API's schema for your request instead of the auto-fetched schema.

To import a GraphQL schema into your request manually, do the following:

  1. Create or import a GraphQL API in your workspace.
  2. Select New > HTTP and enter a GraphQL endpoint URL in the URL box.
  3. Select POST from the request method dropdown list.
  4. Under the Body tab, select the GraphQL body type.
  5. Select the arrow next to Auto Fetch to open the schema selection dropdown list.
  6. Select your schema from the dropdown list.

You may need to refresh by selecting the refresh icon Refresh icon.

When you write your query, Postman suggests autocomplete options from the data in the selected GraphQL schema.

Use 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. Under 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

Use a GraphQL content type header

  1. Select New > HTTP and enter a GraphQL endpoint URL in the URL box.

  2. Select POST from the request method dropdown list.

  3. Under the Body tab, select the GraphQL body type.

  4. Under the Headers tab, add the Content-type of application/graphql.

    Set the content-type header
  5. Under the Body tab, select the raw body type. Choose Text from the format dropdown list.

  6. Build your query in the request body using standard GraphQL formatting.

    GraphQL query request body

Import the query as a cURL request

  1. Select Import.
  2. Paste your cURL command in the request bar. Your cURL command must contain a GraphQL endpoint URL and must specify the POST request method. Postman opens the request in a new tab with the specified GraphQL endpoint URL and the POST request method selected.

Last modified: 2023/11/15