JS Monday 12 - Building a GraphQL Server

Michele Riva
openmind
Published in
6 min readMay 5, 2019

--

Remember the good old SOAP protocol? Maybe you forgot it ’cause REST replaced it, and it’s way better!
But what if I tell you that we’ll soon wish to forget REST in favor of GraphQL?

The need for querying data

GraphQL is a query language created by Facebook in 2012 and open sourced in 2015.
It allows requests and manipulations for specific data, so clients have more control over what information the server will send.
A common REST problem is Data Overfetching: imagine you only want to know the first name and the email of a given user, but the API will return the entire profile… why do we get so many useless informations?
Now imagine that you only need a list of user IDs, but the API will return a huge array of objects containing every user’s informations. What a waste of time and resources!
GraphQL provides a declarative data fetching API, which allows you to require only what you need.

Type Safety

GraphQL queries are written in the Schema Definition Language (SDL), which requires strong typing. GraphQL schemas are validated during compile time, which means that the compilation will fail if any type error is found in your schema.

--

--