# Optimise GraphQuery hitting limit

**URL:** <https://community.prismic.io/t/optimise-graphquery-hitting-limit/5020>\
**Category:** Developing with Prismic\
**Tags:** rest-api\
**Created:** [April 19, 2021, 2:40pm UTC](https://community.prismic.io/t/optimise-graphquery-hitting-limit/5020 "2021-04-19T14:40:29Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [April 19, 2021, 2:40pm UTC](https://community.prismic.io/t/optimise-graphquery-hitting-limit/5020/1 "2021-04-19T14:40:30Z")

</div>

Moving this post here:

> [@GraphQL/Graphquery and Slice Machine Update](https://community.prismic.io/t/graphql-graphquery-and-slice-machine-update/4925/7):
>
> On that note, I was wondering if you have any tips on handling long/large body slices with content relationships.
> 
> I feel within my NextJS app, I could improve the way in which I use GraphQuery with the API.
> 
> For instance, I've got a large GraphQuery for a PPC marketing landing, when I've had to add a new component, with a new slice lately, it leaves me too long a query request, which means the requests fails.
> 
> This is due to needing to get a number of relationship-based fields further down the slices tree. Which then results in a long GraphQuery file. For instance:
> 
> ```auto
> landing_page{
> ...landing_pageFields
> body{
> //otherslices
> ...onadd_related_product{
> repeat{
> ...repeatFields
> related_product{
> ...onproduct_page{
> ...product_pageFields
> primary_category_rel{
> ...onprimary_category{
> ...primary_categoryFields
> }
> ...onmanaged_laundry{
> uid
> heading
> }
> }
> manufacturer{
> ...manufacturerFields
> }
> related_sub_type{
> ...onsub_type{
> ...sub_typeFields
> }
> }
> category_rel{
> ...onproduct_type{
> ...product_typeFields
> }
> ...onmanaged_laundry{
> uid
> heading
> }
> ...onsignage_software{
> uid
> heading
> }
> ...ontv_info_page{
> uid
> heading
> }
> ...onguestcast_page{
> uid
> heading
> }
> ...ondetergents_auto_dosing{
> uid
> heading
> }
> }
> }
> }
> }
> }
> //otherslices
> }
> }
> 
> ```
> 
> Should I be splitting longer body slice queries up into small chunks?
> 
> Then doing another request during build time to get the additional content, say requesting the product\_page data, if a product type exists top\_product through a separate function.
> 
> PS: The only solution I've had is trimming whitespace. Which works to an extent.

---

<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:** [April 19, 2021, 2:44pm UTC](https://community.prismic.io/t/optimise-graphquery-hitting-limit/5020/3 "2021-04-19T14:44:11Z")

</div>

Hey @daf ,

When you say "Which then results in a long GraphQuery file" do you mean you're hitting the 2048 character limit in the query URL?

If so from your example I don't have any other suggestions than removing the whitespace. I think the best course of action is splitting the query up like you suggested and making multiple queries.

---

<div class="post-metadata">

**Author:** ![daf](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/daf/32/1160_2.png) [@daf](https://community.prismic.io/u/daf)\
**Post date:** [April 19, 2021, 2:59pm UTC](https://community.prismic.io/t/optimise-graphquery-hitting-limit/5020/4 "2021-04-19T14:59:12Z")

</div>

Thanks Phil,

I think removing whitespaces ended up being sufficient in the end.

When eventually moving to GraphQL, it will definitely need a larger refactor in how I return queries and structure the data. Though when I come to it, I'll solve that issue.

---

<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:** [April 19, 2021, 3:04pm UTC](https://community.prismic.io/t/optimise-graphquery-hitting-limit/5020/5 "2021-04-19T15:04:52Z")

</div>

Great, let me know how that goes. 🙂

_ **For future readers, here are some optimisation tips:** _

For Slices you grab all the info like:

```auto
{
  blog {
    body {
      ...on text_block {
        non-repeat {
          ...non-repeatFields
        }
      }
      ...on image_gallery {
        non-repeat {
          ...non-repeatFields
        }
        repeat {
          ...repeatFields
        }
      }
    }
  }
}

```

We explain that in more detail here:

> **[API reference for GraphQuery (fetchLinks v2)](https://prismic.io/docs/technologies/graphquery-rest-api#all-fields-in-a-slice)**
>
> This shows how to use the Prismic GraphQuery query option to retrieve certain fields and retrieve content from linked documents.

For removing the whitespace you'll still need the new lines, so it will work like your example here:

```auto
{
blog{
body{
...ontext_block{
non-repeat{
...non-repeatFields
}
}
...onimage_gallery{
non-repeat{
...non-repeatFields
}
repeat{
...repeatFields
}
}
}
}
}

```

You can use this tool to do it for you:

> **[Remove All Whitespace from Text - Online Text Tools](https://onlinetexttools.com/remove-all-whitespace-from-text)**
>
> Super simple, free and fast browser-based utility for removing all whitespace from text. Just paste your text and you'll instantly get all whitespace deleted. Textabulous!

---

<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:** [April 20, 2021, 3:05pm UTC](https://community.prismic.io/t/optimise-graphquery-hitting-limit/5020/6 "2021-04-20T15:05:46Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

---

<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, 4:22pm UTC](https://community.prismic.io/t/optimise-graphquery-hitting-limit/5020/7 "2021-12-09T16:22:04Z")

</div>


