GraphQL API Query Size

Im trying to make a (large)call to the graphql api and I get a error telling me the query is too large:

Im tying to keep this down to one api request. Does anyone know if its possible to configure the maximum allowed query size?

1 Like

Because we cache GraphQL queries and the responses to increase performance there is a fixed limit on the size of a query equal to 8kb (8192 bytes). Unfortunately this isn’t configurable or adjustable.

Your query is only 224 bytes above the limit (8416 bytes vs 8192 bytes); have you removed extra whitespace from your query and are you using fragments where that makes sense?

1 Like

@charlie We have this problem too. Is there another way to minify/compress the query? We already removed whitespaces and other unneeded characters from the query. (reducing from 60k to 9k)

Hi @ardeshir.valipoor! Welcome to the community!

There are libraries that will automatically remove unnecessary whitespace and comments like graphql-query-compress. Sounds like you have already done that though.

Are you making use of fragments where possible?

1 Like

Hey! Thanks @charlie
yes, we are using fragments but I am not sure if we are using in correctly.
I can share the query with you for the review.

Fragments can be rather counterproductive here, because their definitions are included in the query. So it depends on the case. Unless you really use a certain fragment multiple times (enough that the definition overhead is smaller than inline repititions would be) the query size will be bigger with that fragment definition than without. So you might have to ditch clean code using fragments to satisfy this ridiculous limitation.

We actually hit the issue at the moment, I’m not sure if compressing the query is the long term solution. Since we are querying first the IDs of the items that we want, and from all of the IDs we further filter it base on other criteria.

I am thinking that if we have let’s say 1,000+ IDs hopefully it will not hit the limit but I doubt it since we are just compressing the graphql query string.

Anybody found out a way to possibly solve this problem?