Getting Started with GraphQL: It’s pretty easy!

Bennett Garner
Level Up Coding
Published in
8 min readMay 24, 2019

--

Many companies have switched over to GraphQL to build their APIs. There’s good reason — it’s a revolutionary way of thinking about how we fetch data.

GraphQL’s origins & why use it

GraphQL comes from Facebook. Internally, Facebook was looking for a way to make their newsfeed load more reliably on mobile.

Using a traditional REST API structure, the newsfeed was making many calls to multiple API endpoints in order to get all the data it needed. Along the way, the API calls were also overfetching extra data that the newsfeed didn’t need. Additionally, upon receipt, the frontend engineers still had to parse through the data to find the fields they wanted.

Facebook engineers wondered, “What if we could write a query language so that we can specify all the information we need in a single API request?”

GraphQL is the result of that effort. It maps the relationships between objects in your database — creating a graph. Then they designed a query language for traversing that map of relationships. Hence, the name GraphQL.

With the addition of a query language, GraphQL APIs can now accept all incoming requests at a single endpoint. They then fetch and return the data you requested, and only the data you requested. No more overfetching information that you won’t use.

A specification, not an implementation

Critically, Facebook decided to open source GraphQL as a specification.

That means that it can be implemented in any programming language. As long as the implementation parses queries, schema, etc in the specified way, it will play nice with any other GraphQL application.

Indeed, there are now dozens of implementations of GraphQL in every major programming language.

In this article, we’ll use the reference implementation of GraphQL that’s written in JavaScript, but the same basic principles apply in any language.

You can check out the full list of GraphQL implementations to find your favorite language.

Basic architecture

--

--

DeveloperPurpose.com — Build a coding career with meaning and purpose 💻 Top writer in technology ✍️