GraphQL - A query language for API - Part 1

Have you recently started hearing about GraphQL and wondering what is it all about?

Here is a short introduction to get you up to speed.


So, lets start with

What is GraphQL?

In simple words, its a query language for APIs. In other words, a client can query server using graphQL exactly what they need. GraphQL has its own format for request or you can say "graphQL query" which is very easy to read and understand for human eye. However, the response is in plain, old and much loved JSON format.


OK. so, where did it come from?

Brief history of GraphQL

GraphQL was developed by Facebook in 2012. Facebook open sourced GraphQL later on in 2015 and now its been maintained by large set of companies and individuals all over the world.




Alright! Let's dive in a bit deeper.


First thing first, GraphQL essentially is a specification which describes how a GraphQL server should be built.

So, what is a graphQL server? We will get there in a bit. Before that, let define few terminologies.


  1. Client system: This is a system which consumes data for example a front-end application like a web page.

  2. Back-end system: This is a system where data is kept at rest. This can be a RDBMS, a no-sql DB or even a file system storing data. You can also think of a complex system which includes many server.

  3. GraphQL query: Client system uses this query to fetch data from Back-end system

  4. GraphQL server: (Now we get to it), This is basically server side implementation of GraphQL specification. In other words, this server is responsible for exposing back-end system data as a GraphQL API which can be queried using GraphQL query.

Simplest form of a GraphQL query example is below.


{
    user{
        name
        age
    }
}

The above query will fetch response in JSON format as follows:


{
    "user":
        {
            "name":"John",
            "age":30
        }
}


Quite simple right!! One of the most powerful feature of GraphQL is you can query what data you want. Whereas, in REST based API, you don't have that choice, you can query resource, for example here "user" and you get every data associated with "user".


To get the above result, you need to implement core of GraphQL concept - the "GraphQL Server".

There are various concepts one should understand while implementing a GraphQL server such as its Type System, Schema, language to define Schema called Schema Definition language etc.

Good news is its fairly easy to learn and almost all Programming language has libraries supporting GraphQL server implementation.



In my next blog, I will try cover more details on implementation of GraphQL server with some examples. For now, Adios! Happy Learning!




5 views0 comments

Recent Posts

See All

"this" in javascript

Here we will talk about this keyword in javascript and how it is different from any other javascript object. "this" is and current context object in runtime engine, but unlike any other object the pro