Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch children of node via webroot path in Gentics Mesh?

Tags:

gentics-mesh

I have a webroot path of a parent node and would like to return the children of this node. Using https://demo.getmesh.io/api/v1/demo/webroot/images/ for example just yields the node itself.

like image 965
Michael Bromley Avatar asked Jan 04 '23 05:01

Michael Bromley


2 Answers

Unfortunately it's not possible to do so with just the webroot. However, there're other ways to accomplish it:

  • Use the GraphQL-Enpoint by using this query for example:

    query childrenByWebroot($path: String) {
     node(path: $path) {
       uuid
       children {
         elements {
           uuid
         }
       }
      }
    }
    

    This will just load all UUIDs of the children and the parent. For more functionality, check the Docs of GraphQL for more information.

  • Load the Node from the webroot first and and then load the children via the Children-Endpoint: /api/v1/<project>/nodes/<uuid>/children

  • Search for Nodes which have the webroot-element as parent. This allows you to filter the content more clearly if it is required:

    {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "parentNode.uuid": "<uuid>"
              },
              // ... Other checks
            }
          ]
        }
      }
    }
    
like image 186
Dominik Avatar answered May 18 '23 00:05

Dominik


There is currently no way to load the children of a node via REST using a single request. You can however load the node of the path. Use the uuid of that node and load the children via /api/v1/:projectName/nodes/:nodeUuid/children

A much more elegant approach however would be to use the following graphql query. I highly recommend this option since it is more efficient when handling large datasets.

Background: Computing the totalCount / totalPage size is costly and you can avoid this by using hasPreviousPage and hasNextPage.

You can use the following graphql query:

query ($path: String) {
  node(path: $path) {
    children(perPage: 5) {
      hasNextPage
      hasPreviousPage
      currentPage
      elements {
        uuid
        fields {
          ... on vehicleImage {
            name
          }
        }
      }
    }
  }
}

Query variables:

{
  "path": "/images"
}
like image 26
Jotschi Avatar answered May 17 '23 23:05

Jotschi