DEV Community

Cover image for Getting started with GraphQL
Shruti Kapoor
Shruti Kapoor

Posted on

Getting started with GraphQL

What is GraphQL?

GraphQL is a way of asking for data from API - a query language for 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.

What is cool about GraphQL is that it provides an easy way of developing APIs over time. With GraphQL, you get one endpoint - /graphql and since every client talks to the same endpoint, it becomes very easy 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 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 to get started with GraphQL?

  1. Understand concepts: How to GraphQL
  2. Read the official docs
  3. How does GraphQL compare with REST
  4. Understand the common misconceptions about GraphQL
  5. Play around with GraphiQL to try out GraphQL with GitHub's API
  6. Watch a course in your stack
  7. Build a GraphQL server
  8. Use GraphQL on the client
  9. Read a book on GraphQL

Top comments (4)

ashraful profile image
Mohamad Ashraful Islam

Nice article

lorendsr profile image

For the learning resources, I recommend also checking out The GraphQL Guide

bhupendra1011 profile image

Great article to get started .one more learning resource :

shrutikapoor08 profile image
Shruti Kapoor

Thats the first link :)