Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Parent and child queries

🚧

This feature is deprecated

The _children field is deprecated and is replaced by _link. See Joins with linking. _children continues to work throughout 2025.

Use parent-child queries in Optimizely Graph to retrieve a parent document and its related child documents in one request, so you can render hierarchical content (such as a landing page and its blog posts) without chained calls.

When a parent-child relationship exists between GraphQL schemas, create a single query to retrieve parent documents and their children's documents using a special field in the projection called _children. With _children, formulate the child query with the child schema using arguments similar to regular GraphQL queries.

Example

The following examples show how a single query returns parent documents alongside their child documents using the _children projection. The first uses the StartPage schema for the parent and the BiographyPage schema for the child.

{
  StartPage(locale: en) {
    total
    items {
      _children {
        BiographyPage {
          items { 
            Name
          }
        }
      }
      Name
    }
  }
}

Response

The response below shows the shape Graph returns for the previous query, with the child BiographyPage items nested under each StartPage parent.

{
  "data": {
    "StartPage": {
      "total": 4,
      "items": [
        {
          "_children": {
            "BiographyPage": {
              "items": [
                {
                  "Name": "Abraham Lincoln"
                }
              ]
            }
          },
          "Name": "Start"
        }
      ]
    }
  },
  "extensions": {
    "requestId": "4b45a5b3-f905-4824-b903-5b9180376837",
    "responseTime": 111
  }
}

The next example uses the BloglistPageType schema for the parent and the BlogitemPageType schema for the child. For every matching parent item in the blog list, Graph retrieves and returns the items for each parent in a single response.

{
  BloglistPageType(locale: en, where: {Title: {startsWith: "Optimizely"}}) {
    items {
      Name
      Language
      _children {
        BlogitemPageType(where: {Created: {lt: "2019"}}) {
          items {
            Name
          }
        }
      }
    }
  }
}