Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev guideRecipesAPI Reference
Dev guideUser GuidesLegal TermsNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Parent and child queries

🚧

This feature is deprecated

The _children is deprecrated and replaced in favor of _link, see Joins with Linking.

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

Example:

The following example shows the parent query is used with the StartPage schema, and the child query is used with the BiographyPage schema.

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

Response

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

The following example shows the parent query is used with the BloglistPageType schema, and the child query is used with the BlogitemPageType schema. So for every matching parent item in the blog list, the items for each parent are retrieved and shown in a single response. 

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