Introduction to Graph QL

In this article we are going to understand that what is GraghQL and what types of problem are solved by GraphQL.

What is GraphQL?

GraphQL is a query language for APIs (Application Programming Interfaces) and a runtime environment for executing those queries with your existing data. It was developed by Facebook in 2012 and open-sourced in 2015.

Before moving the WHY of GraphQL let's understand How APIs works.

Work as a way for different software applications to communicate and interact with each other. They define a set of rules and protocols that allow one piece of software (like an app or a website) to request and exchange data with another piece of software (like a server or a database).

  • Communication Protocols: APIs use communication protocols to define how data is transmitted between the client (requesting application) and the server (responding application). HTTP (Hypertext Transfer Protocol) is a common protocol for web APIs.

  • RESTful Protocols: Representational State Transfer (REST) is a popular architectural style for building APIs. It defines a set of constraints and conventions, including the use of standard HTTP methods like GET, POST, PUT, and DELETE.

Problem with RESTful API:

  • One key issue is over-fetching and under-fetching of data.

For example Imagine an application that displays information about users. In a RESTful approach, the server might provide an endpoint to fetch user details, but it would return all available information about a user, including fields that the client might not need at that moment.

Now GrapgQl Comes.

GraphQL addresses the over-fetching and under-fetching issues inherent in RESTful APIs by providing a more flexible and efficient data querying mechanism.

  • Single Request: Unlike REST, where multiple endpoints might be needed to gather related data, GraphQL typically allows clients to retrieve all necessary information in a single request. This reduces the number of network requests and can lead to faster data retrieval.

  • Schema-Based Approach: GraphQL uses a schema to define the structure of the data. This schema serves as a contract between the client and the server, ensuring that both parties understand what data can be requested and what will be returned.

  • No Overhead of Versioning: GraphQL's flexibility eliminates the need for versioning in APIs. Clients can evolve independently of the server, and new fields can be added to the schema without breaking existing clients.

This was the basic understanding of GraphQL and what type of problem is solve br graphQL.

In the upcoming Article we are coding to learn the implementation of Grpah QL in our machine and how we can implement the Schema of GraphQL.

I Hope you got something from my Article To know more about GraphQL follow the the Link

Thank you for reading my content. Be sure to follow and comment on what you want me to write about next 🤓.

Did you find this article valuable?

Support Saurabh verma by becoming a sponsor. Any amount is appreciated!