API Design

GraphQL API Response JSON Example

A real-world JSON example of a GraphQL API response — including nested data, pagination with cursors, null errors field, and extensions for request tracing. Follows the GraphQL specification response format.

{
  "data": {
    "user": {
      "id": "usr_9k2mXpQr4t",
      "name": "Ravi Mehta",
      "email": "ravi.mehta@example.com",
      "posts": {
        "totalCount": 12,
        "pageInfo": {
          "hasNextPage": true,
          "hasPreviousPage": false,
          "startCursor": "cursor_xyz789",
          "endCursor": "cursor_abc123"
        },
        "edges": [
          {
            "cursor": "cursor_xyz789",
            "node": {
              "id": "post_1",
              "title": "Getting Started with GraphQL",
              "publishedAt": "2025-01-10T10:00:00Z",
              "tags": [
                "graphql",
                "api"
              ]
            }
          }
        ]
      }
    }
  },
  "errors": null,
  "extensions": {
    "requestId": "req_qA8mZ2",
    "duration": 42,
    "complexity": 8
  }
}

Field Reference

datarequiredobject | nullThe result of the GraphQL query. null if errors prevented execution.
errorsoptionalarray | nullArray of error objects if any field resolution failed. null when successful.
extensionsoptionalobjectProtocol extensions: request IDs, tracing, complexity scores.
data.user.posts.pageInforequiredobjectRelay-style cursor pagination info for the connection.
data.user.posts.pageInfo.hasNextPagerequiredbooleanWhether more items exist after endCursor.
data.user.posts.edges[].cursorrequiredstringOpaque cursor for this specific edge — used in after: argument.
data.user.posts.edges[].noderequiredobjectThe actual data object for this edge.

Variants

With errorsGraphQL partial response — data for resolved fields, errors for failed ones
{
  "data": {
    "user": {
      "id": "usr_9k2mXpQr4t",
      "name": "Ravi Mehta",
      "posts": null
    }
  },
  "errors": [
    {
      "message": "You do not have permission to view posts for this user",
      "locations": [
        {
          "line": 4,
          "column": 5
        }
      ],
      "path": [
        "user",
        "posts"
      ],
      "extensions": {
        "code": "FORBIDDEN"
      }
    }
  ]
}

Common Use Cases

  • Building GraphQL client code that handles both data and errors correctly
  • Mocking a GraphQL server for frontend development without a backend
  • Understanding Relay-spec cursor-based pagination for infinite scroll
  • Writing integration tests that assert on response shape and field values
  • Documenting your GraphQL API with concrete response examples
GraphQLAPIpaginationcursorresponse formatREST alternative

Validate or format this JSON

One click loads this exact example into the tool — no copy-paste needed. Format it, validate it, explore the tree, or generate TypeScript types instantly.

Frequently Asked Questions

The GraphQL spec separates HTTP transport from operation success. A 200 response means the HTTP layer worked. The errors array in the body tells you whether the GraphQL operation succeeded. This lets you return partial data — some fields resolved, others errored — in a single response.

If data is null, a non-recoverable error occurred before any field could be resolved. If data contains fields but errors is populated, it's a partial response — some fields resolved successfully and others failed. Always check both data and errors in your client code.

Offset pagination (skip: 20, take: 10) breaks when items are added or removed during pagination. Cursor pagination uses a stable pointer to a specific item — after: 'cursor_abc' always returns items after that item regardless of insertions. Relay's Connection spec formalizes cursor pagination with edges, nodes, and pageInfo.

Extensions is a free-form map for non-standard metadata. Common uses: requestId for distributed tracing, duration for performance monitoring, complexity for rate limiting by query cost, and cacheControl for per-field cache hints. The spec reserves this field specifically so clients and servers can extend GraphQL without breaking the spec.

Related JSON Examples