How to start with GraphQL?

Deepak Mankotia
3 min readMar 4, 2021

--

What is GraphQL?

GraphQL is essentially a query language for your API. It is a way of asking for data from API. It offers a flexible way of asking for data, and you can get as much or as little data as you need.

A typical GraphQL implementation involves GraphQL on the server side (GraphQL API) and GraphQL on the client side (to talk to GraphQL APIs). A lot of different tools can be used to build a full-stack GraphQL application — such as Prisma, Apollo, Express, Hasura. At its core, it is just an API served over HTTP. You can send a curl command to talk to a GraphQL API without having to need any library. What is cool about GraphQL is that it provides an easy way of developing APIs — extending as well as deprecating over time. With GraphQL, you get one endpoint — /graphql and since every client talks to the same endpoint, it becomes very simple to add to an existing API and ensure that all clients are able to leverage newly updated data.

One thing to remember is that GraphQL is just a specification. How you implement GraphQL largely depends on the library (Apollo, Prisma, Express, etc.) you use, and therefore GraphQL is language agnostic. The libraries available in Java, JavaScript, Python, Go enable GraphQL across platforms.

Why GraphQL?

  1. Type safety
  2. Backward and forward compatible : no versions
  3. Less throwaway data
  4. Instrumentation
  5. Save multiple round trips
  6. Free documentation

How do you benefit from GraphQL on the front end?

As a Front End Engineer, I like working with a GraphQL API for the following reasons:

  1. Instantly test queries and mutations using GraphiQL or playground
  2. Less data means lighter state management
  3. Offload heavy lifting to the server through resolvers
  4. Documentation that is up-to-date and interactive

How does it compare with REST?

GraphQL is better than REST because -

  1. One endpoint to fetch all resources.
  2. Avoid over fetching of data (getting too many fields when only a few fields are needed).
  3. Avoid under fetching of data (having to call multiple APIs because one API doesn’t give back all the information needed).

REST does certain things better -

  1. Caching
  2. Microservices based architecture
  3. HTTP codes — 200s, 400s, 500s for every request

How is it better than REST?

  1. One endpoint to fetch all resources.
  2. Avoid over fetching of data (getting too many fields when only a few fields are needed).
  3. Avoid under fetching of data (having to call multiple APIs because one API doesn’t give back all the information needed).

How to get started with GraphQL?

  1. Understand concepts: How to graphql https://www.howtographql.com/
  2. Read the official docs — https://graphql.org/learn/
  3. Play around with GraphiQL to try out GraphQL with GitHub’s API — https://developer.github.com/v4/explorer
  4. Watch a course in your stack — https://www.udemy.com/topic/graphql/
  5. Build a GraphQL server — https://egghead.io/courses/build-a-graphql-server
  6. Use GraphQL on the client — https://egghead.io/courses/graphql-data-in-react-with-apollo-client
  7. Read a book — https://www.amazon.com/Learning-GraphQL-Declarative-Fetching-Modern/dp/1492030716

Happy Coding!!

More articles
Useful Javascript Array trick which one should know
What is event loop in javascript?
Understanding React Hooks
what is closure in javascript, advantages and disadvantages?

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Deepak Mankotia
Deepak Mankotia

Written by Deepak Mankotia

Full Stack Web Developer | Open Source Enthusiast

No responses yet

Write a response