Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add populate property to Local / REST API #8969

Conversation

r1tsuu
Copy link
Member

@r1tsuu r1tsuu commented Oct 31, 2024

What?

Adds populate property to Local API and REST API operations that can be used to specify select for a specific collection when it's populated

const result = await payload.findByID({
  populate: {
   // type safe if you have generated types
    posts: {
      text: true,
    },
  },
  collection: 'pages',
  depth: 1,
  id: aboutPage.id,
})

result.relatedPost // only has text and id properties
fetch('https://localhost:3000/api/pages?populate[posts][text]=true') // highlight-line
  .then((res) => res.json())
  .then((data) => console.log(data))

It also overrides defaultPopulate

Ensures defaultPopulate doesn't affect GraphQL.

How?

Implements the property for all operations that have the depth argument.

@r1tsuu r1tsuu force-pushed the feat/add-populate-to-local-api-and-rest-api-operations-property branch from 448161c to d62c473 Compare October 31, 2024 17:18
@r1tsuu r1tsuu force-pushed the feat/add-populate-to-local-api-and-rest-api-operations-property branch from d62c473 to d490a8f Compare November 2, 2024 02:56
…pulate-to-local-api-and-rest-api-operations-property
Copy link
Contributor

@DanRibbens DanRibbens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
In my review I was checking that this doesn't impact the data loader, it seems like it will work well. Each collection can only have one definition of select so no issues.

@DanRibbens DanRibbens merged commit a22c0e6 into beta Nov 6, 2024
48 checks passed
@DanRibbens DanRibbens deleted the feat/add-populate-to-local-api-and-rest-api-operations-property branch November 6, 2024 18:50
Copy link
Contributor

github-actions bot commented Nov 6, 2024

🚀 This is included in version v3.0.0-beta.126

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants