Answered

How to query (New) Linked Content with a Dynamic Reference name in Gatsby?

This question is posted on behalf of a user.

In the Gatsby Agility starter, I noticed you pull content with StaticQuery's when it's possible to use a static reference name (like "Global Header").

What about linked content (including nested linked content) that is dynamic - resulting in a generated reference name ?

Consider the content structure:

Top List

  Top List Item

    Nested List

      Nested List Item

Where Nested List is new/dynamically generated per Top List Item instance. One Nested List would have a referenceName like NestedList_12345, another with NestedList_6789, etc...

 What's the best way to pull this content from Agility? I've created a modified version of the getLinkedContentItems util provided in the Gatsby starter that can navigate nested list items. Is there a better/another way to do this though?

Overall it seems like we want to avoid any dynamically linked content when possible, but for when we cannot what's the best approach?

1

Comments

1 comment
  • Official comment

    When dealing with resolving linked content, especially when you can't possibly know the reference name, its best to use the concept of resolvers. 

    "I've created a modified version of the getLinkedContentItems util provided in the Gatsby starter that can navigate nested list items. Is there a better/another way to do this though?"

    I would say the way you are handling this here is the best way to do this. The resolver your setup should be responsible for automatically resolving the reference based on the dynamically generated reference name.

    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post