GraphQL product API is extremely slow

GraphQL product API is extremely slow

sinuhe
Shopify Partner
29 0 9

Hi there, 

 

we are migrating from REST API to GraphQL API, as advised on https://www.shopify.com/partners/blog/all-in-on-graphql. However, we have found that for queries like the following, the GraphQL API takes more than 10 seconds in average, when a similar query with REST API takes just about 30 milliseconds. 

 

Could you take a look in order to optimice it?

{
products(first: 250, query: "published_status:published") {
nodes {
description
id
handle
productType
title
vendor
publishedAt
updatedAt
tags
featuredImage {
url
}
variants(first: 250) {
edges {
node {
id
title
availableForSale
compareAtPrice
barcode
price
sku
image {
url
}
}
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}

 

Kind regards.

Replies 6 (6)

PageFly-Amelia
Shopify Partner
626 165 238

Hi @sinuhe ,

This is Amelia from PageFly - a Landing Page Builder App,

Migrating from REST to GraphQL can bring performance challenges, especially with complex queries. Here are some strategies to optimize your GraphQL query for better performance:

  1. Limit the Number of Fields: Only request the fields you need. Each additional field increases the complexity and processing time of the query.

    {
      products(first: 250, query: "published_status:published") {
        nodes {
          id
          handle
          title
          vendor
          featuredImage {
            url
          }
          variants(first: 250) {
            edges {
              node {
                id
                title
                price
              }
            }
          }
        }
        pageInfo {
          endCursor
          hasNextPage
        }
      }
    }
    
  2. Use Pagination: Instead of fetching 250 products and their variants in one go, consider fetching smaller batches. This reduces the load on the server and can improve response times.

    {
      products(first: 50, query: "published_status:published") {
        nodes {
          id
          handle
          title
          vendor
          featuredImage {
            url
          }
          variants(first: 50) {
            edges {
              node {
                id
                title
                price
              }
            }
          }
        }
        pageInfo {
          endCursor
          hasNextPage
        }
      }
    }
    
  3. Optimize Query Complexity: Shopify’s GraphQL API uses a calculated query cost method to manage rate limits. Reducing the complexity of your query can help stay within these limits and improve performance.

  4. Batch Requests: Use tools like DataLoader to batch and cache requests. This can reduce the number of requests sent to the server and improve performance.

  5. Monitor and Analyze Performance: Use performance monitoring tools to identify and optimize slow queries. GraphQL tracing can help you understand where the bottlenecks are.

  6. Leverage Caching: Implement caching strategies to reduce the load on your server. Cache frequently accessed data on the client or server side.

I hope that my solution works for you.

Best regards,

Amelia | PageFly

Please let me know if it works by giving it a Like or marking it as a solution!


➜ Optimize your Shopify store with PageFly Page Builder (Free plan available) 
➜ Weekly updated Shopify tutorials on YouTube 


All features are available from Free plan. Live Chat Support is available 24/7.

sinuhe
Shopify Partner
29 0 9

Thanks Amelia, 

 

of course I can optimize my query, and I will have 🙂

 

But my comment is more about why are we forced to migrate to a much slower system. I mean, the same query is more than 20 times faster with the REST API, so I just ask Shopify to try to optimize it, in order to make this mandatory migration to GraphQL smoother.

 

Kind regards,

    Fran

fb_123
Shopify Partner
7 0 4

Yes, the entire promise and selling point of GraphQL was to make things easier on the client. If you're forced to reduce the limit of records (even when the max limits fit in your allotted cost points) and have to use pagination or some other tools, that's simply crazy. Remove one layer of complexity to add another. Completely defeats the purpose. I think that certain things in GraphQL don't seem 100% thought out. It's probably increased complexity a lot on Shopify's side, too. There's quite a lot of breaking changes/churn with each API version, for such a newly designed API. Lots of renaming of fields, and removing fields that were added not that long ago etc.

I'd much prefer to do 5 REST queries in parallel, then join records on my end (Ruby has features that make this easy), than build these massive queries. I hope you find some answers OP. Your query looks extremely common. It should take milliseconds.

DoggyMugs
Shopify Partner
3 0 1

I got excited when I started looking at the 2025 shopify store front api. The first time I hooked it up the request were instant. One day later, every single one is abysmally slow. 10 to 20 plus seconds to fetch a collection with 17 products in it.

 

Right here https://shopify.dev/docs/api/usage/rate-limits it says this thing has no rate limits. I thought hmmm maybe it's a network fluke. Nope. Even the create cart requests can take 10 to 20 or more seconds. 

 

This makes buy buttons faster than the store front api by a long shot.

 

I sent a help ticket and got a response that says we are changing the way we do help tickets. I don't want to talk to crappy AI chat bots. It drives all of us insane. 

 

Here is my query. Any help is appreciated.

 

 var graphqlQuery = new
 {
     query = $@"
         query {{
            collection(id: ""gid://shopify/Collection/{collectionId}"") {{
                 id
                 title
                 description
                 image {{
                     url
                     altText
                 }}
                 products(first: 20) {{
                     edges {{
                         node {{
                             id
                             title
                             description
                             featuredImage {{
                                 url
                                 altText
                             }}
                             variants(first: 40) {{
                                 edges {{
                                     node {{
                                         id
                                         title
                                         sku
                                         price {{
                                             amount
                                             currencyCode
                                         }}
                                         image {{
                                             url
                                             altText
                                         }}
                                     }}
                                 }}
                             }}
                         }}
                     }}
                 }}
             }}
         }}"
 };

 

 

fb_123
Shopify Partner
7 0 4

10 seconds is too high. The query looks common enough that it should probably be optimized on their end, so this delay sounds more like a bug than anything else. Perhaps try with a "node" query and see if works better. Also, why does the query have duplicate "{{" and "}}"?

 

node(id: $id) {
on ... Collection {
 
}
}
DoggyMugs
Shopify Partner
3 0 1

Thank you. It has become instant again - shrug emoji 🙂