Sitecore Community GraphQL Cookbook

Build site navigation

This sample query combines finding the site root with the ability to traverse item children. You can use the hasLayout argument to find only items with layout (navigable pages) and the includeTemplateIds argument to filter on a (base) data template.
Source: Sitecore
    Sitecore DocumentationSample ComponentDelivery API

Query


JSON Response

1{
2  "data": {
3    "layout": {
4      "item": {
5        "pageTitle": {
6          "value": "Welcome to Sitecore JSS"
7        },
8        "url": {
9          "path": "/"
10        },
11        "children": {
12          "results": [
13            {
14              "pageTitle": {
15                "value": "GraphQL | Sitecore JSS"
16              },
17              "url": {
18                "path": "/graphql"
19              },
20              "children": {
21                "results": [
22                  {
23                    "pageTitle": {
24                      "value": "Sample 1 Page Title"
25                    },
26                    "url": {
27                      "path": "/graphql/sample-1"
28                    }
29                  },
30                  {
31                    "pageTitle": {
32                      "value": "Sample 2 Page Title"
33                    },
34                    "url": {
35                      "path": "/graphql/sample-2"
36                    }
37                  }
38                ]
39              }
40            },
41            {
42              "pageTitle": {
43                "value": "Styleguide | Sitecore JSS"
44              },
45              "url": {
46                "path": "/styleguide"
47              },
48              "children": {
49                "results": [
50                  {
51                    "pageTitle": {
52                      "value": "Custom Route Type | Sitecore JSS"
53                    },
54                    "url": {
55                      "path": "/styleguide/custom-route-type"
56                    }
57                  }
58                ]
59              }
60            }
61          ]
62        }
63      }
64    }
65  }
66}