Overview
In this lesson, we'll get our development environment set up and Airlock up and running as a monolith graph. By the end of this lesson, we will:
- Learn how the backend GraphQL server is organized
- Learn what services and data sources the server uses
- Have both the server and client running on our local machine
- Set up the Rover CLI
- Set up the graph on GraphOS
Prerequisites
Our app uses Node.js on the backend and React on the frontend. We recommend using the latest LTS version of Node. To check your Node version, run node -v.
You'll also need to be comfortable with running commands in the terminal, such as navigating between directories and running scripts.
We'll use the Rover CLI to publish our schemas, so you'll need Rover installed and logged in to your GraphOS account with rover auth login. If you took Voyage I, you've already done this. Run rover auth whoami to confirm that you see your account information. If you haven't set up Rover yet, we'll walk through it in the Setting up the Rover CLI section below.
Additionally, we'll be working with files with the same name (schema.graphql, or index.js) but are located in different directories. Keep an eye on which file in which subgraph directory you're working on as we go through the course.
Airlock is split up into two different repos, one for the GraphQL server backend and another for the frontend web client.
Running the backend
Let's start with the backend server repo!
Clone the repo.
git clone https://github.com/apollographql/odyssey-voyage-II-server
There's a lot going on in this server, so let's take a deeper look at the folders and services we're working with.
The structure of the server looks like this:
📦 odyssey-voyage-II-server┣ 📂 monolith┣ 📂 router┣ 📂 services┣ 📂 subgraph-template┣ 📄 .gitignore┗ 📄 README.md
We'll go over each directory and its purpose in the following sections!
Navigate to the
monolithdirectory, and install the required packages.monolithnpm installThis also triggers an install for the
servicespackages.
Services
There are five different services required to run Airlock: accounts, listings, bookings, reviews and payments. These services are a mix of REST and direct database services. For the purposes of this course, most of these services will be run locally on your own computer (with the exception of the payments service). This means you'll be able to play around with Airlock features and data in a semi-isolated environment!
Note: For simplicity's sake, all locally-run services are located in the same repo. In a real-world scenario, each of these is more likely to be located in a different repo and owned and maintained by a different team.
| Service | Description | Type of data source | Hosting |
|---|---|---|---|
| Accounts | Manages users, their roles, and their profiles. | REST API | Run locally on port 4011 |
| Listings | Manages listing details, listing ownership, and amenities. | REST API | Run locally on port 4010 |
| Bookings | Manages bookings for listings. | SQLite database | Accessed locally |
| Reviews | Manages reviews about hosts, guests, and listings. | SQLite database | Accessed locally |
| Payments | Manages user wallet amounts and payments. | REST API | Hosted for you |
Running the services
To run our services, we can use a launch script that's available in monolith/utils/launch.js. This script takes care of starting up all the services hosted locally.
In a new terminal in the monolith directory, run:
npm run launch
We'll see a bunch of output come up in the terminal. Each message is prefixed with a color-coded label identifying which service or server the message belongs to. The accounts, listings, bookings, and reviews services should now be running!
We won't be modifying anything in the services directory!
Data sources
Our GraphQL server uses data sources to connect and communicate with each service. Here's a quick summary of each data source:
AccountsAPI: aRESTDataSourcethat connects to theaccountsservicePaymentsAPI: aRESTDataSourcethat connects to thepaymentsserviceListingsAPI: aRESTDataSourcethat connects to thelistingsserviceBookingsDb: a customDataSourceclass that connects to thebookingsservice using SequelizeReviewsDb: a customDataSourceclass that connects to thereviewsservice using Sequelize
We'll be making use of each data source's methods in our resolvers, but we won't need to create any new methods!
Running the GraphQL server
We're using Apollo Server, which is initialized in monolith/index.js.
Our server uses two pieces that are important to our graph:
- the schema (located in
schema.graphql) - the resolvers (located in
resolvers.js)
In a new terminal window in the monolith directory, run:
npm start
Our monolith server should now be running on http://localhost:4000! We're using nodemon for these start scripts so any changes we save to our code will also automatically restart the server.
If you need to manually stop the process for whatever reason, you can press CTRL+C to do so.
Testing a query with Sandbox
Let's test out our Airlock graph! When we open up http://localhost:4000 in the browser, we can query the graph using Apollo Sandbox.
In Sandbox, we'll build a query to retrieve all the amenities that a listing can provide. From the sidebar on the left, we can choose the listingAmenities field. Then for each amenity, we want to retrieve its category and name. Finally, let's rename the query to GetAllAmenities so it describes what it does.
Your query should look like this:
query GetAllAmenities {listingAmenities {categoryname}}
When we run the query, we'll see the results populate on the right-hand section. We can see there are a number of different amenities available for categories like "Accommodation Details", "Space Survival", and "Outdoors".
Feel free to play around with other queries, but note that not all of them may work! Some fields are protected and can only be accessed with the correct authorization permissions. We'll take a look at how to set those later on in the course.
Setting up the Rover CLI
Rover is Apollo's official command line interface, and plays a central role in every supergraph. We'll use Rover commands to publish our subgraph schemas.
If you haven't installed Rover from the previous course, refer to the instructions below!
Rover is Apollo's command line interface (CLI) tool that helps developers work with graphs and interact with GraphOS.
Rover also needs to be logged in to your GraphOS account so it can publish schemas on your behalf. If you haven't done this yet (or you're not sure), follow these steps:
In a terminal, run:
rover auth loginRover opens your browser so you can log in to GraphOS and authorize Rover. If the browser doesn't open automatically, copy the URL that Rover prints in the terminal and open it yourself.
After you authorize Rover, the terminal prints
Successfully logged in.To check if it worked, run:
rover auth whoamiAnd you should see your account information displayed. You're all set!
Creating the graph in GraphOS
While Sandbox is great for quickly running queries against our local graph, we're going to want the full GraphOS experience to explore our supergraph. Let's get a graph set up in GraphOS.
We're going to start with a supergraph architecture right away. Airlock is a monolith today, but we're about to break it apart, so we want a graph that's ready for federation from the beginning.
We can create a new graph by clicking the Add graph button in the upper right corner of the Graphs page.
We'll publish our schemas to the graph we create here, so give it a helpful name. Leave the Graph architecture set to Supergraph, then click Add graph.
Studio takes us to our new graph's Overview page. It shows the graph's APOLLO_KEY (hidden by default; click the eye icon to reveal it) and the graph ref, which is the <graph-id>@current value. We'll use both when we publish our subgraph and set up the router:
Let's create a .env file in the monolith directory to store both values so we can easily refer back to them.
📂 monolith┣ 📂 datasources┣ 📂 node_modules┣ 📂 utils┣ 📄 .env┣ 📄 index.js┣ 📄 package.json┣ 📄 resolvers.js┗ 📄 schema.graphql
Add your APOLLO_GRAPH_REF (the graph ID followed by @current) to monolith/.env. Then reveal and copy your APOLLO_KEY and paste it in as well. We won't use the key until we set up the router, but it's handy to have it saved.
APOLLO_GRAPH_REF=your-graph-name@currentAPOLLO_KEY=your-graphs-apollo-key
Warning: For security, environment variables should never be committed to version control. For this reason, this project includes a .gitignore file which specifies that the .env file should be ignored when committing code changes to a repository.
Our graph doesn't have any schema yet. We'll publish our first subgraph in the next lesson, once we've turned the monolith into one.
Running the frontend
Time to get the web app up and running!
In a new terminal window, outside of the server repo we set up previously, clone the frontend client repo.
git clone https://github.com/apollographql/odyssey-voyage-II-clientNavigate to the root of the project directory, and install the packages.
npm installRun the app.
npm start
This should open up http://localhost:3000 in the browser. You'll see something that looks like this:

You can use Airlock as either a guest or a host by clicking Log In on the top right and selecting the appropriate option. We also have additional account login options for you to choose from, but generally we'll stick with the main Guest or Host buttons.
To switch to a different account after logging in, click the profile picture on the top right of the page and "Log out".

Up next
And we're all set! Note that we'll be working primarily in the server repo for the course. Now with our development environment running, we can start federating our monolith graph!
Share your questions and comments about this lesson
This course is currently in
You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.