Include relationship component's children

Hello,

Struggling with the following so maybe someone can help.

I have my data set up in the following way.

Collection type of Page
Collection type of Form
Component (section) of type Form
Component of TextField

The Form component has a field of relationship, which is to the Form collection type. The Form component is being included in the Page via dynamic zone. Then in the Form collection type I have another dynamic zone which can have the TextField component.

At the moment if I go to /pages?slug=contact then I get the following result:

[
  {
    "id": 2,
    "slug": "contact",
    "shortName": "Contact",
    "status": "published",
    "created_at": "2021-04-04T10:42:56.655Z",
    "updated_at": "2021-04-04T11:22:11.133Z",
    "contentSections": [
      {
        "__component": "sections.form",
        "id": 1,
        "form": {
          "id": 1,
          "created_at": "2021-04-04T11:05:52.523Z",
          "updated_at": "2021-04-04T11:08:47.796Z",
          "title": "contact"
        },
        "title": "Contact Us"
      }
    ]
  }
]

Under form I am missing the next level of data (components) which can be seen below if I manually go to /forms/1

{
  "id": 1,
  "created_at": "2021-04-04T11:05:52.523Z",
  "updated_at": "2021-04-04T11:08:47.796Z",
  "title": "contact",
  "components": [
    {
      "__component": "form-fields.text-field",
      "id": 1,
      "name": "name",
      "type": "text",
      "placeholder": "Your full name",
      "label": "Name"
    }
  ]
}

How can I get that level of components to appear under the /page search? I believe it has something to do with the api/page/services/page.js file but I’ve tried all sorts in here and nothing seems to make it appear.

This is what I’ve tried and various versions of it:

module.exports = {
    find(params, populate) {
        return strapi.query('page').find(params, ['contentSections', 'contentSections.form', 'contentSections.form.components']);
      },
};

Any ideas?

2 Likes