GraphQL product API is extremely slow when requesting variants

Hi there,

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.

Could you take a look in order to optimice it?

Kind regards, this is the query:

{
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
}
}
}

1 Like

Hey Sinuhe, can you share your x-shopify-request-id that you can find in the response header for one of your slow GraphQL requests?

Hi,

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.

  • c47735f5-cf64-45e3-a909-264a467ddbba-1732797069
  • fcdf55b9-e8a5-438e-a757-d6bd67ff0bc3-1732797066
  • 2ab9648d-da44-463c-96be-8857828acb77-1732797061
  • 14edd838-e3a1-4c73-997a-5ea811b45d25-1732797058
  • 787b9be2-efb2-4989-a9ba-a4643cbecfe0-1732797103
  • eb035eeb-e4c8-4b4d-8166-35bc4c743284-1732797101

Hope it helps :slight_smile:

@teddyhwang Any updates on this request?

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.

1 Like

@abel1756 as long as you posted within the past few hours, mind posting a request ID from today? We are actively working on this discrepancy.

@gmac thanks for looking into this!

I re-ran the GQL query to pull 100 products with variants and media, here are the results with their request IDs:

GraphQL

HTTPService POST (12918.9ms) [200] https://shogun-ayoub-store.myshopify.com/admin/api/2024-10/graphql.json query Products
request-id: 1376502c-fad5-40a5-b811-4f80cb936b5b-1736451960
HTTPService POST (11443.2ms) [200] query Products
request-id: a2546343-2d75-44a5-8cf6-a3d87a6555e5-1736451973
HTTPService POST (11187.7ms) [200] query Products
request-id: cbada3b1-622f-41ce-893b-0b4fc0cb2569-1736451985
HTTPService POST (12696.8ms) [200] query Products
request-id: 6292f08a-e422-49c3-8d42-a8129e7a35cf-1736451996
HTTPService POST (13544.7ms) [200] query Products
request-id: 2ca1cdb3-9805-422e-b83b-34fc59e7abad-1736452009
HTTPService POST (13036.5ms) [200] query Products
request-id: 38b6c361-3d36-428b-baf0-2711716fda51-1736452023
HTTPService POST (15661.6ms) [200] query Products
request-id: 087032ed-415d-4542-bc09-179fc22d61ce-1736452036
HTTPService POST (12198.7ms) [200] query Products
request-id: 5197cadf-3b76-4806-8691-515b0966e3ef-1736452052

REST

Here are benchmarks for REST with their request IDs for reference:

HTTPService GET (1059.1ms) [200] https://shogun-ayoub-store.myshopify.com/admin/api/2024-01/products.json?limit=100
request-id: d5d15265-5fdb-4f5f-af82-b8ab9d89568d-1736452669
HTTPService GET (955.5ms) [200]
request-id: 9f25c745-feb7-4412-bf62-fe68d74a7734-1736452670
HTTPService GET (970.2ms) [200]
request-id: 89217e8e-c513-4bfa-a746-fde39f7029ed-1736452671
HTTPService GET (1049.1ms) [200]
request-id: 054ba350-e73e-45a2-a008-e6e044296ead-1736452672
HTTPService GET (972.5ms) [200]
request-id: 1ff9279f-f592-4a9e-a1a9-6aa1357ffc0a-1736452674
HTTPService GET (972.2ms) [200]
request-id: 5409f64e-5f0a-4253-9608-4eb7b8847050-1736452675
HTTPService GET (954.0ms) [200]
request-id: f19d1a62-6059-4d0c-ae01-33569306ab81-1736452676
HTTPService GET (952.5ms) [200]
request-id: c8be1406-80e9-4679-8800-d5c3922259c6-1736452677
HTTPService GET (954.8ms) [200]
request-id: e16f7a1c-59ff-4f0f-b860-8cc37077a438-1736452678
HTTPService GET (1181.8ms) [200]
request-id: 1e7a9343-effd-4c86-a729-572394eb1940-1736452679

1 Like

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.

Cheers,
Gary