Let's prepare our development environment so we can dive into hands-on practice with batching in Connectors.
In this lesson, we will:
Verify our Apollo GraphOS account
Set up our code environment
Install and authenticate Rover
Start a local project
What we're building
Meet our course project: Airlock.
Airlock is an intergalactic travel booking app, where we can find a cool place to stay in the wide open universe!
https://odyssey-airlock.netlify.app/
For this course, we'll focus on one slice of Airlock: its featured listings.
We've already set up a minimal schema connected to a simple REST API using Apollo Connectors. With a couple of endpoints, we can explore these featured listings and their details, like the number of beds, cost, and location.
"A curated array of listings to feature on the homepage"
featuredListings:[Listing!]!
@connect(
source:"listings"
http:{GET:"/featured-listings"}
selection:"""
id
title
numOfBeds
costPerNight
"""
)
}
"A particular intergalactic location available for booking"
typeListing
@connect(
source:"listings"
http:{GET:"/listings/{$this.id}"}
selection:"""
id
title
numOfBeds
costPerNight
description
photoThumbnail
latitude
longitude
"""
)
@key(fields:"id"){
id:ID!
"The listing's title"
title:String!
"The number of beds available"
numOfBeds:Int
"The cost per night"
costPerNight:Float
"The listing's description"
description:String
"The thumbnail image for the listing"
photoThumbnail:String
"Latitude coordinates for the destination"
latitude:Float
"Longitude coordinates for the destination"
longitude:Float
}
Then, continue to the next lesson.
Option 2: Create a new project
If you don't have an existing project or want to start fresh, follow the steps below.
Project setup
1) Verify your Apollo GraphOS account
To use Connectors, you'll need an Apollo GraphOS account.
Don't have an account yet? Create one now and get started with the Free plan! Jump to the next step.
If you already have an existing account within an organization with an Enterprise plan, you must have the role of Graph Admin to be able to create graphs.
2) Install and authenticate Rover
You'll need at least Rover0.33.0 installed.
The Rover CLI is the primary command-line interface for managing and maintaining graphs with Apollo. We'll use it to set up and run a local project.
Find the command that fits your environment to install the latest version of Rover.
If you've already installed Rover before, you'll get a message asking if you'd like to overwrite the existing installation. Type y and hit enter to continue.
Verify that the installation completed successfully:
rover --version
To complete this course, your Rover version should be at least on 0.33.0.
Next, let's make sure we're authenticated to Rover. Run the rover config auth command in your terminal.
rover config auth
Rover will ask you for a personal API key to finish authenticating. Let's head over to GraphOS Studio in the browser to retrieve that key.
If you have a brand new organization, you'll see instructions for installing and authenticating Rover. On the second step, click Generate API key. We'll give this key any name (for example, dev), click Create, then copy the key.
studio.apollographql.com
For users with existing graphs: Click on your avatar on the top right and select Personal Settings. Under the API Keys tab, hit Create new key, give this key any name (for example, dev), click Create, then copy the key.
studio.apollographql.com
Back in the terminal, paste the key and press Enter to authenticate Rover.
3) Start a local project
We're ready to start a local project using rover init. The init command launches a wizard to create a project template.
In a terminal, create an empty directory for the project.
Run the command:
rover init
Walking through the wizard prompts, select the answers below to create a project with Connectors.
Prompt
Selection
Select option
Create a new graph
Select organization
Select the GraphOS organization to create the graph in
Select use case
Start a graph with one or more REST APIs
Name your graph
Enter a name for the graph, e.g., Odyssey Airlock
Confirm or modify your graph ID
Confirm or modify the generated graph ID.
Lastly, hit Y to let Rover create the project. After a few moments, we'll see an outline of the created files, graph credentials, and the command to spin up the project.
Copy the command in the terminal that matches your local environment and run it. Note that you'll have your own graph credentials substituted in:
We'll see output confirming the router has started on port 4000.
Optional: Run a query
Head to http://localhost:4000 in the browser to use Apollo Sandbox, a local playground for exploring our GraphQL API.
In the Explorer, paste this GraphQLquery in the Operation section:
queryGetProducts{
products{
id
name
description
}
}
Click ► GetProducts to run the request. You'll get a response with data for the product's id, name, and description; exactly the properties we asked for! 🎉
The rover init wizard sets up a working GraphQL service with an example schema and all the files we need to get started.
If you lost the APOLLO_KEY, generate a new API key for the graph. Go to GraphOS Studio, click into the graph, and select the gear icon for Settings.
Next, click into the This graph tab. You'll see a menu item called API Keys. To generate a new key, click the Create new key button. Copy the value, and you're all set!
Error: License not found.
You need an Apollo account with a Free or Enterprise plan to use Connectors. Verify your organization's plan by navigating to GraphOS Studio, clicking on Settings, then selecting the Billing tab.
You may also be using the incorrect value for the APOLLO_KEYvariable. Follow the instructions above for "Need a new APOLLO_KEY?" to generate a new one.
Still having trouble? Visit the Odyssey forums to get help.
4) Set up your code environment
When working on a GraphQL project, it's helpful to have features such as autocompletion, schema information, and syntax highlighting.
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.