top of page
  • Writer's picturePriyanka Palshetkar

Exploring GraphQL as an alternative to REST API - Part 3

So let’s take an in depth look at how GraphQL is able to achieve this.


Even though we have the liberty to ask for what data we want, the application still needs to understand what kind of data architecture we are dealing with. We define this with the GraphQL schema. Schema is a contract between the client and the server. It has information about all our data and the operations that we can perform on our data. This is an example of our restaurant schema. So we have the information on our data and data fields. Like the Appetizers object. Similarly we will have the Drinks, Entres object etc. And we have information about the data operations, which are query, mutation and subscriptions.



So let’s look at the operations. Query Operation helps us to read the data. Mutation Operation is to write data to the database. Subscription Operation is to listen to some data events and then perform some action. So these are the major operations we can perform on our data using GraphQL.


To add to this, we also want to understand how GraphQL handles errors? If our request fails due to any reason, we get a GraphQL error object attached to our response in return. So then depending on whether this errors Object is present or not we can determine if our request is successful and take relevant actions.

Continued in Part 4

19 views0 comments

Comments


bottom of page