barelydead / strapi-plugin-populate-deep Goto Github PK
View Code? Open in Web Editor NEWA Strapi plugin that makes it easier to populate deep content structures
A Strapi plugin that makes it easier to populate deep content structures
Currently trying to filter and deep populate. Adding filters brakes puplate=deep
Example query
http://localhost:1337/api/experiences?populate=deep,10
π works perfectly
http://localhost:1337/api/experiences?filters[slug][$eq]=my-slug&populate=deep,10
π not working
Thanks in advance for this plugin. Strapi should work like this by default
I see you have Node 20 merged into main. Is it possible to release that version so it can be used now that Node 20 is LTS? Thanks!
Hi, it seems like it is not possible to set a depth larger than 5 in version 3.0 with Strapi v4.12.1
Here is my config:
module.exports = ({ env }) => {
return {
"strapi-plugin-populate-deep": {
config: {
defaultDepth: 6,
},
},
};
};
I have also tried ?populate=deep,6 to no effect.
I would love to see something like "select: []" array in configuration file to choose what attributes should be returned by api. This array could be injected in your getFullPopulateObject function. Right now it can be done by setting privateAttributes for collection types, but it not possible to set it for media response so funcionalitty like this could provide possiibilities to reduce media object response.
It would be nice to be able to exclude a relationship which you know is going to return a lot of unneeded data at the default depth.
Output of strapi develop
[2022-03-15 09:53:09.318] error: Could not load js config file /Users/bob/code/xxx-strapi/node_modules/strapi-plugin-populate-deep/strapi-server.js: Unexpected token '.'
Hi, first of all, great plugins!
But I just realized that when I use deep, with i18n plugin, we cannot avoid end up a large response bc localizations list are nested into another content, then another content. I wonder if it's possible that we have some exclude logic that to not deep certain fields?
Hi
I've encountered an issue where one of our component isn't being populated (there's a missing "cover" media field) no matter what depth we specify. The said component is in a dynamic zone.
The strange thing is that the bug occurs on a singleType that is almost the duplication of another collectionType that is working perfectly.
Here is the definition of the faulty singleType
{
"kind": "singleType",
"collectionName": "homepages",
"info": {
"singularName": "homepage",
"pluralName": "homepages",
"displayName": "π Homepage",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {
"url-alias": {
"enabled": false
}
},
"attributes": {
"definition": {
"type": "string",
"required": true
},
"featuredlink": {
"type": "component",
"repeatable": false,
"component": "texts.button"
},
"hero": {
"type": "media",
"multiple": false,
"required": true,
"allowedTypes": [
"images"
]
},
"title": {
"type": "string",
"required": true
},
"content": {
"type": "dynamiczone",
"components": [
"data.custom-editorial-list",
"data.custom-project-list",
"data.editorial-list",
"data.event-list",
...
]
}
}
}
The component data.custom-project-list
is missing it's cover field.
I've switched the homepage into a collectionType without any success.
In any case does the populate param include this : [content][populate][items][populate][cover]=true
The "working" collectionType has the same dynamic zone with the same components, same name (content), just different fields around...
I've forked the plugin and traced everything, I cannot understand the differences between my two content-types in terms of behavior from the plugin...
Does anyone has any issue similar to this ?
When using the new option in content-type's schemas "populateCreatorFields": true, (see docs here) the plugin blocks population due to :
server/helpers/index.js, lines 16-18
if (modelUid === "admin::user") {
return undefined;
}
because you explicity drop any info related to "admin::user".
Can you please update your plugin by dropping these 3 lines to allow population?
I have deleted these 3 lines inside your files in my node_modules folder and this works perfectly.
Thanks!
Hey, first things first: thanks alot for the small but REALLY helpful plugin.
I tried installing it and neither npm nor yarn could find the package in their repo.
After searching directly on npmjs.com I found out that your README just includes the wrong package names (deep-populate
instead of populate-deep
:
IS:
npm install strapi-plugin-deep-populate
yarn add strapi-plugin-deep-populate
SHOULD BE:
npm install strapi-plugin-populate-deep
yarn add strapi-plugin-populate-deep
Hi, Hello,
we use Strapi and your plugin in combination with plugin for internationalization - https://docs.strapi.io/developer-docs/latest/plugins/i18n.html
According to doc you should as for localizations in request to be send back in response. But we get the object "localizations" even if we do not ask for it.
I have strong suspicion that usage of your plugin caused that we have unwanted objects in response.
Could you add to your plugin check if localizations are requested before they are populated deeply and send back to the caller party please?
We use Strapi v4.3.4 and latest version of all plugins. If necessary, I will provide additional information later.
Thank you.
Required System information
Node.js version: v14.15.4
NPM version: 6.14.16
Strapi version: 4.2.0
Database: Postgres : 8.6.0
Operating system: ubuntu 18.10
Population of deep content structures using slug.Any examples?
http://localhost:1337/api/articles/128?populate=deep,2 , works perfectly
http://localhost:1337/api/articles/new-slug?populate=deep,10, when id is replaced with slug it is not working as expected.
In the first level of the response, components have the key __component, containing the component identifier. This key is really useful when doing contain generation. But this key is not present on nested component. Do you know a good way tho add this key on nested component ?
Cheers. π
I am currently updating my strapi project to use node v18, but I am getting an unsupported engine warning when running npm install
. Is it a hard failure or can this be upgraded to also support up to node v18?
I can't say how much I appreciate this plugin!!!
The population system by strapi default is extremely confusing and frustrating especially when you get to dynamic components with media items. This capability needs to get merged back into strapi.
I went from this.
'populate[authors][populate]': '',
'populate[seo][populate]': '',
'populate[thumbnail][populate]': '',
'populate[alsoCheckout][populate]': '',
'populate[alsoCheckout][on][__articles.podcast]': '*',
which the thumbnail was still not loading to just thisβ¦
'populate': 'deep'
and it just works!
Thanks for maintaining as well.
Hi there,
I'm expanding Strapi 4's controllers to use some custom filtering. However, looking at the GitHub page, all of the example implementation appears to only include using the "?populate=deep" param on the initial request that gets sent to Strapi.
I would like to implement it in a custom controller. I'm using the Strapi QueryEngine, (Not the entityService, although they're pretty similar.).
For example, I'd like something along the lines of:
const onlyArticles = await strapi.db
.query("api::article.article")
.findMany({
where: {
.......
},
populate: 'deep'
});
Is this already possible? Or is it something not currently possible in this plugin?
Thanks in advance!
Let's say if have for example 4 components:
Component A and B - Child components
Component P1 and P2 - Parent components
component A fields:
component B fields:
Component P1 and P2:
These 2 components wrap component A and B respectively using the same field name as an input for components A and B.
When making the request to an entity with the deep populate, the image will not be populated.
It depends of the order the components were added. The populate will use the last component added.
As a workaround, when working with component nesting when the parent component has the same field name, we need to make sure that each field name is unique
Is there a way to set a maxDepth for the population? So that I can protect my server from being overload.
When I tried to set maxDepth=2 and tried with depth=10 (localhost:1337/api/articles/6?populate=deep,10), the API server seemed to be stuck.
I think it takes too much time processing that request and blocks other requests because the depth is too much.
Maybe I can use a policy to check for this but it would be nice if we support this feature in this plugin.
Plugin does not populate relational content nested inside a component or dynamic zone e.g.
Mycomponent -> title, description, category(one to one category)
Using https://market.strapi.io/plugins/strapi-plugin-populate-deep
Only populates title, description
but never populates the category
field
I attempted to introduce a 'createdBy' variable on my blog page to specify the author of each blog article. However, whenever I include an additional parameter after 'deep', I encounter a 'maximum call stack size' error.
Example usage:
router?path=/blog&populate=deep,createdBy
Example usage (this example doesn't cause an error, but the data is no longer retrieved):
router?path=/blog&populate=deep,10,createdBy
I am using this plugin as well as strapi-plugin-menus from @mattmillburn.
I actually have a lot of items (~280 items) inside my menu.
I am not able to use:
GET
/api/menus/1?nested&populate=deep
since it causes my app to crash due to a memory leak.
Here is the heroku error: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
.
I have a content type which has on to one relation (parent content type has one child content type) to another content type which in turn also have it's own relations multiple levels deep.
Now the parent content type has 2 fields for the child relation, one of them is being populated as expected, but the other is missing some of it's own relations.
I know that the levels of deepness is not an issue since one if the child relations is being populated properly and they are both on the same level, and they are both the same type
I know the configurations is not an issue since I was able to get the desired data populated properly when I tried Strapi's official guide on how to populate multiple relations multiple levels deep (via populate[child_type_1][populate][0]=child_of_child type&populate[child_type_2][populate][0]=child_of_child_type
)
So it's working as expected with Strapi's guide but with populate=deep
only one of the child_type-s is being populated fully, the other one is a bit weird because it has images, but one of the relations is missing from it
How to replicate:
Expected behavior:
the relations are populated
Actual:
the relations are populated partially in one of the child types
Is there a way I can call populate deep without returning the localization data ?
I discovered some weird bug with naming.
I have a collection "pages".
it contains a dynamic zone (sections) with a few components.
For example there are four components:
All these components have another, the same repeatable component.
For some reason images are not populated in cards and instructions
you can see see the output from the api there:
https://cms.propera.ch/api/energy-pages/43?populate=deep,10
if I explicitly ask to populate sections.items.image - it returns the image for cards and instructions
https://cms.propera.ch/api/energy-pages/43?populate[0]=sections.items.image
but of course everything else is missing
What could be a reason?
Initially I blamed myself, then recently updated strapi, so I tried to downgrade it.
Finally I added one more repeatable field to "cards" and named it differently (cards:). and images start working for the field.
So I think that it's definitely because of the name "items".
of course I can rename it although it requires some extra work for me on the company web portal. :/
Hello,
We have some trouble when getting a lot of data with localisations.
I tried this patch (#12) directly on the server and it's made the job.
Is it ok for you to merge it or do i have to make a fork ?
Best regards.
Originally posted here by mistake: strapi/strapi#18577.
Essentially, the typings for the localizations field are incorrect.
However, unfortunately, while I can reproduce the correct state on our internal repo, I wasn't able to reproduce it on a fresh repo or on the internal if I delete the package-lock.json
. Whatever I try, it's just consistently broken now.
I think the latest addition for the ciruclar references introduces a case, where a relationship is ignored while populating if it is named the same as the collection.
E.g:
Collection named "Response" --> strapis plural is responses
The same collection as a field named "responses" which is not the same collection, just a list of values
--> It gets ignored since version 3.0.0
Thanks for the effort you put into this plugin. I love it and use it daily.
One thing i would like to see is deep population for the i18n localization of entries.
I found the same feature request in this strapi forum.
And also found this work around in another forum post. Although this is a valid solution i think this should be possible without the need of a custom controller, fetching the attributes of a deeper nested entity.
Thank you for any suggestions
Getting the following warning:
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '[email protected]',
npm WARN EBADENGINE required: { node: '>=12.x. <=16.x.x', npm: '>=6.0.0' },
npm WARN EBADENGINE current: { node: 'v16.17.0', npm: '8.19.2' }
npm WARN EBADENGINE }
So despite it being in the range noted it still invokes a warning. Not critical, but wanted to note.
It would be very nice to have an option to use the deep population only for specific fields/properties
Hi,
After installing this plugin via yarn yarn add strapi-plugin-populate-deep
, I get the following error when trying to start the development server:
ModuleNotFoundError: Module not found: Error: Can't resolve 'style-loader' in '/PROJECT_FOLDER/packages/cms'
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/Compilation.js:2011:28
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:795:13
at eval (eval at create (/PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:275:22
at eval (eval at create (/PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:538:15
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:124:11
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:609:8
at /PROJECT_FOLDER/node_modules/neo-async/async.js:2830:7
at done (/PROJECT_FOLDER/node_modules/neo-async/async.js:2925:13)
resolve 'style-loader' in '/PROJECT_FOLDER/packages/cms'
Parsed request is a module
using description file: /PROJECT_FOLDER/packages/cms/package.json (relative path: .)
resolve as module
looking for modules in /PROJECT_FOLDER/packages/cms/node_modules
single file module
using description file: /PROJECT_FOLDER/packages/cms/package.json (relative path: ./node_modules/style-loader)
no extension
/PROJECT_FOLDER/packages/cms/node_modules/style-loader doesn't exist
.js
/PROJECT_FOLDER/packages/cms/node_modules/style-loader.js doesn't exist
/PROJECT_FOLDER/packages/cms/node_modules/style-loader doesn't exist
/PROJECT_FOLDER/packages/node_modules doesn't exist or is not a directory
looking for modules in /PROJECT_FOLDER/node_modules
single file module
using description file: /PROJECT_FOLDER/package.json (relative path: ./node_modules/style-loader)
no extension
/PROJECT_FOLDER/node_modules/style-loader doesn't exist
.js
/PROJECT_FOLDER/node_modules/style-loader.js doesn't exist
/PROJECT_FOLDER/node_modules/style-loader doesn't exist
/node_modules doesn't exist or is not a directory
/Users/tom/Documents/node_modules doesn't exist or is not a directory
/Users/tom/node_modules doesn't exist or is not a directory
/Users/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
ModuleNotFoundError: Module not found: Error: Can't resolve 'style-loader' in '/PROJECT_FOLDER/packages/cms'
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/Compilation.js:2011:28
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:795:13
at eval (eval at create (/PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:275:22
at eval (eval at create (/PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:538:15
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:124:11
at /PROJECT_FOLDER/node_modules/@strapi/admin/node_modules/webpack/lib/NormalModuleFactory.js:609:8
at /PROJECT_FOLDER/node_modules/neo-async/async.js:2830:7
at done (/PROJECT_FOLDER/node_modules/neo-async/async.js:2925:13)
resolve 'style-loader' in '/PROJECT_FOLDER/packages/cms'
Parsed request is a module
using description file: /PROJECT_FOLDER/packages/cms/package.json (relative path: .)
resolve as module
looking for modules in /PROJECT_FOLDER/packages/cms/node_modules
single file module
using description file: /PROJECT_FOLDER/packages/cms/package.json (relative path: ./node_modules/style-loader)
no extension
/PROJECT_FOLDER/packages/cms/node_modules/style-loader doesn't exist
.js
/PROJECT_FOLDER/packages/cms/node_modules/style-loader.js doesn't exist
/PROJECT_FOLDER/packages/cms/node_modules/style-loader doesn't exist
/PROJECT_FOLDER/packages/node_modules doesn't exist or is not a directory
looking for modules in /PROJECT_FOLDER/node_modules
single file module
using description file: /PROJECT_FOLDER/package.json (relative path: ./node_modules/style-loader)
no extension
/PROJECT_FOLDER/node_modules/style-loader doesn't exist
.js
/PROJECT_FOLDER/node_modules/style-loader.js doesn't exist
/PROJECT_FOLDER/node_modules/style-loader doesn't exist
/node_modules doesn't exist or is not a directory
/Users/tom/Documents/node_modules doesn't exist or is not a directory
/Users/tom/node_modules doesn't exist or is not a directory
/Users/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
This is using strapi 4.2.2 with node 16.5.1
Thanks
When 1:n, n:1, n:n relations are involved, the plugin populates everything self-recursively (we haven't tested other scenarios yet). For Example, a collection of cities and stations, when a city has multiple stations, and the station belongs to one city, then the plugin populates as deep as it can in both directions (default 5). Meaning the result (simplified) will look something similar to the example below. Instead the recursion should stop, once it tries to recurse into itself, meaning the recursion of a property / data should stop once it has already been recursed. I hope I am explaining it somewhat understandable. As far as I am aware, in real world examples there is (most of the time) no need to recurse / populate any further, once the final relation has been hit. +The depth functionality (default 5) might not be required anymore (or just as a hard fallback if everything goes wrong) and could be used optionally only if really needed. Maybe I am missing something, then let me know. Thanks for the great plugin, we are already using it, and we are only missing this one critical implementation to use it in production :) π
{
"cities": [
{
"cityname": "London",
"stations": [
{
"stationname": "Townhall",
"cities": [
{
"cityname": "London",
"stations": [
// ...and so on
]
}
]
}
]
}
]
}
Hello! It is not working for the Users-Permissions plugin routes. Can it be applied there too?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.