1. Introducing Apollo Connectors
3m

Introduction

Are you tired of writing code and hosting yet another just to add a few to your graph from a REST API? Or maybe you already have an existing REST API that's working perfectly fine and want to get started on a new graph. We've got you covered!

In this course, we'll learn how to plug in an existing REST API into a using Apollo Connectors.

We'll use two schema to implement our connectors: @connect and @source. We'll get equipped with useful tools for our developer workflow, including using for local development and Explorer to debug connector network calls and examine . By the end of the course, we'll have working graph powered by a REST API, without writing a single line of code!

Ready? Let's get started! 🚀

In this lesson, we will:

  • Identify the key pieces of a architecture
  • Understand where Apollo Connectors fit in

Note: Apollo Connectors for REST APIs is currently in the public preview stage.

A federated GraphQL API: the supergraph

First, let's take a look at how a API currently works.

How a GraphQL API works

When a client needs some data, it sends a to the . The server uses its schema, , and to retrieve and resolve that data, then sends it back to the client. It's a pretty great experience!

This setup works well for smaller projects or teams, but what happens as our API grows? As more teams start adding types, , and features to our schema, our API becomes harder to manage, scale, and deploy. This is a common bottleneck problem with monolithic backend services.

To solve this problem, we can divide our API's capabilities across multiple -powered microservices, with each one taking responsibility for a different part of our API's schema. When we adopt this federated architecture, each of our microservices is called a subgraph, and together, they form the foundation of our supergraph.

Subgraphs

If we split our API's capabilities between lots of different microservices, how do clients across all of them? For that, we need the other piece of our : the router.

The knows about all of our , and it also knows which subgraph is responsible for each in our API's schema. Clients send queries to the router, and the router intelligently divides them up across the appropriate subgraphs.

Supergraph

The acts as the single access point for our API, kind of like an API gateway. This means that clients don't need to worry about communicating with our individual !

Zooming in on subgraphs

By splitting up our schema into , backend teams can work on their own independently, without impacting developers working on other . And since each subgraph is a separate server, teams have the flexibility to choose the language, infrastructure, and policies that work best for them.

These are great benefits and have proven very useful for enterprise companies and products.

But what if we could shorten the development process—and connect directly to the datasources that power these ?

Introducing Apollo Connectors

Apollo Connectors enable us to easily integrate REST APIs into the , without leaving the comfort of the schema!

When implementing a , the process typically begins with the schema: we define our types and . Then, we need to select a language and framework to develop in. Each of our schema's types and fields needs functions, which contain the logic to populate the data for that particular type or field by connecting to the necessary . These data sources are, more often than not, existing REST APIs. To complicate matters further, the REST API responses will often differ greatly from the shape of our schema; this leaves us writing even more code just to map data into the types and the expects.

With Apollo Connectors, we can skip the time-intensive steps of spinning up a and writing code. Instead, we can work directly in the schema to map our REST API data to our schema's types and . With this connectors-enabled schema, the creates a that will directly call our REST API endpoints, plucking out the properties we've defined. That's right, all we need is the schema!

Supergraph with connectors

Practice

Which of the following are benefits of using Apollo Connectors?

Key takeaways

  • In a federated architecture (also known as the ), a client sends a to the , which intelligently divides it up and executes it against smaller GraphQL-powered microservices called .
  • Apollo Connectors enable us to easily integrate REST APIs into the by working directly in the schema, skipping the process of spinning up a and writing code.

Up next

Let's set up the project we'll be working with for this course (a space travel booking API) so we can get hands-on with Apollo Connectors!

Next

Share your questions and comments about this lesson

This course is currently in

beta
. Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.

You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.