Should I Use Apollo for GraphQL?

Rajat S
Bits and Pieces
Published in
7 min readFeb 19, 2019

--

There is something new happening almost every day in the world of technology. On one day the good people of React bring us a way to work with the state without having to write classes (React Hooks), and on some other day, someone releases a new library that lets you work with Ethereum through Vue (Vuethereum)!

Instead of running behind these updates and immediately implementing them into your project, it is better to stick with something that is reliable, stable, and easy to work with. At the same time, you need to make sure that your tech stack is more than capable of giving you what you need.

The same is true in the case of GraphQL! GraphQL is an open source data querying language that is used for building APIs for web and mobile applications. It is a great replacement for REST and other web service architectures. It allows the client side of the app to get the data in any structure.

To know more about the benefits of using GraphQL, check out this other post that I wrote a while back.

But GraphQL is just a query language. And in order to use it easily, we need to use a platform that will do all the heavy lifting for us. One such platform is provided by Apollo.

The Apollo platform is an implementation of GraphQL that can transfer data between the cloud (server) to the UI of your app. In fact, Apollo builds its environment in such a way that we can use it to handle GraphQL on the client as well as the server side of the application.

In this post, I will present some of the great reasons why Apollo is considered to be one of the popular choices for using GraphQL in JavaScript-based apps.

Tip: Use Bit to build JS apps faster with components. Organize, share and reuse components to build apps with your team. It also works great with Apollo and React components, give it a try.

React spinners with Bit: choose, play, install

More about the Platform

The Apollo platform is made up of a combination of components. It contains things like the Apollo Server, IDE Plugins, the Apollo CLI and other components that fall into one of these three categories:

  • Open Source Components
  • Client Services
  • Commercial Plugins
Source: Apollo Docs

Let’s take a closer look at the components inside these categories.

Open Source Components

Apollo platform contains a JavaScript GraphQL server that defines the schema and a set of resolvers that implement each part of that schema. The server is extensible in the sense that the commercial plugins can connect to any requests sent to the server.

The platform also has a client component that can manage the entire data of the application. The component can be used with React, Vue, Angular, and many other applications.

For mobile apps, the platform has an android and iOS client component that was developed by the GraphQL community.

Apart from all these, the platform also comes with a CLI (command line interface) component that helps the developer access Apollo’s cloud services.

Cloud Services by Apollo

Among its many useful cloud services, the platform consists of a service that registers the GraphQL schemas and acts as a “single source of truth” for the schema. The platform can also register each and every client of the schema, and all the known operations that can be performed on the schema.

The platform also has a pipeline and a storage layer that takes in information about the GraphQL operations processes by the Apollo Server.

Gateway

The Apollo platform’s gateway is a configuration of the server and plugins. It consists of “micro-schemas” that refer to each other into a single “master-schema”. When answering queries, the gateway builds a query plan, fetches the data from the GraphQL service, and puts it together into a single result.

Now that you have some understanding of the Apollo platform, let’s take a look at some of the reasons why using Apollo for GraphQL is a good thing.

Pros of Apollo

Given below are some of the advantages of using the Apollo Platform for GraphQL

1. Apollo’s environment is huge!

The Apollo platform has grown so big that it can solve almost any problem that you might face while working with GraphQL. Apollo regularly releases new updates or additional libraries that make working with this platform an amazing experience. The platform not only supports GraphQL but also provides backward compatibility to RESTful architecture.

2. Substantial company and community support

Apollo’s has invested and continues to invest a lot of resources into this platform. By open-sourcing the platform’s core components, the platform has gained a great following in the tech community, which keeps growing every day.

Some of the well-known companies that use Apollo are:

  • Airbnb
  • Twitch
  • The New York Times
  • KLM
  • Medium

3. Plenty of additional libraries

Apollo provides a whole lot of open-source libraries that are extremely helpful in implementing GraphQL for JavaScript applications. The Apollo Link library provides us with an API that can “link” different features into the GraphQL control flow.

4. Built-in Features

The platform consists of features that take out most of the data related complexity from the application and handle the communication between the client-side and the server-side. These features handle more than just caching, they also handle things like handling errors, pagination, optimistic user interface, prefetching data, and connecting the Apollo Client to UI libraries such as React and Vue.

5. Interoperability with other frameworks

Just like the react-redux library connects React to Redux, Apollo contains libraries such as react-apollo that contains higher order components (HOC) and render prop components that can connect React to Apollo. There are other similar libraries out there that makes Apollo great for JavaScript-based application.

This is just on the client side of the application, at the server side of things, Apollo offers many other libraries that can connect it with Node, Express, Koa, and Hapi.

6. Handling Data with Modern Data Handling

Back in the day, we had to trigger a fetch in the component’s lifecycle methods in order to load the data. With Apollo Client, the data queries become declarative.

Usually, GraphQL’s mutations are triggered imperatively, but that’s only because a HOC or render prop grants access to the function which executes the mutation (e.g. on a button click). With Apollo, the mutations and queries become declarative over imperative.

7. Apollo for State Management

As if things were not already confusing in the world of state management, people started to wonder if they should use libraries like Redux and MobX if they are also using Apollo at the server side.

As an answer to this, Apollo released the “Apollo Link State” library that lets you manage all the data (local and remote) with GraphQL. You can instead use the Apollo Client cache as your single source of truth that holds all of your local data alongside your remote data. To access or update your local state, you use GraphQL queries and mutations just like you would for data from a server.

Wrapping up

Even with all the good things that are happening with the Apollo platform, there are certain areas where things can be improved.

Even though GraphQL has been around since 2015 (stable release in 2016), it is still considered to be fairly new. With Apollo building an environment around GraphQL while it is still in development, Apollo users will have to be careful of any major changes to GraphQL.

Thanks for reading this long post! I hope this post helped you understand GraphQL and Apollo’s place in it a little better.

I will soon be publishing a post on How to Build React Apps with GraphQL. In the meantime, check out this post from me about why people like GraphQL

If you liked this post, then please do give me a few 👏 and please feel free to comment below. Cheers!

--

--