Interact with any GraphQL API.

graphql-request-header

The GraphQL Request Action allows you to seamlessly interact with any GraphQL API by sending queries or mutations, including headers and authentication information. This action simplifies the process of making GraphQL requests and handling responses within your flows.

Usage

Within the Action, you can specify any GraphQL endpoint you want to fetch data from.

Inside the Configure Query modal, you can specify your GraphQL query or mutation, as well as define any variable you need to use inside your request. Check out the official GraphQL Documentation if you need some more information on how to write a GraphQL query.

Additionally, you can also set your authentication or any request headers that you need.

Using Variables

Variables within the GraphQL query work by using the Variables drawer at the bottom of the Edit Request modal. As an example lets imagine that we have a route for fetching Rick & Morty characters via the https://rickandmortyapi.com GraphQL API and we filter these results by the name that we pass in via an query parameter to the fastgen route.

We would then enter the https://rickandmortyapi.com/graphql as the url of the GraphQL action and then start of by defining a mapping to make the name query parameter accessible within the query syntax.

Variables
{
  "name": "{{$query.name}}"
}

Now that we have defined where the variable is coming from, we can specify the Query as

Query
query Query($name: String) {
  characters(filter: { name: $name }) {
    info { count }
    results { name }
  }
}

The first line of the query defines that we are gonna in a variable called name of type string for which we just created a mapping. On the next line we then use the variable to filter all records using that name.

If we now call our fastgen route and pass in the name in the query either by specifying it in the url like /rickandmorty?name=rick or by specifying it under URL Parameters > Query in the request modal of the fastgen debug mode, we can see all filtered records being returned.

Output

{
    "Status": 200,
    "Body": "" // String or already parsed if response content-type is 'application/json'
    "Header": { // Response header
      "Content-Type": "application/json",
      "...": "..."
    }
}