Definition

Nested queries allow fetching related data by selecting fields that return other object types and specifying their subfields.


Core Concept

If a field returns an object or list of objects, you can query its fields inside the parent query.

This enables retrieving hierarchical data in a single request.


Basic Example

query {
  user(id: "1") {
    id
    name
    posts {
      title
    }
  }
}

Response Structure

{
  "data": {
    "user": {
      "id": "1",
      "name": "Zeeshan",
      "posts": [
        {
          "title": "GraphQL Intro"
        }
      ]
    }
  }
}

Multi-Level Nesting

query {
  user(id: "1") {
    name
    posts {
      title
      comments {
        content
      }
    }
  }
}

Execution Model