How can graphQL compare with REST performance ?

SPEAZ
Shopify Partner
26 3 11

Hello ! 

I dont see how GraphQL is supposed to maintain the same performance as REST when you deal with a lot of data ?

e.g if you want to grab 1000 products with all variants it's take 5sec with REST and 30sec+ with graphQl ?

Or maybe i am missing something ?

Replies 4 (4)

Ashish_Shah
Shopify Staff
20 7 9

Hello @SPEAZ 

I am not sure about the details of the query you are referring to which takes 5s on REST and 30s on GraphQL.   How many variants does each product have?  Also when did you last try this query with GraphQL?

 

We recently made significant changes to the Query Cost calculation on GraphQL specifically pertaining to querying connections. 

 

Below is an example query that cost 252 points but now only costs 13

query {
products(first: 250) {
edges {
node {
title
}
}
}
}

ALIAS | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

SPEAZ
Shopify Partner
26 3 11

Thanks for your answer

 

Here is an example for 2500 products : 

 

with REST 14sec and GraphQl 28sec so double of time with less data than REST !

it's not seems about the cost cause the bucket always stay at 1800 available but the time it take for the Graphql request to resolve 

so i'm wondering how it will be with 1000+ variants and more data ?

 

 

 

 

 query {
      products(first: 250) {
        pageInfo {
          endCursor
          hasNextPage
        }
        nodes {
          id
          tags
          options {
            name
          }
          handle
          vendor
          status
          updatedAt
          createdAt
          priceRangeV2 {
            minVariantPrice {
              amount
            }
          }
          options {
            id
            name
            position
            values
          }
          featuredImage {
            id
            url
          }
          description(truncateAt: 200)
          variants(first: 100) {
            pageInfo {
              endCursor
              startCursor
            }
            nodes {
              id
              title
              displayName
              price
            }
          }
        }
      }
    }​

 

 

Shayne
Shopify Staff
254 20 64

Hi Speaz, thanks for the questions!

I'm not sure why you're seeing such long query times on your GraphQL requests, the response time that you're seeing here is atypical. 

The response time for the REST request that you shared is going to vary too. Today in REST if you try to fetch 250 products with 100 variants on each one of those products, you're often going to get timeouts. You might get lucky and get a good cache hit that significantly shortens the response time — but a cold cache is real trouble for that REST client. Expand to 1000 variants, and you're looking at 250,000 variants being returned with a single call in a single response. Even without descriptions, that's a 150 MB JSON payload. That's too big. The REST throttle works on a calls-per-second basis regardless of complexity, which really starts hurting you if you need to paginate for a single resource.

You can expect that in real-world scenarios, GraphQL throughput is going to be about 3x faster than what you'd see from REST. It gets even faster than that when you start whittling down your responses to the specific fields that you need rather than fetching everything. 

Shayne | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

SPEAZ
Shopify Partner
26 3 11

Hello @Shayne 🙂

You was actually right , i was actually making my comparaison on orders.json / orders graphql api ( and fetch api there win far ahead) and i thought was the same for products endpoint

i didnt know products endpoint of graphql specifically was improved with speed connection and using less bucket , i thought it was the same for all graphql endpoint 😄

 

so i hope orders and other endpoint from graphql will follow that improvement !

thank you for your answer !