2. Sandbox Explorer
10m

Overview

Let's get to know our API!

In this lesson, we will:

  • Learn about the
  • Explore the API using

The GraphQL schema

We'll communicate with the running on Heroku to serve up our data—but first, we should get to know its schema. The GraphQL schema is a collection of types and that make up the comprehensive picture of everything we can do with the data in a . No actual data lives here; just the basic skeleton of the shapes that the live data will conform to. (Think of a blueprint!)

The schema has its own language called schema definition language, or SDL.

Note: We won't need to write in this course; instead, we'll use the 's schema to generate the code that we'll use in the frontend. With codegen, we can reduce the amount of time we spend manually writing . Instead, an automatic process can retrieve the information we need from the schema and output the code we'll use. We'll explore codegen more in the coming lessons.

We could take a look at the raw schema file that our uses, but there's a better way to get hands-on: using !

Using Apollo Sandbox

Enter Apollo Sandbox. Sandbox is free to use and doesn't require an account. It's part of the platform, and helps with local graph development.

Apollo GraphOS is a complete cloud platform for building, managing, and scaling your . provides a set of tools and services so that product developers can focus on building better apps, faster.

With Sandbox, we can load a 's schema and explore it using some cool features such as a schema reference and the Explorer. The Explorer is a powerful web IDE for creating, running, and managing GraphQL . It lets us build operations easily and quickly, look at our operation history, peek at response hints, and share operations with others.

This link takes us directly to the Explorer, with an automatic connection to the API we'll be using.

https://studio.apollographql.com/sandbox/explorer

The landing page for the Explorer, connected to our API

Note: We can tell that this Sandbox instance is pointed at our server because its URL, https://apollo-fullstack-tutorial.herokuapp.com, is in the box at the top left of the page. If Sandbox is properly connected, you'll see a green dot, which means we're good to go!

Exploring the schema

Awesome, let's check out our schema, which is the first tab in our main navigation.

https://studio.apollographql.com/sandbox/schema

The Schema page in Sandbox

Here we have a full view and reference into our schema! This tells us all about what types and fields exist in the API. These represent the different data objects we can the API for. And building those queries starts with the Query type.

The query

The most common is the query, which requests data from your in a structure that conforms to the server's schema. In our schema, the Query type defines the various we can use to for different objects.

Scroll down to find the launches .

https://studio.apollographql.com/sandbox/schema

The fields in the Query type highlighted

Here we'll find the details about this . We can see the term itself, the return type, and information about parameters that can be passed to the query. You can use this information to write a query you'll eventually add to your app.

To start working with this in Explorer, select the "play" to the right of the 's details.

https://studio.apollographql.com/sandbox/schema

The play button highlighted on the launches field

This brings you back to the Explorer tab, with the Documentation panel on the left opened to the you've selected.

https://studio.apollographql.com/sandbox/explorer

The Explorer opened to show the launches field in the Documentation panel

The Operation panel in the middle is where we create queries. We can write the manually or add from the Documentation panel on the left.

Clicking on the plus (⊕) button next to a automatically adds that field to our current . This is a handy way to assemble complex queries without needing to remember your schema's exact structure or syntax.

Let's click the plus button to add the launches to the Operation panel.

https://studio.apollographql.com/sandbox/explorer

Adding the launches field to the Operation panel

This updates the in the Operation panel to look like the following:

query Launches {
launches {
}
}

Let's break down what you're seeing here:

  • The type of the , query, followed by the name of the , currently Launches (we'll make that more specific in a second), is the outermost set of brackets.
  • The next set of brackets contains the 's . In , the term selection set is the list of you want to fetch. Since the arguments for this both have default values, they are not automatically added to the query for you.
  • An error in the empty space between the brackets, which is where you'll put the list of information you want back from each .

The SDK requires every to have a name (even though this isn't required by the spec). Since you're going to be creating more than one query, it's also a good idea to give this a specific name other than Launches. Change the name of the to LaunchList:

Back in the Documentation panel, you can select the you want back in the returned object. Start by clicking the button next to the cursor . It will mark that field as selected, then insert it into your .

https://studio.apollographql.com/sandbox/explorer

The query updated with the cursor field added

You can also use auto-complete to add to your . Add a new line below cursor in the Operation panel and start typing ha. An auto-complete box pops up and shows you options based on which in the schema match.

https://studio.apollographql.com/sandbox/explorer

Autocomplete in the Explorer recommending the hasMore field

As the schema indicates, the launches returns a LaunchConnection object. This object includes a list of , along with related to pagination (cursor and hasMore). The you've written so far indicates exactly which of this LaunchConnection object you want to be returned.

Run this by pressing the Submit Operation button, which should now have the name of your , LaunchList. You'll quickly see the returns results as a JSON object on the right-hand side of the page.

https://studio.apollographql.com/sandbox/explorer

Running the LaunchList query

This executes successfully, but it doesn't include any information about the launches themselves! That's because we didn't include the necessary in the . Click the button next to the launches at the bottom of the left column. It will add a set of braces for launches to the Operation panel, and then update Documentation to show information for the Launch type.

https://studio.apollographql.com/sandbox/explorer

Updating the query with the launches subfield

The you add in this set of brackets will be fetched for every in the list. Click the buttons next to id and site to add those two . When you're done, your should look like this:

query LaunchList {
launches {
cursor
hasMore
launches {
id
site
}
}
}

Run the again. Now you'll see in addition to the information you got back before, you're also getting a list of with their ID and site information.

https://studio.apollographql.com/sandbox/explorer

The response for the query updated with id and site

For your convenience, we've created an embeddable version of for this course. Feel free to use this embedded version or a separate browser from here on out.

Up next

Now that we've seen how queries work, let's set up the schema in our project.

Previous

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.