GraphQL vs Rest: New Server for Elastic Path Commerce Cloud
The recently released GraphQL Server for Elastic Path Commerce Cloud provides a GraphQL implementation of Elastic Path Commerce Cloud APIs to support shopping experiences. This release enables developers more familiar with GraphQL, as compared to REST, to more easily build shopping experiences.
GraphQL vs REST
We often get asked about REST vs GraphQL. In our experience you can do almost anything with both REST and GraphQL. There are some technical differences, but nothing that's a roadblock in achieving a business goal. The choice between REST and GraphQL comes down to preference. An analogy would be that humans communicate in many languages - English, French, Mandarin, German etc. Some languages might be "better" for some things. However, there are very specific nuances and can oftentimes be difficult for a non-native speaker. People would prefer to speak in their native language, solely due to preference and comfort level. The same goes for choosing between GraphQL and RESTFUL APIs.
At Elastic Path, we prefer REST because it follows HTTP protocol standards. This enables us to keep our APIs clean and simple, and REST APIs can take advantage of all the efforts to improve web performance at every level. As an example, it is relatively simple to use browser caching and CDNs to optimize HTTP requests.
At the same time, we also recognize that GraphQL makes some things easier for developers consuming APIs. You may prefer GraphQL because you are familiar with it, or that it makes it easier to wrap different APIs together, or any other reason by which GraphQL makes the front-end development easier for you. We certainly want to give you the choice of using the technology that works for you.
GraphQL Server for Elastic Path Commerce Cloud
The GraphQL server provides the following capabilities:
- Ability to build shopping experiences using Elastic Path Commerce Cloud and GraphQL
- Convenience of wrapping APIs from different systems and vendors with a single GraphQL endpoint
The GraphQL server is easy to consume. The readme provides steps on how to set it up on your machine and deploy to the cloud. As the source is available to you, you can add additional data sources to wrap multiple APIs from different systems and vendors. You can also use something like Apollo Federation to aid with this.
GraphQL in Action
The GraphQL server comes with GraphQL Playground which is an interactive, in-browser GraphQL IDE. Here’s a simple query to fetch nodes and products in a storefront.