Barelydead / strapi-plugin-populate-deep

A Strapi plugin that makes it easier to populate deep content structures
172 stars 39 forks source link

Strapi v5 rc15 gives validation error #53

Open NEDDL opened 1 week ago

NEDDL commented 1 week ago

Strapi v5.rc15 started giving this Validation Error: Screenshot 2024-09-06 at 13 19 51

NEDDL commented 1 week ago

Related feature https://github.com/strapi/strapi/pull/21034

innerdvations commented 1 week ago

Hello from Strapi!

For some guidance on migrating the plugin to Strapi 5, plugins should start handling cases like this with document service middlewares, taking the "invalid" parameter from the user request and converting it into a valid query. I assume it's already doing something very similar internally, you would just need to update the layer in which it's done.

Content API queries for deep-populate could be sent in a parameter such as ?deeppopulate=5

The deep populate plugin would add document service middleware such as:

strapi.documents.use((ctx, next) => {
   if(ctx.params.deeppopulate) {
     ctx.params.populate = getDeepPopulateQuery(ctx);
   }
   return next();
})

if you run into any issues because it attempts to populate fields the user doesn't have access to (again, I'm not sure how it's developed internally, perhaps you already have a check for this), you could generate the populate query, and then run it through the query sanitizer utility which will remove restricted relations from the query.

NEDDL commented 1 week ago

I forked this plugin to change the param so it wouldn't get stuck in the validation: https://github.com/NEDDL/strapi-v5-plugin-populate-deep

Can be used directly from the NPM package: https://www.npmjs.com/package/strapi-v5-plugin-populate-deep