apostrophecms / apostrophecms/apostrophe

apostrophe-pages data object returns an empty array under the "_children" key, even after configuration

Open
#2,092 11 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
4.6k
Forks
650
Avg merge
19h 21m
Merged PRs (30d)
23

Description

Currently running version ^2.91.0 of Apostrophe in my project running on Node 12.1.0. I'm using Apostrophe as my headless backend, feeding data to my separate front end application. I am trying to access the children of apostrophe-pages to appear in my data object, however the _children array always returns as an empty array. My pages have 4 levels of child pages and they are all set up in the front end. I specifically need to access the time stamp of "CreatedAt" and "UpdatedAt" of all the children which is why fetching data from "api/v1/apostrophe-pages?all=true&hideOrphans=true" does not suffice as it only returns limited information. Fetching every child via their _id does not seem like the most viable option when fetching volumes deep. If there is a way to access all the children from their top parent level, that would be the most optimal in this case.

My index.js for the lib/modules/apostrophe-pages module contains the following:
` addFields: [
{
name: '_pages',
type: 'joinByArray',
withType: 'apostrophe-page',
label: 'Pages',
idsField: 'pageIds',
filters: {
children: {
depth: 4,
areas: false
},
projection: {
title: 4,
slug: 4,
rank: 4,
level: 4,
path: 4
}
}
}
]`

I even tried passing '1' as it says to do in the docs and still only returns an empty array under the "_children" key when logging out data.

and I have the following in my app.js file:
`'apostrophe-pages': {
filters: {
ancestors: {
children: {
depth: 4
}
},
children: {
depth: 4
}
},`

No matter what I try, I still get "_children: [ ]" back from my logs. How can I get the _children key to populate accurately as my navigation tree shows?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the empty _children result using lib/modules/apostrophe-pages/index.js, the apostrophe-pages configuration in app.js, and the api/v1/apostrophe-pages?all=true&hideOrphans=true endpoint. Trace how the children and ancestors filters are applied to the headless response, then verify that a top-level page returns its descendants with the requested timestamps.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.