gatsby-source-graphcms icon indicating copy to clipboard operation
gatsby-source-graphcms copied to clipboard

Markdown nodes null in production

Open sbuys opened this issue 4 years ago • 8 comments

Using 2.8.0

Picking up from #214, where the same issue occurred with local images - null in production but valid in development. Not sure if the issue here is related.

Example project with public API endpoint.

Plugin config:

{
  resolve: 'gatsby-source-graphcms',
    options: {
      endpoint: process.env.GRAPHCMS_API_ENDPOINT,
      buildMarkdownNodes: true,
      downloadLocalImages: true,
    },
}
`

sbuys avatar Feb 05 '22 03:02 sbuys

Hey everyone,

I have the same issue with buildMarkdownNodes working in development but not in production mode. Are there any logs that we can provide to assist in debugging?

DennisSimon avatar Feb 07 '22 16:02 DennisSimon

@notrab anything we can do to help on this one? We are stuck in a holding pattern on a few projects.

sbuys avatar Feb 13 '22 23:02 sbuys

So i managed to work around the issue in my case, which is very similar to the case that you posted as an example @sbuys. Here is a quick rundown of what i changed:

Previously, i was simply querying the ids of all posts/pages that contained the markdownNodes in gatsby-node.js, passed them to the gatsby template pages via the context and then retrieved all required fields within the template via page queries.

I found that when i query all required fields within gatsby-node and then pass all of them via the context, the markdownNodes are not null anymore.

I am guessing that this might be either due to some sort of race-condition (might explain why it works during development as the fields are queried on demand) or an issue where certain nodes are simply not available during page queries.

DennisSimon avatar Feb 17 '22 00:02 DennisSimon

Another piece of information:

I noticed that the workaround i posted above suddenly stopped working. To get it working again, i needed to clean the cache and rebuild.

So it might also be a caching issue?

DennisSimon avatar Feb 17 '22 19:02 DennisSimon

@DennisSimon thanks for the update. I'll look into the caching and report back.

sbuys avatar Feb 17 '22 21:02 sbuys

@DennisSimon The problem actually seems tied to the code in onCreateNode().

Per the documentation for Gatsby v4, mutation of nodes outside of createNode() is an anti-pattern. More info here.

field.value.markdownNode = markdownNode.id will not update the node in the Gatsby store and the fact that it works in development is probably a fluke.

What I'm not sure about is how to use the recommended API createNodeField as it seems you can't alter a field directly.

sbuys avatar Feb 28 '22 07:02 sbuys

Any updates or workaround on this issue? Experiencing the same thing with 2.8.0 and gatsby 4.20.0.

zzullick avatar Aug 10 '22 18:08 zzullick

@zzullick we moved to another CMS. We're one of the case studies on the website too 💔.

sbuys avatar Aug 10 '22 19:08 sbuys