如何通过 Gentics Mesh 中的 webroot 路径获取节点的子节点?
How to fetch children of node via webroot path in Gentics Mesh?
我有一个父节点的 webroot 路径,想 return 这个节点的子节点。
例如,使用 https://demo.getmesh.io/api/v1/demo/webroot/images/ 只会生成节点本身。
不幸的是,仅使用 webroot 无法做到这一点。但是,还有其他方法可以实现它:
使用 GraphQL-Enpoint 通过使用此查询例如:
query childrenByWebroot($path: String) {
node(path: $path) {
uuid
children {
elements {
uuid
}
}
}
}
这只会加载子项和父项的所有 UUID。有关更多功能,请查看 Docs of GraphQL 了解更多信息。
首先从 webroot 加载节点,然后通过 Children-Endpoint 加载子节点:/api/v1/<project>/nodes/<uuid>/children
Search for Nodes 以 webroot 元素为父元素。这允许您在需要时更清楚地过滤内容:
{
"query": {
"bool": {
"must": [
{
"term": {
"parentNode.uuid": "<uuid>"
},
// ... Other checks
}
]
}
}
}
目前无法使用单个请求通过 REST 加载节点的子节点。但是,您可以加载路径的节点。使用该节点的 uuid 并通过 /api/v1/:projectName/nodes/:nodeUuid/children
加载子节点
然而,更优雅的方法是使用以下 graphql 查询。我强烈推荐此选项,因为它在处理大型数据集时效率更高。
背景:计算 totalCount
/ totalPage
大小的成本很高,您可以使用 hasPreviousPage
和 hasNextPage
.[=29 来避免这种情况=]
您可以使用以下 graphql query:
query ($path: String) {
node(path: $path) {
children(perPage: 5) {
hasNextPage
hasPreviousPage
currentPage
elements {
uuid
fields {
... on vehicleImage {
name
}
}
}
}
}
}
查询变量:
{
"path": "/images"
}
我有一个父节点的 webroot 路径,想 return 这个节点的子节点。 例如,使用 https://demo.getmesh.io/api/v1/demo/webroot/images/ 只会生成节点本身。
不幸的是,仅使用 webroot 无法做到这一点。但是,还有其他方法可以实现它:
使用 GraphQL-Enpoint 通过使用此查询例如:
query childrenByWebroot($path: String) { node(path: $path) { uuid children { elements { uuid } } } }
这只会加载子项和父项的所有 UUID。有关更多功能,请查看 Docs of GraphQL 了解更多信息。
首先从 webroot 加载节点,然后通过 Children-Endpoint 加载子节点:
/api/v1/<project>/nodes/<uuid>/children
Search for Nodes 以 webroot 元素为父元素。这允许您在需要时更清楚地过滤内容:
{ "query": { "bool": { "must": [ { "term": { "parentNode.uuid": "<uuid>" }, // ... Other checks } ] } } }
目前无法使用单个请求通过 REST 加载节点的子节点。但是,您可以加载路径的节点。使用该节点的 uuid 并通过 /api/v1/:projectName/nodes/:nodeUuid/children
加载子节点然而,更优雅的方法是使用以下 graphql 查询。我强烈推荐此选项,因为它在处理大型数据集时效率更高。
背景:计算 totalCount
/ totalPage
大小的成本很高,您可以使用 hasPreviousPage
和 hasNextPage
.[=29 来避免这种情况=]
您可以使用以下 graphql query:
query ($path: String) {
node(path: $path) {
children(perPage: 5) {
hasNextPage
hasPreviousPage
currentPage
elements {
uuid
fields {
... on vehicleImage {
name
}
}
}
}
}
}
查询变量:
{
"path": "/images"
}