@fourlights/strapi-plugin-deep-populate

中文文档
1.17.1发布于 2026/09/17MITTypeScriptESM + CJS构建来源已验证近 30 天下载 3786

This plugin provides a simple way of retrieving all nested objects in a single request.

原始使用文档
文档目录13 节
  1. Features
  2. Installation
  3. Usage
  4. Basic Usage
  5. Advanced Usage
  6. omitEmpty and localizations
  7. Caching
  8. Creator Fields
  9. Allow / Deny Lists
  10. How The Plugin Works
  11. Troubleshooting
  12. Star History
  13. Built with ☕ in Deventer, NL .

Strapi v5 Deep Populate Plugin

npm version

A Strapi v5 plugin that automatically populates all nested relations in a single request using populate: '*'. It does not impose a limit on the level of nesting and can cache the populate object for improved performance.

Features

  • Automatically resolves and populates all nested relations
  • Supports all relation types including dynamic zones
  • Handles circular references and edge cases
  • Includes caching for improved performance
  • Honors populateCreatorFields setting
  • Supports optional allow/deny lists for specific relations or components during population

Installation

npm install @fourlights/strapi-plugin-deep-populate

Usage

Enable deep population in your Strapi config:

// config/plugins.js
module.exports = ({ env }) => ({
  'deep-populate': {
    enabled: true,
    config: {
      useCache: true, // default
      replaceWildcard: true, // default
    }
  }
});

Basic Usage

// Get fully populated document
const document = await strapi.documents("api.page.page").findOne({
  documentId: 'xyz',
  populate: '*'
});

Advanced Usage

// Get populate object for custom usage
const populate = await strapi.plugin("deep-populate")
  .service("populate")
  .get({
    documentId: 'xyz',
    contentType: 'api::page.page',
    omitEmpty: true // optional
  });

const document = await strapi.documents('api::page.page').findOne({
  documentId: 'xyz',
  populate
});

omitEmpty and localizations

The plugin provides fine-grained control over which attributes are included in the populate object through omitEmpty and localizations options.

Global Configuration

Set default behavior for all content types:

// config/plugins.js
module.exports = ({ env }) => ({
  'deep-populate': {
    enabled: true,
    config: {
      useCache: true,
      replaceWildcard: true,
      omitEmpty: true, // Omit empty attributes by default
      localizations: false, // Exclude localizations by default
    }
  }
});

Content-Type Specific Configuration

Override global settings for specific content types:

// config/plugins.js
module.exports = ({ env }) => ({
  'deep-populate': {
    enabled: true,
    config: {
      useCache: true,
      replaceWildcard: true,
      omitEmpty: true,
      localizations: false,
      
      contentTypes: {
        'api::page.page': {
          omitEmpty: false, // Include all attributes for pages
          localizations: true, // Always include localizations for pages
        },
        'api::blog-post.blog-post': {
          omitEmpty: true, // Explicitly omit empty attributes
          localizations: true, // But include localizations for blog posts
        }
      }
    }
  }
});

Function Parameter Configuration

Override both global and content-type settings per request:

// Get populate object with custom settings
const populate = await strapi.plugin("deep-populate")
  .service("populate")
  .get({
    documentId: 'xyz',
    contentType: 'api::page.page',
    omitEmpty: true, // Override content-type setting
    localizations: false // Override content-type setting
  });

Override Priority

Settings are applied in the following priority order (highest to lowest):

  1. Function parameters - Passed directly to the get() method
  2. Content-type configuration - Specific to the content type
  3. Global configuration - Default plugin settings

Special Behavior

  • When localizations: true, the localizations field will be included even if omitEmpty: true
  • When localizations: false, localizations are excluded regardless of the omitEmpty setting
  • The localizations option only affects content types that have i18n enabled

Caching

The plugin caches populate objects to improve performance. Cache can be disabled via the useCache setting. Cache entires are persisted in the database and can become stale after content-type updates. You can use the cacheOptions > clearCacheOnStartup to force cache purging on server start.

Cache Configuration

// config/plugins.js
module.exports = ({ env }) => ({
  'deep-populate': {
    enabled: true,
    config: {
      useCache: true, // Enable caching (default: true)
      cacheOptions: {
        clearCacheOnStartup: false, // Clear cache on server startup (default: false)
        warmOnWrite: false, // Re-warm cache synchronously after writes; NOTE: can be slow (default: false)
      }
    }
  }
});

Creator Fields

The plugin automatically populates createdBy and updatedBy fields when populateCreatorFields is enabled in the content-type configuration.

Allow / Deny Lists

Sometimes you may want to restrict the nested population of certain relations or components. For example if you have a Page contentType where a deeply nested Link component has a relation to another Page. In those situations you can use the allow or deny lists to control where the plugin should stop resolving nested relations.

// config/plugins.js
module.exports = ({ env }) => ({
  'deep-populate': {
    enabled: true,
    config: {
      useCache: true,
      replaceWildcard: true,
      
      contentTypes: {
        // '*' would apply to all content types
        'api::page.page': {
          deny: {
            relations: ['api::page.page']  // prevent resolving nested pages when populating a page
            // alternatively we could have denied the link component in this case
            // components: ['shared.link']
          }
        }
      }
    }
  }
});

How The Plugin Works

The plugin recursively:

  1. Traverses the content-type schema
  2. Retrieves documents with one-level deep populate
  3. Resolves all nested relations
  4. Returns a complete populate object

This process handles all relation types including dynamic zones and circular references.


Troubleshooting

Due to the dynamic nature of Strapi, stuff becomes complex pretty quickly and it can sometimes become tricky to see the proverbial forest through the trees. In that case, feel free to open up an issue and I'll try to help you out.

But first, make sure you:

  1. use the latest version of the plugin
  2. use the latest version of Strapi
  3. see if disabling the cache fixes the problem
  4. check if your content-types are still valid, e.g. no dynamic zones who reference deleted components etc.
  5. check you don't have attributes/relations marked as private if you expect them in the API response

If that didn't fix it, open up that issue! Make sure you report the used versions (plugin & strapi) and preferably share the affected content-type definitions. Or even better, a reproduction of the problem.


Star History

Star History Chart

Thanks for reading and using the plugin. If you like it, consider starring it to give me a nice little dopamine hit next time I'm working on it.

Built with ☕ in Deventer, NL.

版本与发布记录

@fourlights/strapi-plugin-deep-populate 共发布 60 个版本,首次发布于 2025/01/23;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.17.1latest2026/09/171 个月前
1.17.02026/09/171 个月前
1.17.0-beta.0beta2026/09/082 个月前
1.16.02026/07/034 个月前
1.16.0-rc.12026/07/014 个月前
1.17.0-rc.02026/07/014 个月前

关于 @fourlights/strapi-plugin-deep-populate 的常见问题

@fourlights/strapi-plugin-deep-populate 是什么?

This plugin provides a simple way of retrieving all nested objects in a single request.

如何安装 @fourlights/strapi-plugin-deep-populate?

在项目目录运行 npm install @fourlights/strapi-plugin-deep-populate,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@strapi/sdk-plugin(^5)、@strapi/strapi(^5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fourlights/strapi-plugin-deep-populate 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fourlights/strapi-plugin-deep-populate 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fourlights/strapi-plugin-deep-populate 可以商用吗?

@fourlights/strapi-plugin-deep-populate 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fourlights/strapi-plugin-deep-populate 的下载量有多少?

根据 npm 官方下载统计,@fourlights/strapi-plugin-deep-populate 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,786 次,日均约 126 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fourlights/strapi-plugin-deep-populate 还在维护吗?

最新版本 1.17.1 发布于 2026/09/17(1 个月前);至今共发布 60 个版本,其中过去 12 个月发布了 20 个;首次发布于 2025/01/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。