Shopify REST API vs GraphQl

Shopify allows us to use GraphQL and REST API, which allows us to communicate with the back end of the store from the perspective of the code on the front. In the past REST has been a generally accepted standard in the design and development of APIs, but for a few years GraphQL has been gaining popularity and gaining more and more fans.

Facebook revolution

Facebook presented GraphQL as a revolutionary alternative to REST APIs, so the difference between the two approaches is considerable. REST is the general architectural standard for creating APIs, while GraphQL is also a query language and a set of tools that operate on one endpoint using HTTP protocol.
The advantage of consuming REST API is simplicity, we don’t need any libraries or external packages for this. We send a request using e.g. fetch (which is natively available in JavaScript) or axios, after which the server returns a response. One of the REST problems is “over fetching”. The point is that we can not limit the fields returned by the API, we will always get the full set of data. In the case of GraphQL we can specify the fields we want to receive in response.

For example, imagine that we have a movie board where each object contains information about a single movie; title, description, director, etc., and we want to display only movie titles on the front. Using GraphQL, we can specify the request to get data from a particular field, e.g. ‘title’, and we don’t have to wait for the server to return the whole set of data to display the movie titles themselves later.

This is more than the API

As I mentioned above, GraphQL is also a set of tools, as GraphiQL is an example. It is an integrated environment, a tool that helps us to build the correct query structure and mutations (a newer and more interesting equivalent of this IDE is GraphQL Playground). Thanks to Apollo we have access to the client (CLI), which allows us to manage the state of applications in React based on smooth GraphQL operations. Learning curve can also be a disadvantage of this environment, but the time spent on learning it will certainly pay off.
Both these API development standards have their pros and cons, so there is not a single golden mean. Using GraphQL requires us to know the whole environment related to it, while we can consume the REST API using for example the default JavaScript interface.

Hubert Strawa
Frontend Developer, travel lover and collector of vinyl records. He deals with the implementation of websites and online stores on a daily basis.

Recommended news

Leave a Reply

Porozmawiaj z nami
Czat udostępnia CRM