we are migrating from REST API to GraphQL API, as advised by Shopify. However, we have found that for queries like the following, the GraphQL API often takes more than 10 seconds in average, when a similar query with REST API takes just about 300 milliseconds.
sure. Just a comment, I am sharing the ‘x-request-id’ of the responses, and not the ‘x-shopify-request-id’ as you mentioned, as I could not find that header.
In the following cases, the average time of the GraphQL API response has been around 2 seconds, which is still much larger than the REST API 300 milliseconds.
I am running into the same issue. I currently use the REST API to fetch all products and their variants in a single request, and it’s always been performant. Since working on the migration to the GraphQL API for the same query, I noticed GQL queries were significantly slower.
Here is an example from a Test site I own. Below is a comparison of 20 requests to get 100 products with their variants and media:
REST
HTTPService GET (979.7ms) [200] https://shogun-ayoub-store.myshopify.com/admin/api/2024-01/products.json?limit=100
HTTPService GET (989.7ms) [200] – same request
HTTPService GET (997.0ms) [200] – same request
HTTPService GET (1025.7ms) [200] – same request
HTTPService GET (991.6ms) [200] – same request
HTTPService GET (1012.5ms) [200] – same request
HTTPService GET (1155.2ms) [200] – same request
GraphQL
HTTPService POST (11.9ms) [200] https://shogun-ayoub-store.myshopify.com/admin/api/2024-10/graphql.json query Products
HTTPService POST (13719.0ms) [200] – same request
HTTPService POST (12736.9ms) [200] – same request
HTTPService POST (11387.7ms) [200] – same request
HTTPService POST (21240.6ms) [200] – same request
HTTPService POST (11915.4ms) [200] – same request
HTTPService POST (11811.5ms) [200] – same request
I have found REST to take ~1.3 second on average while GraphQL takes ~14 seconds on average to retrieve the same amount of data. I rely on fetching product data with variants/media during initial setup on my app, and would appreciate any tips on how to boost performance of the GraphQL API.
I just ran into this issue today as well. I though it was because I had a rather complex query with several fragments (which is partly to blame) But pulling circa 666 products (3 requests) using the rest api took just over 1.7 seconds whereas using graphql it took almost 10 seconds, after removing the fragments, with the fragments (conditional include as false) it took 19 seconds for the 3 requests.
Here is my GraphQL query
query getProducts(
$first: Int!,
$after:String,
$query:String,
) {
products(first: $first, after:$after, query:$query) {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
title
handle
descriptionHtml
description
productType
tags
vendor
publishedAt
createdAt
status
hasOnlyDefaultVariant
images(first:10){
nodes{
altText
url
}
}
options {
name
position
}
variants(first:100){
pageInfo{
hasNextPage
endCursor
}
nodes{
id
displayName
barcode
taxable
sku
price
compareAtPrice
inventoryQuantity
inventoryItem{
requiresShipping
id
measurement{
weight{
unit
value
}
}
}
selectedOptions{
name
value
}
}
}
}
}
}
{
"first": 250,
"query":"status:ACTIVE"
}
Please fix this before forcing us developers and app developers to migrate.
@gmac hey greg any movement on this, Im in the middle of building a new public app and I am guessing that It wont get approved if I am still using the rest api for reading products and variants? But we are talking about 10x slower querying with graphql than with rest for the same number of products/variants.