# Migration from fetchLinks to graphQuery

**URL:** <https://community.prismic.io/t/migration-from-fetchlinks-to-graphquery/12369>\
**Category:** Developing with Prismic\
**Created:** [February 7, 2023, 1:04pm UTC](https://community.prismic.io/t/migration-from-fetchlinks-to-graphquery/12369 "2023-02-07T13:04:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreas.kratzel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/andreas.kratzel/32/415_2.png) [@andreas.kratzel](https://community.prismic.io/u/andreas.kratzel)\
**Post date:** [February 7, 2023, 1:04pm UTC](https://community.prismic.io/t/migration-from-fetchlinks-to-graphquery/12369/1 "2023-02-07T13:04:22Z")

</div>

Hi there,

I stumbled upon the issue that `fetchLinks` only returns the `first` element of a specific field - in my case, the rich text field. So the second and third paragraphs are not returned. Quite a bummer.

I read that graphQuery is being referred to as `fetchLinks v2`, but tbh the syntax is just much more complex and not really intuitive - I know, it's basically gql syntax, but fetchLinks was just straightforward and simple.

I am having a hard time as well to migrate fetchLinks to graphQuery.

My use case is on the homepage, where I have some slices that have a content relationship field. With fetchLinks, I could simply do the following:

```auto
const doc = await client.getByUID("generic_page", params?.uid as string, {
    fetchLinks: [
      "crosspromo.image",
      "crosspromo.title",
    ]
});

```

CrossPromo is a slice that contains a content relationship to a single `crosspromo` which is a repeatable custom type.

Not sure how that would translate to graphQuery tbh.

Could you help me out here?

Thanks!

---

<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 9, 2023, 9:59am UTC](https://community.prismic.io/t/migration-from-fetchlinks-to-graphquery/12369/4 "2023-02-09T09:59:26Z")

</div>

Hello @andreas.kratzel

Thanks for reaching out to us.

It's true that fetchLinks doesn't work if you want to retrieve linked content from Slices and Group fields. For that, you must use graphQuery. Let me allow you to clarify one thing that GraphQuery is different than GraphQL. GraphQuery is an updated version of fetchLinks which allows you to retrieve content from a Content Relationship field when using the REST API.

I think that your GraphQuery will look something like this:

```auto
generic_page {
  body {
    ...on CrossPromo {
        non-repeat {
          ...non-repeatFields
          content_relationship_field_name {
           ... on type_of_linked_doc {
             ...linked_doc_type_Fields
          }
        }
     } 
   }
}

```

Give that a try and let me know if it works for you. Keep in mind that you’ll need to update `content_relationship_field_name`, on type\_of\_linked\_doc, and linked\_doc\_type\_Fields` with the API ID of the Custom Type that you are querying. Please follow this article: [GraphQuery API Option Technical Reference - Documentation - Prismic](https://prismic.io/docs/graphquery-rest-api#slice-content-of-a-linked-document-within-a-slice-with-the-legacy-builder)

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![andreas.kratzel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/andreas.kratzel/32/415_2.png) [@andreas.kratzel](https://community.prismic.io/u/andreas.kratzel)\
**Post date:** [February 9, 2023, 11:09am UTC](https://community.prismic.io/t/migration-from-fetchlinks-to-graphquery/12369/5 "2023-02-09T11:09:53Z")

</div>

Thanks, I'll give it a try and lyk 👍

---

<div class="post-metadata">

**Author:** ![andreas.kratzel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/andreas.kratzel/32/415_2.png) [@andreas.kratzel](https://community.prismic.io/u/andreas.kratzel)\
**Post date:** [February 9, 2023, 11:12am UTC](https://community.prismic.io/t/migration-from-fetchlinks-to-graphquery/12369/6 "2023-02-09T11:12:58Z")

</div>

btw, why don't you internally rework the fetchLinks functionality instead of coming up with a whole new syntax that's just awfully overcomplex?

```auto
graphQuery={
  page {
    slices {
      ...on paragraph_slice {
        variation {
          ...on default {
            primary {
              details {
                ...on author {
                  slices {
                    ...on contact_slice {
                      variation {
                        ...on default {
                          items {
                            name
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

```

@Priyanka

---

<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 10, 2023, 2:00pm UTC](https://community.prismic.io/t/migration-from-fetchlinks-to-graphquery/12369/7 "2023-02-10T14:00:17Z")

</div>

Hello @andreas.kratzel

I understand that using graphQuery is a bit complex and has an entirely different syntax, but once we learn it, I assume it wouldn't be a big problem. I will open this conversation to my team and see if we can simplify them. I'll have to continue this conversation internally.

Thanks,  
Priyanka
