Skip to content

Commit e3203cf

Browse files
committed
first commit
0 parents  commit e3203cf

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

README.md

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<p align="center">
2+
<a href="https://magictm.com" target="_blank" rel="noopener noreferrer">
3+
<img width="270" src="assets/logo.svg" alt="Project Logo">
4+
</a>
5+
</p>
6+
7+
<br/>
8+
9+
<p align="center">
10+
<a href='#'>
11+
</a>
12+
<a href="https://www.npmjs.com/package/@magictm/strapi-plugin-deep-populate" target="__blank"><img alt="NPM version" src="https://img.shields.io/npm/v/@magictm/strapi-plugin-deep-populate?flat&colorA=0e0a18&colorB=8c67ef"></a>
13+
<a href="https://www.npmjs.com/package/@magictm/strapi-plugin-deep-populate" target="__blank"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/@magictm/strapi-plugin-deep-populate?flat&colorA=0e0a18&colorB=8c67ef"></a>
14+
<a href="https://github.com/magictm/strapi-plugin-deep-populate" target="__blank"><img alt="GitHub stars" src="https://img.shields.io/github/stars/magictm/strapi-plugin-deep-populate?flat&colorA=0e0a18&colorB=8c67ef"></a>
15+
</p>
16+
17+
<br/>
18+
19+
<h1 align='left'>MagicTM · Deep Populate · Strapi Plugin</h1>
20+
21+
🚀 The MagicTM Deep Populate Strapi Plugin simplifies deep population of content structures within your Strapi v4 applications. This plugin streamlines fetching nested data, making your API responses more comprehensive and developer-friendly.
22+
23+
🌐 Follow me: https://stawowczyk.me
24+
25+
## ⛓ Versions
26+
27+
Strapi v4 - (current) - v1.x
28+
29+
Tested on Strapi v4.25.4.
30+
31+
## 💻 1. Install
32+
33+
### Install the plugin
34+
35+
```bash
36+
npm install @magictm/strapi-plugin-deep-populate
37+
```
38+
39+
## 2. Enable the plugin
40+
41+
Navigate to your Strapi project's configuration file:
42+
`<strapi app root>/config/plugins.js` or `.ts`
43+
44+
Add the following code snippet:
45+
46+
### Minimal configuration:
47+
48+
```ts
49+
'magictm-deep-populate': {
50+
enabled: true,
51+
}
52+
```
53+
54+
### Advanced configuration
55+
56+
```ts
57+
'magictm-deep-populate': {
58+
enabled: true,
59+
config: {
60+
minDepth: 5, // Minimum population depth
61+
maxDepth: 5, // Maximum population depth
62+
// Skip populating creator fields (e.g., created_by)
63+
skipCreatorFields: false,
64+
// Array of fields to always ignore.
65+
// Must be type of ['relation', 'component', 'dynamiczone', 'media']
66+
ignore: ['localizations', 'strapi_stage'],
67+
// Enable debug mode for detailed logs
68+
debug: false,
69+
// Array of models where deep population is allowed e.g. ['api::page.page', 'api::post.post']
70+
// If empty all models are allowed.
71+
allowedModels: ['api::page.page', 'api::post.post'],
72+
},
73+
}
74+
```
75+
76+
### Full example (typescript)
77+
78+
```ts
79+
export default () => ({
80+
// other plugins
81+
82+
'magictm-deep-populate': {
83+
enabled: true,
84+
},
85+
})
86+
```
87+
88+
## 3. (Re)Start Your Application
89+
90+
For the changes to take effect, restart your Strapi application:
91+
92+
```
93+
npm run develop
94+
```
95+
96+
## 4. 🚀 Usage
97+
98+
The MagicTM Deep Populate plugin seamlessly integrates with your existing Strapi API. Here's how to use it:
99+
100+
### Default Deep Population
101+
102+
To fetch content with deep population up to the configured default depth, simply append `?populate=deep` to your API endpoint:
103+
104+
```
105+
/api/articles?populate=deep
106+
```
107+
108+
### Custom Population Depth
109+
110+
For finer control, specify the desired depth level numerically after the `deep` keyword:
111+
112+
```
113+
/api/articles?populate=deep,10
114+
```
115+
116+
This fetches articles with relations populated up to 10 levels deep, or the maximum depth set in the plugin configuration – whichever is lower. This ensures your API responses remain performant even with large datasets.
117+
118+
### Excluding Specific Fields from Population
119+
120+
Use the `populateIgnore` parameter to prevent specific fields or relations from being populated. This helps tailor your API responses by omitting unnecessary data.
121+
122+
For example, to exclude the seo field from population:
123+
124+
```
125+
/api/articles?populate=deep&populateIgnore=seo
126+
```
127+
128+
You can comma-separate multiple fields to ignore. For instance, to exclude both the `seo` field and a relation named `relPosts`:
129+
130+
```
131+
/api/articles?populate=deep&populateIgnore=seo,relPosts
132+
```
133+
134+
## 🤝 Contributing
135+
136+
Contributions to the MagicTM Deep Populate Strapi Plugin are always welcome! To contribute:
137+
138+
- **Fork** the repository.
139+
- **Create** a new branch for your feature/bug fix.
140+
- **Commit** your changes with descriptive messages.
141+
- **Push** your changes to your forked repository.
142+
- **Submit** a pull request to the `master` branch.
143+
144+
## ☕️ Help me keep working on this project 💚
145+
146+
If you find this plugin valuable, consider supporting its development. Your contribution helps me maintain and improve this project.
147+
148+
- Buy me a coffee: https://www.buymeacoffee.com/m7rlin
149+
- Support via PayPal: https://paypal.me/merlinArtist
150+
151+
## 🎖️ Sponsors
152+
153+
We appreciate all sponsors! Please contact us if you're interested in sponsoring this project.
154+
155+
## 📜 License
156+
157+
LGPL-2.1 License © 2024-PRESENT Marcin Stawowczyk (m7rlin)
158+
159+
Thank you for using the MagicTM Deep Populate Strapi Plugin! Let me know if you have any other questions.

0 commit comments

Comments
 (0)