Linking Data In Gatsby
The possible ways can be generally grouped by if you have some control of the nodes or if they are made for you.
When Nodes Are Made For You
- mapping nodes, probably the fastest and most approachable, but requires your data at each node to "match"
- using createParentChildLink typically in the onCreateNode lifecycle
- The onCreateNode lifecycle fires every time a new node is created. You can use this to link a node to another node.
When You Have Control Of The Nodes
- Setting up the relationship with ___NODE appended to your node name.
- A plain value and let Gatsby infer (guess) the type of node (generally for File nodes)
- Creating a new type and using a resolver to "manually" query and link them
- This is likely the most involved. You will need to use onCreateNode to create "linking" nodes.
- The "linking" nodes will point to your custom type. The type can use the createResolvers that let you code the way the node is "inferred".
- You can see an example of this in my gastby-theme-recipes.