Custom data in rich text link resolver

I'm working with the linkResolver in React w/ Next.js. I get back doc.id and doc.uid. Is there anyway to access custom attributes inside of the link resolver. I have a parent field that affects the url but don't see how to get access to it without fetching a bunch of data inside the link resolver which seems pretty inefficient.

Hello, @ryandunnewold welcome to the Forum!

You can pass more information to the Link Resolver other than the metadata by using Fetchlinks, which allows you to fetch a specific content field from a linked document.

  • How are you fetching the extra data passed to your link resolver?
  • Are you trying to build nested URLs?

Hi @Pau,

Thanks for your response! I am using GraphQL for fetching data and am trying to build nested URLs. I'm checking to see if there is a 'parent' attribute on the particular page. If so I take it to /parent/uid. Otherwise I take it to /uid. Here is a simplified query of what I'm doing:

    query($uid: String!) {
      page(lang: "en-us", uid: $uid) {
        _meta {
          uid
        }
        parent
        page_content {
          ... on PagePage_contentFaq {
            type
            primary {
              heading
              subtitle
              background_color
            }
            fields {
              question
              answer
            }
          }
        }
      }
    }

Where 'answer' is a rich text field. When I render that rich text field though I just get these standard attributes on the doc param: Link Resolving in Javascript - Prismic

Hi Ryan, thank you for sending over your query. I can see that you have a parent field before the page_content object. What is this field? Is it a Content relationship field or maybe just a Link?

To retrieve linked document content from a Link, you have to use the Union type in your queries; here's a more detailed article that explains how to do it: Retrieve linked document content with the Prismic GraphQL API - Prismic

This issue has been closed due to inactivity. Flag to reopen.