Not able to fetch text field inside of group relationship

I'm having problems fetching a simple text field from related documents.

Here's what I have inside my document:

      "categories": {
        "type": "Group",
        "config": {
          "label": "Categories",
          "fields": {
            "category": {
              "type": "Link",
              "config": {
                "label": "Category",
                "select": "document",
                "customtypes": [
                  "case_category"
                ]
              }
            }
          }
        }
      },

This is what a linked Category looks like:

{
  "id": "case_category",
  "label": "Case Category",
  "repeatable": true,
  "status": true,
  "json": {
    "Main": {
      "title": {
        "type": "Text",
        "config": {
          "label": "Title",
          "placeholder": ""
        }
      }
    }
  }
}

If I now do this fetch:

const { data: caseDoc } = await useAsyncData('case', () => client.getByUID<CaseDocument>('case', route.params.slug as string, { fetchLinks: ['categories.category.title'] }))

I do not get the title in my response. What am I doing wrong?
Thanks for any help

Hello @christianreich

Thanks for reaching out to us.

fetchLinks can not retrieve the following fields:

  • Embed
  • GeoPoint
  • Link
  • Link to Media
  • Rich Text (anything other than the first element)
  • Any field in a Group or Slice

To retrieve any field in a Group, you need to use GraphQuery.
GraphQuery API Option Technical Reference - Documentation - Prismic

Thanks,
Priyanka

Hey @christianreich, even though Prismic's documentation says that you can't query a field in a group, I found out that you actually can (I discussed this in another thread but not sure if the Prismic team updated their docs) - GraphQuery vs FetchLinks).

I have a very similar setup for Prismic Templates - give it a go and let me know if it works


Hello @kris

Thanks for your response; I highly appreciate it.

We can not wholly rely on fetchLinks to get fields inside group relationships. Sometimes with some repo, it does work, and sometimes it doesn't. That's why we usually recommend graphQuery.

Best,
Priyanka

hey @Priyanka, in which cases it doesn't work?

@kris Thanks for your reply! Your setup does look very similar, however I can't figure out why it's not working. I tried "categories.category.title" and "category.title", nothing seems to work for me.

I've now circumvented the problem by making the categories a simple RichText field. Thankfully in my project the categories are just a convenience, but not strictly necessary as a separate Content Type.

@Priyanka I'm also curious, what's the logical explanation behind this?

@christianreich Did you try "case_category.title" ?

Hello, @kris @christianreich We have discussed many times internally, but we don't have any concrete answer for this, in which case it work or doesn't. Most of the time, it doesn't work for me with my repos so I prefer to use graphql. However, I will pass this on to my documentation team for further exploring.

Thanks,
Priyanka