How can we access the fields of a component that are dynamically added ( based on an API request in custom fields)?

System Information
  • Strapi Version: 4.11.7
  • Operating System: macos
  • Database: - mongo
  • Node Version: - v16.14.2
  • NPM Version: - 8.5.0
  • Yarn Version: - 1.22.18

Context:

I have a custom component ( autocomplete with list of options from external api ) that allows me to select an option based on an API request. After the selection, the body of the option becomes part of the structure and looks like this (where ‘type’ is a field of the custom component):

Grapql response:

{
  "data": {
    "newsCollection": {
      "data": [
        {
          "id": "23",
          "attributes": {
            "type": [
              {
                "id": "DSDSD",
                "name": "DSADASDASD",
                "name2": "DSADASDASD",
              },
              {
                "id": "DSDSD3",
                "name": "DSADASDASD",
                "name2": "DSADASDASD",
              }
            ]
          }
        }
      ]
    }
  }
}

When I try to make a GraphQL request to selectively get the fields of this component, or to filter by nested fields ( name, name2, id ), I run into a problem that GraphQL doesn’t know these fields exist because it identifies the component as JSON.

Example:

query Test(
    $filters: NewsFiltersInput
    $pagination: PaginationArg = {}
    $sort: [String] = []
    $publicationState: PublicationState = LIVE
){
 newsCollection(
      filters: $filters
      pagination: $pagination
      sort: $sort
      publicationState: $publicationState
    ) {
  data {
    id
    attributes {
     type {
       ..... I can't identify fields here 😞
     }
    }
  }
}
}

Is there a way to solve this problem in Strapi? :pray:


To be more precise, how to filter by fields and get the fields that are in the json type field?

I did not find a way to redefine the type to custom, but only to extend (