# How to retrieve linked document data with GraphQuery

**URL:** <https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608>\
**Category:** Developing with Prismic\
**Tags:** nextjs\
**Created:** [October 26, 2021, 11:27am UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608 "2021-10-26T11:27:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomasvit6](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tomasvit6](https://community.prismic.io/u/tomasvit6)\
**Post date:** [October 26, 2021, 11:27am UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/1 "2021-10-26T11:27:59Z")

</div>

Hi, could someone explain to me how to retrieve a linked document in my case?

I have a custom type: "home-page". My "home-page" has 2 slices "carousel" and "available\_offers". "available\_offers" is linked to another document  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/0/08270bb5b77ee3d3cb03d9911e814c1646d6d7dc.png)

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/9/9d7ea4e8da5d4c8236d7add7892985be776bf537.png)

Current query:

```auto
const graphQuery = `{
    home-page {
      ...home-pageFields
    }
  }`;
  const res = await client.getSingle('home-page', {
    lang: appLocale,
    graphQuery
  });

```

I get a response but it's missing linked document data. Current response:

```auto
{"page":1,"results_per_page":1,"results_size":1,"total_results_size":1,"total_pages":1,"next_page":null,"prev_page":null,"results":[{"id":"YWanmxIAACsA3yX8","uid":"home-page","url":"/","type":"home-page","href":"https://ocb-base-local.cdn.prismic.io/api/v2/documents/search?ref=YXawVhIAACkAZecx&integrationFieldsRef=ocb-base-local%7E5effe007-9cd7-4e66-bbd6-58f1c0c4e47c&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22YWanmxIAACsA3yX8%22%29+%5D%5D","tags":[],"first_publication_date":"2021-10-13T09:32:15+0000","last_publication_date":"2021-10-25T13:25:42+0000","slugs":["home-page"],"linked_documents":[],"lang":"en-gb","alternate_languages":[],"data":{"slices":[{"slice_type":"carousel","slice_label":null,"version":"sktwi1xtmkfgx8626","variation":"default-slice","primary":{"arrowColor":"primary.main","dotColor":"primary.main"},"items":[{"title":[],"description":[],"textColor":"light.main","background":{"dimensions":{"width":1920,"height":1280},"alt":null,"copyright":null,"url":"https://images.prismic.io/ocb-base-local/2295dffc-65a3-4164-b496-3947db9892c2_meeting-1245776_1920.jpg?auto=compress,format"},"backgroundColor":"dark.main","ctaTextColor":"light.main","ctaBackgroundColor":"primary","ctaTextLink":[],"slideVariation":"full-width","imageFit":"cover"}]},{"slice_type":"available_offers","slice_label":null,"version":"sktwi1xtmkfgx8626","variation":"default-slice","primary":{"offers":{"id":"YXatGBIAACoAZddj","type":"offers","tags":[],"slug":"available-offers","lang":"en-gb","first_publication_date":"2021-10-25T13:11:57+0000","last_publication_date":"2021-10-25T13:11:57+0000","link_type":"Document","isBroken":false}},"items":[{}]}]}}],"version":"31acd9d","license":"All Rights Reserved"}

```

I imagine my GraphQuery should be something like this:

```auto
const graphQuery = `{
    home-page {
      ...home-pageFields
      ...on available_offers {
        non-repeat {
          ...non-repeatFields
        }
        repeat {
          ...repeatFields
        }
      }
    }
  }`;

```

But that doesn't work. Not sure how to achieve this...

---

<div class="post-metadata">

**Author:** ![Priyanka](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/priyanka/32/3223_2.png) [@Priyanka](https://community.prismic.io/u/Priyanka)\
**Post date:** [October 26, 2021, 1:06pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/3 "2021-10-26T13:06:51Z")

</div>

Hello @tomasvit6

Welcome to the Prismic community, and thanks for reaching out to us.

You have to specify the Content Relationship field to retrieve any content from the linked documents. The Content Relationship field won’t provide any content from the linked document unless you specify. Here is the [documentation for this](https://prismic.io/docs/technologies/graphquery-rest-api#retrieve-a-single-field-from-a-linked-document).

I believe in your case, your GraphQuery should be like this if your repeatable zone of the Slice has a content relationship:

```auto
const graphQuery = `{
    home-page {
      ...home-pageFields
      ...on available_offers {
        non-repeat {
          ...non-repeatFields
        }
        repeat {
          ...repeatFields
         name_of_content_relationship_field {
            ... on linked_doc_type {
              ...linked_doc_type_Fields
            }
        }
      }
    }
  }`;

```

You can change if you have a Content Relationship field in the non-repeatable zone. Give this a try, and let me know if you have any further questions.

Thanks  
Priyanka

---

<div class="post-metadata">

**Author:** ![tomasvit6](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tomasvit6](https://community.prismic.io/u/tomasvit6)\
**Post date:** [October 26, 2021, 4:35pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/4 "2021-10-26T16:35:59Z")

</div>

Thanks for your reply Priyanka. Unfortunately, that didn't help. I get an odd error:

```auto
{"type":"api_validation_error","message":"Unable to parse fetch query Invalid fetch parsing Exception.\n\nInvalid input ' ', expected AlphaNum, AlphaChar, '_', '-' or test (line 4, column 12):\n ...on available_offers {\n ^\n\n5 rules mismatched at error location:\n ...racketed/ /$anonfun/ +:-36 /Relation/ |:-5 /Fragment/ /FragmentName/ /Key/ capture:-2 / +:-2 / | / AlphaNum:<CharPredicate>\n ...acketed/ /$anonfun/ +:-36 /Relation/ |:-5 /Fragment/ /FragmentName/ /Key/ capture:-2 / +:-2 / | / AlphaChar:<CharPredicate>\n ...onfun/ +:-52 /Doc/ /bracketed/ /$anonfun/ +:-36 /Relation/ |:-5 /Fragment/ /FragmentName/ /Key/ capture:-2 / +:-2 / | / '_'\n ...onfun/ +:-52 /Doc/ /bracketed/ /$anonfun/ +:-36 /Relation/ |:-5 /Fragment/ /FragmentName/ /Key/ capture:-2 / +:-2 / | / '-'\n .../ /bracketed/ /$anonfun/ +:-52 /Doc/ /bracketed/ /$anonfun/ +:-36 /Relation/ |:-5 /Fragment/ /FragmentName/ <action> / test\n"}

```

Current implementation:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/b/b127e8b8733839696948c607b20a8682cececb6b.png)

---

<div class="post-metadata">

**Author:** ![Priyanka](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/priyanka/32/3223_2.png) [@Priyanka](https://community.prismic.io/u/Priyanka)\
**Post date:** [October 27, 2021, 9:51am UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/5 "2021-10-27T09:51:06Z")

</div>

Hello @tomasvit6

I think we are very close to solving it. By default, the Slices of your documents are found in the body section of the response object.  
Trying to modify your query with this:

```auto
const graphQuery = `{
  home-page {
    ...home-pageFields
    body {
     ...on available_offers {
       non-repeat {
         ...non-repeatFields
         name_of_content_relationship_field {
           ... on linked_doc_type {
             ...linked_doc_type_Fields
           }
        }
      }
        repeat {
          ...repeatFields
       }
     }
    }
  }
 }`;

```

Let me know if it still doesn't solve your issue.

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![tomasvit6](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tomasvit6](https://community.prismic.io/u/tomasvit6)\
**Post date:** [October 27, 2021, 12:10pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/6 "2021-10-27T12:10:06Z")

</div>

That just gives me:

```auto
{
"type": "api_validation_error",
"message": "Unable to parse fetch query Invalid fetch parsing Exception.\n\nUnable to find body in home-page"
}

```

---

<div class="post-metadata">

**Author:** ![Priyanka](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/priyanka/32/3223_2.png) [@Priyanka](https://community.prismic.io/u/Priyanka)\
**Post date:** [October 27, 2021, 12:57pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/7 "2021-10-27T12:57:51Z")

</div>

Can you please send me the URL of your Prismic repository? You can send me a private message though.

---

<div class="post-metadata">

**Author:** ![tomasvit6](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tomasvit6](https://community.prismic.io/u/tomasvit6)\
**Post date:** [October 27, 2021, 12:58pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/8 "2021-10-27T12:58:42Z")

</div>

Okay, done

---

<div class="post-metadata">

**Author:** ![Priyanka](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/priyanka/32/3223_2.png) [@Priyanka](https://community.prismic.io/u/Priyanka)\
**Post date:** [October 27, 2021, 3:26pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/9 "2021-10-27T15:26:31Z")

</div>

I have checked your repository. This issue is related to as GraphQuery doesn't work with Slice Machine slices, and this is already a known issue. This issue is already in our issue tracker, and I will update you when I get any updates from the product team.

---

<div class="post-metadata">

**Author:** ![tomasvit6](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tomasvit6](https://community.prismic.io/u/tomasvit6)\
**Post date:** [October 27, 2021, 3:34pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/10 "2021-10-27T15:34:02Z")

</div>

Is it possible to do the same with `fetchLinks`? I really don't want to call 2endpoints and then map them to achieve this. 😕

---

<div class="post-metadata">

**Author:** ![Priyanka](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/priyanka/32/3223_2.png) [@Priyanka](https://community.prismic.io/u/Priyanka)\
**Post date:** [October 28, 2021, 9:55pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/12 "2021-10-28T21:55:12Z")

</div>

Hello @tomasvit6

I understood your point, but It is not possible to retrieve the field in a Slice. My team will indeed look into the issue ASAP. I will update you when I get any updates from the team.

Thanks  
Priyanka

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [November 23, 2021, 2:40pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/14 "2021-11-23T14:40:15Z")

</div>

This thread is being monitored as an open ticket in the internal Prismic issue tracker. The Prismic support team will update this post as we get more information from our dev team. If you have a similar use-case, you can [‘Flag’ this topic to reopen](https://community.prismic.io/t/re-open-a-thread/2175) and add it here.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 3:20pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/15 "2021-12-09T15:20:15Z")

</div>



---

<div class="post-metadata">

**Author:** ![dinhhuy.trinh](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@dinhhuy.trinh](https://community.prismic.io/u/dinhhuy.trinh)\
**Post date:** [February 22, 2022, 8:42pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/16 "2022-02-22T20:42:27Z")

</div>

So do we have a way to achieve this yet?

---

<div class="post-metadata">

**Author:** ![Priyanka](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/priyanka/32/3223_2.png) [@Priyanka](https://community.prismic.io/u/Priyanka)\
**Post date:** [February 23, 2022, 2:25am UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/18 "2022-02-23T02:25:57Z")

</div>

Hello @dinhhuy.trinh

Our Slice Machine team has fixed that issue. Now you can retrieve linked documents data with GraphQuery.

Are you still getting any issues? If so, Could you give me more details about what do you want to achieve?

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dinhhuy.trinh](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@dinhhuy.trinh](https://community.prismic.io/u/dinhhuy.trinh)\
**Post date:** [February 23, 2022, 7:33am UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/19 "2022-02-23T07:33:25Z")

</div>

Hi,

I have a feature-blog-slice on my home page where editors can pick which blog they would like to display. In the feature-blog-slice, I have a "Content Relationship" linking to the blog type. I want to query all the blogs for the feature-blog-slice then display it on the home page.

I am using prismic client v6

```auto
const graphQuery = `{
    home-page {
      ...home-pageFields
      ...on feature-blog-slice {
        repeat {
          ...repeatFields
        }
      }
    }
  }`;

client.getSingle<PrismicDocument>("home-page", { ref, graphQuery})

```

The query looks the same as the OP's one. I got the same error

```auto
{"type":"api_validation_error","message":"Unable to parse fetch query Invalid fetch parsing Exception.\n\nInvalid input '

```

How does graphQuery work with prismic client? In my case, should I use client.getSingle or what? I cannot find any example from the documentation.

---

<div class="post-metadata">

**Author:** ![Priyanka](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/priyanka/32/3223_2.png) [@Priyanka](https://community.prismic.io/u/Priyanka)\
**Post date:** [February 23, 2022, 8:27am UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/20 "2022-02-23T08:27:51Z")

</div>

Hello @dinhhuy.trinh

You have to specify the API ID of the Content Relationship field to retrieve content from the linked documents. Learn more about [how to retrieve fields from linked documents](https://prismic.io/docs/technologies/graphquery-rest-api#retrieve-fields-from-a-linked-document).

If it still doesn't solve your issue, I need your repo name to debug it.

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [August 30, 2022, 5:43pm UTC](https://community.prismic.io/t/how-to-retrieve-linked-document-data-with-graphquery/7608/22 "2022-08-30T17:43:17Z")

</div>

We have released a new version of the GraphQuery document. Now it has support for Slice Machine.

> **[GraphQuery API Option Technical Reference](https://prismic.io/docs/technologies/graphquery-rest-api)**
>
> This shows how to use the Prismic GraphQuery query option to retrieve certain fields and retrieve content from linked documents.

Please let us know if you have questions, comments, or suggestions.  
Cheers!
