Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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.
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:
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 } } }
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 } } }
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.
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.
Monitor and Analyze Performance: Use performance monitoring tools to identify and optimize slow queries. GraphQL tracing can help you understand where the bottlenecks are.
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.
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
We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024