In this article, let’s talk about the trending GraphQL, a super cool tech built by Facebook which is now open-sourced. We will compare with REST API and understand the use case of GraphQL. We will also build a small prototype that demonstrates the integration of GraphQL in ASP.NET Core. You can find the source code at the end of the article. Let’s get started!

What is GraphQL?

GraphQL or Graph Query Language is an API Standard that was invented and open-sourced by Facebook. It basically is an alternative to REST APIs. GraphQL unlike the tradional REST API, gives the control to the Client so that the Client App / user gets to request for the specific data he wants. In simple words, it is a technology that can replace REST API to build high performance APIs. That said, it doesn’t mean that REST API are going to be nulled anytime soon. But there are quite a lot of scenarios where GraphQL can outperform REST APIs.

GraphQL is a query language for APIs. It gives a definition to the data in your API (Somewhat similar to Swagger, but does more). It is essentially a technology that allows the client to ask for what they need. Nothing more, Nothing less. This gives a lot of power and flexibility to the client as well as developers.

The main goal behind designing the GraphQL was to make the query smarter. Till now, with the traditional REST API approach we might have experienced over-fetching (where the API returns 10 fields but we need only 2) or under-fetching (API return only the IDs but we need more related data which forces us make a second API Resource call) of data. This means that the request and response in always coded and remains static throughout the lifetime of the application, right? GraphQL makes your system smarter and delivers only what is needed , thus reducing the number of roundtrips to the server.

#asp.net core #graphql

Getting Started with GraphQL in ASP.NET Core - Complete Guide
2.90 GEEK