Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-plugin-populate-deep",
"version": "0.1.2",
"name": "strapi-plugin-populate-deep-with-params",
"version": "0.1.4",
"description": "This is the description of the plugin.",
"strapi": {
"name": "strapi-plugin-populate-deep",
Expand All @@ -18,7 +18,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/Barelydead/strapi-plugin-deep-populate"
"url": "https://github.com/jacopobonomi/strapi-plugin-deep-populate"
},
"engines": {
"node": ">=12.x. <=16.x.x",
Expand Down
2 changes: 1 addition & 1 deletion server/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = ({ strapi }) => {
const populate = event.params?.populate;

if (populate && populate[0] === 'deep') {
const depth = populate[1] ?? 5
const depth = populate[1] ?? process.env.DEFAULT_POPULATE_DEPTH ?? 5;
const modelObject = getFullPopulateObject(event.model.uid, depth);
event.params.populate = modelObject.populate
}
Expand Down
14 changes: 11 additions & 3 deletions server/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ const getModelPopulationAttributes = (model) => {
return model.attributes;
};

const getFullPopulateObject = (modelUid, maxDepth = 20) => {
const getFullPopulateObject = (
modelUid,
maxDepth = process.env.MAX_POPULATE_DEPTH ?? 20
) => {

if (maxDepth > process.env.MAX_POPULATE_DEPTH) {
maxDepth = process.env.MAX_POPULATE_DEPTH;
}

if (maxDepth <= 1) {
return true;
}
Expand Down Expand Up @@ -48,5 +56,5 @@ const getFullPopulateObject = (modelUid, maxDepth = 20) => {
};

module.exports = {
getFullPopulateObject
}
getFullPopulateObject,
};