Fetchlinks does not seem to work on content relationship

Hi there, I've seen some resolved issues about it, but I couldn't find my way with my context :sweat:

  1. I have a single type "Home", where I can have a "category" field (relationship to my "Category" content type)
{
  "id": "home",
  "label": "Home",
  "repeatable": false,
  "status": true,
  "json": {
    "Main": {
      "title": {
        "type": "Text",
        "config": {
          "label": "Title*",
          "placeholder": ""
        }
      },
      "slices": {
        "type": "Slices",
        "fieldset": "Slice Zone",
        "config": {
          "choices": {
            "category_slider": {
              "type": "SharedSlice"
            }
          }
        }
      }
    }
  }
}

Here is the model of the slice:

{
  "id": "category_slider",
  "type": "SharedSlice",
  "name": "CategoryCarousel",
  "description": "Text",
  "variations": [
    {
      "id": "default",
      "name": "Default",
      "docURL": "...",
      "version": "sktwi1xtmkfgx8626",
      "description": "Text",
      "primary": {
        "title": {
          "type": "Text",
          "config": {
            "label": "Title*",
            "placeholder": ""
          }
        },
        "category": {
          "type": "Link",
          "config": {
            "label": "Category*",
            "select": "document",
            "customtypes": [
              "category"
            ]
          }
        }
      },
      "items": {},
      "imageUrl": "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"
    }
  ]
}

And lastly the model of the category:

{
  "id": "category",
  "label": "Category",
  "repeatable": true,
  "status": true,
  "json": {
    "Main": {
      "title": {
        "type": "Text",
        "config": {
          "label": "Title",
          "placeholder": ""
        }
      },
      "image": {
        "type": "Image",
        "config": {
          "label": "Image",
          "constraint": {},
          "thumbnails": []
        }
      },
      "uid": {
        "type": "UID",
        "config": {
          "label": "slug",
          "placeholder": ""
        }
      },
      "description": {
        "type": "StructuredText",
        "config": {
          "label": "Description",
          "placeholder": "",
          "allowTargetBlank": true,
          "single": "paragraph,preformatted,heading1,heading2,heading3,heading4,heading5,heading6,strong,em,hyperlink,image,embed,list-item,o-list-item,rtl"
        }
      },
      "parent": {
        "type": "Link",
        "config": {
          "label": "Parent Category",
          "select": "document",
          "customtypes": [
            "category"
          ]
        }
      }
    }
  }
}

I don't understand, because when I fetch the homepage using the method client.getAllByType with the following values:

const fetchLinks = [
  'article.title',
  'article.description',
  'category.title',
  'category.image',
]

... well it doesn't fetch the category Image. In the data object, I only have the title. Any idea why?

Thanks!

Hello @Loki,

Thanks for reaching out to us.

These two Query Options exist on the REST API for getting content from linked documents.

Fetchlinks allows you to get a specific field and all its content from the document. You can't retrieve linked content from Slices and groups with fetchLinks.

To retrieve content from the linked document in slices and groups, you need to use graphQuery (an advanced version of fetchLinks).

Take a look at these documents and let me know if you need any help with building a graphQuery.

Thanks,
Priyanka

Hi Priyanka, thanks for your response.

Just to be sure, If I want to use a content relationship on my single type directly (so adding a "category" to "home") it would work in this situation? Thanks!

Hello Loki,

Yes, it will work. You need to retrieve fields from linked documents. GraphQuery API Option Technical Reference - Documentation - Prismic

I meant, without the graphQL overload :slight_smile: With the fetchlink key?

fetchLinks can not retrieve the Link fields. You need to use graphQuery.