question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to recreate/update gatsby source nodes

See original GitHub issue

I’m creating a couple source nodes with gatby’s sourceNodes API. I noticed that in development mode all nodes are correctly created when the dev server is started, but as I work on my app the nodes become stale due to changes in the data they are reading.

I’m wondering if there’s any API or examples I can see that will show me how to update (or re-create) these source nodes while the dev server is running.

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ryantocommented, Mar 31, 2020

Ok I think I figured it out, wanted to add it here incase anyone runs into this in the future.

https://www.gatsbyjs.org/docs/creating-a-source-plugin/#option-1-transformation-relationships

An example of a transformation relationship is the gatsby-transformer-remark plugin, which transforms a parent File node’s markdown string into a MarkdownRemark node. The Remark transformer plugin adds its newly created child node as a child of the parent node using the action createParentChildLink. Transformation relationships are used when a new node is completely derived from a single parent node. E.g. the markdown node is derived from the parent File node and wouldn’t ever exist if the parent File node hadn’t been created.

Because all children nodes are derived from their parent, when a parent node is deleted or changed, Gatsby deletes all of the child nodes (and their child nodes, and so on) with the expectation that they’ll be recreated again by transformer plugins. This is done to ensure there are no nodes left over that were derived from older versions of data but shouldn’t exist any longer.

The trick is to use createParentChildLink between your node and the node that represents the file on disk (which you can get from onCreateNode).

Thanks again!

0reactions
arryanggaputracommented, Aug 15, 2021

@ryanto I have similar question with you, and figure out about createParentChildLink but have no clue, can I know how you implement it? Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Source Plugin - Gatsby
At a high-level, a source plugin: Ensures the data in the Gatsby DB is synced with the latest updates from its source; Creates...
Read more >
How To Create a Custom Source Plugin in Gatsby
Step 1 — Scaffolding Files and Installing Dependencies · Step 2 — Loading and Configuring the Plugin · Step 3 — Pulling Raw...
Read more >
Gatsby JS Source Plugin Tutorial Step by Step for Beginners
Run Yarn link to create a symlink to the plugin folder you just created. This will allow you to move or rename the...
Read more >
How to Build a Gatsby Source Plugin, using Hashnode as an ...
The implementation · fetch all posts of a user from the API · loop through each post and create a node for it...
Read more >
Build your own Gatsby Source Plugin and Publish it to NPM ...
In this video tutorial we will create a Gatsby source plugin, and publish it to NPM!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found