Tips > Building Workflows

Use the GraphQL Node for Precise Data Fetching

When an API supports GraphQL, use it instead of REST.

When an API supports GraphQL, use it instead of REST. GraphQL lets you request exactly the fields you need in a single request, eliminating over-fetching (receiving 50 fields when you need 3) and under-fetching (needing a second request to get related data). The HTTP Request node works fine for GraphQL, but the dedicated approach makes queries more readable.

Real-world example: You need to fetch GitHub pull requests with their reviews and check statuses. With REST, this requires 3 separate API calls per PR. With GraphQL, it is one request.

How do you send a GraphQL query from n8n?

URL:     https://api.github.com/graphql
Method:  POST
Headers:
  Authorization: Bearer {{ $credentials.githubToken }}
Body:

GraphQL Request Body

{
  "query": "query($owner: String!, $repo: String!) { repository(owner: $owner, name: $repo) { pullRequests(last: 10, states: OPEN) { nodes { number title createdAt author { login } reviews(last: 5) { nodes { state author { login } } } commits(last: 1) { nodes { commit { statusCheckRollup { state } } } } } } } }",
  "variables": {
    "owner": "my-org",
    "repo": "my-repo"
  }
}

Response: Everything in One Request

{
  "data": {
    "repository": {
      "pullRequests": {
        "nodes": [
          {
            "number": 142,
            "title": "Add user authentication",
            "createdAt": "2025-01-14T09:00:00Z",
            "author": { "login": "developer123" },
            "reviews": {
              "nodes": [
                { "state": "APPROVED", "author": { "login": "reviewer1" } }
              ]
            },
            "commits": {
              "nodes": [
                {
                  "commit": {
                    "statusCheckRollup": { "state": "SUCCESS" }
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }
}

What's the difference between REST and GraphQL for this request?

Compare the data volume:

REST vs GraphQL Comparison

REST approach:
  Request 1: GET /repos/{owner}/{repo}/pulls      -> 50 KB (all PR fields)
  Request 2: GET /repos/{owner}/{repo}/pulls/142/reviews -> 12 KB
  Request 3: GET /repos/{owner}/{repo}/commits/{sha}/status -> 8 KB
  Total: 3 requests, ~70 KB, 3 round trips

GraphQL approach:
  Request 1: POST /graphql (query above)           -> 2 KB response
  Total: 1 request, ~2 KB, 1 round trip

GraphQL is especially valuable for workflows that process many records, where the per-record overhead of multiple REST calls adds up to significant execution time and API rate limit consumption.

Related: Use Path Parameters in Webhook URLs for Dynamic Routing · Use Edit Fields in "Map Each" Mode for Simple Renames

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

190 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book an introductory call