Content Relationship ID Characters

I have content with nested content relationships, and so I am attempting to make additional queries for this data. However, the document id that is returned has extra characters at the beginning of the end of it:

Screen Shot 2021-01-19 at 1.06.20 PM

Will every document id returned have that same format, and those extra characters just have to be manually removed?

For that parent_page, I'm trying to run:

const parentID = "=&=018X_TiaBAAAASq78dp%%"
const page = await PrismicClient.query([
  Prismic.Predicates.at('document.type', 'page'),
  Prismic.Predicates.at('my.page.parent_page', parentID),
])

This returns no results because the actual page id is X_TiaBAAAASq78dp. How is that ID that is returned supposed to be handled?

Hey @samantha,

This looks like a glitch to me. I'm happy to look into it. Could you share your project files with me as a GitHub repo or ZIP file? (You can DM them if you like.)

Sam

Hi @samantha,

This is really puzzling. Your parent_page property definitely shouldn't look like that. I've never seen those extra characters before, and I have no idea where they could be coming from.

I tried downloading your project files and running your project to recreate the issue, but I couldn't recreate the same behavior. Could you give me more specifics about how you got those characters to appear — where exactly in your code?

Thanks,
Sam

In lib/layout.js, I'm making a call for the Navigation singleton document:

const { data: nav } = await PrismicClient.getSingle('navigation', {
fetchLinks: ['page.page_slug', 'page.parent_page'],
ref,
})

Looking through that returned data, the items with nested parent_page content relationships have those extra characters:

console.log(
'nav: ',
nav?.body?.map((item) => {
return item?.primary?.page_link?.data?.parent_page?.data
})
)

Thanks for helping to investigate!
Samantha

Hey @samantha,

I think I've figured this out. By using fetchLinks to retrieve a Content Relationship field, the API is recursively fetching data. This is not what is supposed to happen. fetchLinks is only supposed to retrieve the first Content Relationship. Instead, it appears that it is fetching a second Content Relationship and the ID for that document is getting corrupted. I've submitted a ticket with our dev team to look into this. But, in any case, the corrupted document ID that you're seeing should not work.

There are a couple of other ways I can think of to retrieve that data.

One option is to recursively make one query for each level of content relationship.

Another option would be to use GraphQuery. GraphQuery is an API Option that allows you to specify what fields and linked documents you want to retrieve with a syntax similar to GraphQL. GraphQuery allows you to query linked documents up to three levels deep.

Let me know if you have any questions! I hope this solves your issue :slight_smile:

Sam

deep-graphquery.zip (1.9 KB)

Thanks @samlittlefair ! So when the fetchLinks issue is fixed, would that second-level parent_page field just be a string with the content id ?

Hey @Samantha,

Here's an example:

  • You're querying page-one
  • page-one has a "title" field and a "relationship" field
  • page-one's relationship field is filled in with a link to page-two
  • page-two has a relationship field that you want to retrieve with fetchLinks
  • The relationship field on page-two is filled in with a link to page-three

Then, your JSON response should look like this:

{
  "page": 1,
  "results_per_page": 20,
  "results_size": 1,
  "total_results_size": 1,
  "total_pages": 1,
  "next_page": null,
  "prev_page": null,
  "results": [
    {
      "id": "YArUdREAACoASlF1",
      "uid": "one",
      "type": "page",
      "href": "https://recursive-fetchlinks.cdn.prismic.io/api/v2/documents/search?ref=YA6ahBEAACgAWxAu&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22YArUdREAACoASlF1%22%29+%5D%5D",
      "tags": [],
      "first_publication_date": "2021-01-22T13:34:49+0000",
      "last_publication_date": "2021-01-25T10:12:06+0000",
      "slugs": ["page-one", "one"],
      "linked_documents": [],
      "lang": "en-us",
      "alternate_languages": [],
      "data": {
        "title": "Page One",
        "relationship": {
          "id": "YArUaBEAACoASlE3",
          "type": "page",
          "tags": [],
          "slug": "page-two",
          "lang": "en-us",
          "uid": "two",
          "data": {
            "relationship": {
              "id": "YArUWREAACoASlDq",
              "type": "page",
              "tags": [],
              "slug": "page-three",
              "lang": "en-us",
              "uid": "three",
              "link_type": "Document",
              "isBroken": false
            }
          },
          "link_type": "Document",
          "isBroken": false
        }
      }
    }
  ],
  "version": "ec04165",
  "license": "All Rights Reserved"
}

Right now, the only different is that page-three also has a data object with a relationship property displaying corrupt data.

Let me know if that makes sense! I hope this is helping you getting everything sorted. In any case, I'm around if you have more questions.

Sam

PS: If you want to play with the data in the API, you can use the repo I'm using in that example, recursive-fetchlinks.prismic.io/api/v2

Follow-up: a fix for this glitch has been deployed. Thanks @samantha for pointing it out!

1 Like

This issue has been closed as it has been fixed, Flag if it is not the case for you to reopen.