hygraph / gatsby-source-graphcms

The official Gatsby source plugin for GraphCMS projects

Home Page:https://graphcms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Markdown nodes null in production

sbuys opened this issue · 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,
    },
}
`

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?

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

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.

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 thanks for the update. I'll look into the caching and report back.

@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.

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

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