Shopify APIs: GraphQL or REST, Which One Should I Use for My App?

As a developer building an app for the Shopify platform, you may be wondering which API to use: GraphQL or REST. In this article, we will explore the differences between these two APIs, as well as the usage limits on the Shopify platform.

What is REST?

REST, or Representational State Transfer, is a popular architectural style for building APIs. It is based on the HTTP protocol and follows a set of constraints that define how the API should behave. REST APIs allow developers to retrieve, create, update, and delete resources using the HTTP methods GET, POST, PUT, and DELETE, respectively.

REST APIs are organized around resources, and each resource is identified by a unique URL. For example, in a Shopify store, the products resource might be located at the URL https://store.myshopify.com/admin/products. To retrieve a list of products, a developer would make a GET request to this URL. To create a new product, they would make a POST request with the product information in the request body.

What is GraphQL?

GraphQL is a query language for APIs that was developed by Facebook. It allows developers to specify exactly what data they need from an API, and the API will return only that data. This is in contrast to REST APIs, which often return a fixed set of data for a given endpoint.

One of the main benefits of GraphQL is that it allows developers to request exactly the data they need, reducing the amount of data transferred over the network and increasing efficiency. It also allows for more flexible and dynamic data querying, as the shape of the data returned can be tailored to the needs of the client.

Usage Limits

Both the GraphQL and REST APIs on the Shopify platform have rate limits to ensure fair resource allocation and prevent abuse. These limits are based on the type of app and the plan it is on.

For the REST API, the usage limits depend on the app’s plan and the type of request being made. For example, a private app on the Shopify Plus plan can make up to 4 requests per second, while a public app on the Basic plan is limited to 2 requests per second.

The GraphQL API has a different set of limits, based on the number of requests made per minute and the complexity of the queries. This is based on the Leaky Bucket Algorithm, where a bucket of points is refilled at a set amount per second. This allows for large data requests in bursts, or for recurring smaller data requests over time.

It is important to consider these usage limits when deciding which API to use for your app. If you anticipate a high volume of requests, or if you need to make complex queries, you may want to consider using the GraphQL API, especially if the data required is being queried from multiple Shopify Objects (e.g. joining customer location with order line items, or product-collection relationships).

In conclusion, both the GraphQL and REST APIs on the Shopify platform have their own strengths and usage limits. As a developer, it is important to consider the needs of your app and the type of data you need to work with when deciding which API to use. In most use cases, using both REST and GraphQL is common in order to gather and process the data in the efficient manner that Shopify merchants require.