GraphQL product API is extremely slow

GraphQL product API is extremely slow

sinuhe
Shopify Partner
27 0 6

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 2 (2)

PageFly-Amelia
Shopify Partner
603 165 236

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
27 0 6

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