Introduction to GraphQL

Akash Verma
3 min readJan 27, 2020

If you have been following latest trend in web/mobile application development, you may have heard buzz around GraphQL. In this blog, we will be covering what GraphQL is, where does it fit in the existing setup and basic building blocks of GraphQL.

What is GraphQL?

A spec that describes a declarative query language to ask an api an exact data they want. This is achieved by creating a strongly typed schema for your API and client queries are validated against your schema.

Where does it fit in?

  • A GraphQL server act as a layer in front of many 3rd party services and connects them all with one GraphQL API.
  • A hybrid approach where GraphQL server has a connected DB and also communicates with 3rd Party services

All the incoming request hits the GraphQL server and it decides what needs to called upon depending on the incoming request from the client side.

Basic building blocks

The GraphQL schema is the core of any GraphQL project. Nested in a GraphQL server, it defines every functionality available for the GraphQL client.The most basic element of each schema is a type which allows establishing relations between different schema elements & define allowed GraphQL operations to be performed on the server and more. Let’s discuss the basic parts of Schema Definition language(SDL):

  • Types: A construct defining shape with fields.
  • Fields: Keys on Type that have a name and value type.
  • Scalars: A primitive built in type in GraphQL.
  • Query: Defines how client can access data.
  • Mutation: Type that define how client can modify and create data.
  • Resolvers: Functions that are responsible for returning values for fields that exists on type in schema. Resolver execution is dependent on incoming request. It can retrieve data from any source.

To create a server, at minimum, we need a Query Type with a field, and a Resolver for that field. This is how a typical schema looks like.

Thinking in Graphs

Your API is no longer a predefined list of operations that always return the same shapes. Instead, your API is a set of Nodes that know how to resolve themselves and have links to other Nodes. This allows a client to ask for Nodes and then follow those links to get related Nodes.

I believe GraphQL is really powerful and promising approach to client-server communication which resolves only the requested data rather than all the properties of endpoint resulting in fewer bits of data transferred.

If you liked reading this, don’t forget to clap. 👏👏

You can also follow me on twitter @Akash940 for JavaScript or React updates.

Thank-you!

--

--

Akash Verma

JavaScript Enthusiast, Software Engineer @goevive. Follow me on twitter @Akash940