Using GraphQL to workaround the graphQuery limit

Hello! I am working on a fairly large Prismic project with 40+ slices using graphQuery. I recently ran into this error trying to build a new page: “PrismicError: An invalid API response was returned”. The only other information provided was the Prismic api search url which is very long and looks like a condensed version all of the queries I’m using to fetch the data/content relationships for this page. After doing some digging, I discovered the 2048 character limit for Request URLs to the Rest API outlined here. I also found several threads talking about how to optimize this, but the only tip I could seem to find is using a white space tool…

I was able to double the amount of slice queries I can fit into the request by stripping whitespace/tabs, but its still not enough to access the full library. I am able to fit roughly 20 components in one request, but beyond that it maxes out and throws the invalid api response error. I’m very confused to why the queries are being sent over a GET request, this doesn’t seem like a scalable solution.. Is graphQuery meant for smaller Prismic projects? Each slice can have a variable amount of fields and most of my slices require a custom query to resolve content relationships.

Could GraphQL be a work around to this problem? I was reading the docs on setting up GraphQL with Apollo and came across the “useGETForQueries” boolean. If that’s false, will requests from the Apollo client work with Prismic? A POST request makes the most sense here to allow for a growing slice library.

Screen Shot 2023-02-01 at 9.39.31 AM

Thanks in advance, I would appreciate any insight into this.

Hello @maxwell

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

GraphQuery is different than GraphQL. GraphQuery is an updated version of fetchLinks which allows you to retrieve content from a Content Relationship field using the REST API. Unlike GraphQL, GraphQuery does not accept arguments.

GraphQL, however, is an alternative to the REST API. Our GraphQL API is today relying on GET, so when you fire a request, you’re limited by GET constraints. For example, limitations in terms of character. With graphql too, you need to break up queries by not going too many levels deep can help.

You might want to check this discussion on this thread: 413 Request Entity Too Large - #32 by prismic5

Let me know if you have any further questions.

Thanks,
Priyanka