Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Init migration to v4 #266

Merged
merged 41 commits into from
Feb 16, 2022
Merged

Init migration to v4 #266

merged 41 commits into from
Feb 16, 2022

Conversation

soupette
Copy link
Contributor

@soupette soupette commented Jan 21, 2022

Init plugin migration to Strapi v4:

  • API Token support
  • Markdown support
  • Adapt REST API response to gatsby
  • New query system
  • Markdown processing
  • Image processing
  • Link relations and nested relations from api response (only for the first level)
  • Cloud support
  • Dynamic zones support
  • Components supports
  • Extract files from richtext fields

Bug fixes:

Signed-off-by: soupette <cyril@strapi.io>
@strapi-cla
Copy link

strapi-cla commented Jan 21, 2022

CLA assistant check
All committers have signed the CLA.

Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
@timbrandin
Copy link

I have a working solution here (https://github.com/relate-app/gatsby-source-strapi/) that solves all the checkpoints except maybe cloud - not sure what that includes. Please have a look, it uses strapi graphql rather than rest which has it's limitation, i.e. not exposing types properly which is available through the schema introspection on the graphql side of things.

Hope it helps! // T

Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Only fetch data after build
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
soupette and others added 15 commits February 9, 2022 09:21
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Add support for user content type and file content type
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
Signed-off-by: soupette <cyril@strapi.io>
*
* See: https://www.gatsbyjs.com/docs/node-apis/
*/
// You can delete this file if you're not using it

Choose a reason for hiding this comment

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

Probably good to remove this line :)

Comment on lines 71 to 110
const allResults = await Promise.all(
endpoints.map(({ kind, ...config }) => {
if (kind === 'singleType') {
return fetchEntity(config, ctx);
}

return fetchEntities(config, ctx);
})
);

let newOrExistingEntries;

// Fetch only the updated data between run
if (lastFetched) {
// Add the updatedAt filter
const deltaEndpoints = endpoints.map((endpoint) => {
return {
...endpoint,
queryParams: {
...endpoint.queryParams,
// TODO
filters: {
updatedAt: { $gt: lastFetched },
},
},
};
});

newOrExistingEntries = await Promise.all(
deltaEndpoints.map(({ kind, ...config }) => {
if (kind === 'singleType') {
return fetchEntity(config, ctx);
}

return fetchEntities(config, ctx);
})
);
}

const data = newOrExistingEntries || allResults;

Choose a reason for hiding this comment

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

Does this still fetch all nodes on each run? Shouldn't there be a conditional to not fetch allResults if there's a lastFetched key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well we need to fetch all the results in order to know which content has been deleted.

Copy link

@TylerBarnes TylerBarnes Feb 14, 2022

Choose a reason for hiding this comment

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

Does allResults mean all node data in Strapi? If so, needing to fetch that to determine what was deleted means the plugin doesn't really have incremental builds support.
Unless I'm misunderstanding, this code fetches all data on cold builds then on subsequent cached builds it again fetches all data and then additionally double fetches anything that changed since the first build. Is that right or am I misunderstanding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On subsequent cached build it uses the delta fetched data to create/update nodes. The first call is only used to know which nodes should be deleted.

So on cold build we use all the data and on then we only use the other fetches to have smaller rebuilds

Choose a reason for hiding this comment

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

Nice 👍 good to hear that 😄 Does that happen inside fetchEntities? I'm having trouble finding it

Copy link
Contributor Author

@soupette soupette Feb 16, 2022

Choose a reason for hiding this comment

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

Not it happens with the filer updatedAt that is set with the lastFetched constant retrieved from the cache

Choose a reason for hiding this comment

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

Thanks 👍 I get that part but I'm not sure how allResults on line 71 doesn't refetch all data on each build. On cold builds that's what pulls in all initial nodes right? I'm not following how it doesn't re-fetch all nodes again on warm builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

allResults are always fetched it is used to know which nodes we need to delete, however on subsequent build if we have already requested the API the data we use is the result of the delta fetches from L.85.

Is that an issue? Should I make an update?

If you check L.96 you'll see that we use the delta results if it exists otherwise the full results.

Copy link

@TylerBarnes TylerBarnes Feb 17, 2022

Choose a reason for hiding this comment

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

Ah, yeah the problem is in which data is fetched, not in which is used. Data fetching is the slow part (especially for large sites) so if we need to refetch all results on every build then the delta isn't really helping. Ideally there would be a way to fetch deletes as part of the delta too. Then on warm builds we would skip fetching all results and just fetch the delta.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be interesting to add this behaviour only when GATSBY_IS_PREVIEW is true or should we always do it?

...endpoint,
queryParams: {
...endpoint.queryParams,
// TODO

Choose a reason for hiding this comment

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

is this still a todo?


const nodeType = makeParentNodeName(ctx.schemas, uid);

const mainEntryNode = nodes.find((n) => {

Choose a reason for hiding this comment

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

Is it possible to edit a block outside of a page in Strapi? In Contentful we create node manifests for all content nodes (even if they're not top level) because it means you can press "Open Preview" from within the edit view of a nested block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's not possible, only primary nodes, the one that create pages, regarding linked nodes the manifest will also be created for them as we fetch them

@soupette soupette changed the base branch from v4-migration to master February 14, 2022 09:46
Signed-off-by: soupette <cyril@strapi.io>
@soupette soupette marked this pull request as ready for review February 15, 2022 09:35
Signed-off-by: soupette <cyril@strapi.io>
- [Image optimisation](#image-optimisation)
- [Rich text field](#rich-text-field)
- [Components](#components)
- [Dynamic zones](#dynamic-zones)

Choose a reason for hiding this comment

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

Can you add a localizations section and accompanying documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be okay to add this in a future release?

Because I think it will be easier once we'll have updated the Gatsby corporate starter which uses i18n

Choose a reason for hiding this comment

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

That'd be a cool starter to have! I've got alpha 4 working with my test site and it's working well except for a few localization bits. Doing those in a discrete release could be a nice milestone

Copy link

Choose a reason for hiding this comment

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

May I chime in here? I'm just a regular developer watching the PR and tries it in development. While a starter is great to reduce startup time and complexity it's IMHO a nice to have while undocumented features makes the lib really hard to use until you release a new starter. I don't want to sound demanding here, you do a great job on this lib, I just wanted to give some user input if you find it helpful. 💚

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

Successfully merging this pull request may close these issues.

10 participants