GraphQL Query Size Limit Reached

I think I found a solution to this @Fares. I did more research into what the reference GraphQL library gives us as developers. They built a really nice function that minifies queries for us:
stripIgnoredCharacters. I implemented it today and it fixed my issue about large query sizes.

Sample implementation below:

// This is a query to get each Page by its uid, so we have to programmatically provide that uid
export async function getSingleLandingPage(uid, previewData) {
  const dataCondensed = stripIgnoredCharacters(`
    query LandingPage($uid: String!, $lang: String!) {
      landing_page(uid: $uid, lang: $lang) {
        // do your work here
      }
    }
  `)
  
  // fetch from Prismic with condensed info
  const data = await fetchAPI( dataCondensed,
    {
      previewData,
      variables: {
        uid,
        lang: API_LOCALE,
      },
    }
  )
  return data
}
1 Like