Odyssey

GraphOS: Basics
deprecated

Getting started with GraphOSProject setupWhat's in a supergraph?Creating a supergraph in GraphOSQueries and the ExplorerSharing your supergraphGraphOS metrics & client awarenessUsing @defer
5. Queries and the Explorer
2m

Overview

Now for the fun part: actually using our supergraph!

In this lesson, we will:

  • Run queries in Apollo Explorer
  • Create and use operation collections

Building and running queries

We can easily build, run, and manage GraphQL operations with the help of the Apollo Explorer. The Explorer IDE is part of the GraphOS platform and it's easily accessible through the sidebar navigation.

https://studio.apollographql.com

The Explorer on Apollo Studio

Note: You can also get to the same page immediately after creating your supergraph by clicking on Query your supergraph in the modal.

Let's run our first query.

Getting to know the Explorer

The Operation panel in the middle is where we create queries. The Explorer has already filled in a default operation! You can edit the operation directly or add fields from the Documentation sidebar.

At the top of the Operation panel is the button to run our query. Let's click it now and see what happens!

https://studio.apollographql.com

The response shows data after clicking on the Run button

The Response panel on the right displays our list of recipe IDs. Not super helpful right now, so let's spice up this query.

We'll ask for a random recipe and include all the details we need to prepare it.

query GetRandomRecipe {
randomRecipe {
id
name
cookingTime
prepTime
servings
instructions
readyTime
ingredients {
text
}
}
}

When we run this query, we'll get back data about a random recipe, in Poetic Plates style.

We might want to use this query again, so let's save it using operation collections.

Operation collections

There are two types of collections: personal and shared.

Personal collections are visible only to you. Shared collections are visible to all organization members who can view the supergraph the collection belongs to.

Creating a shared operation collection

Let's get our shared collection started, this is going to be helpful for future teammates (and future us!) to get the most out of the supergraph.

Click on the bookmark icon to access your collections.

https://studio.apollographql.com

Accessing the Operation Collections tab in the left panel

Under the Shared section, click the + Create collection button.

We'll give the collection a name and a description.

Name: Recipes
Description: A collection of queries to retrieve content about recipes
https://studio.apollographql.com

Creating a collection, filling in the name and description in the modal

Then click Add. We'll see the new collection show up under the Shared section.

Saving an operation to a collection

Next, let's add to our collection. Click the Save icon.

https://studio.apollographql.com

Click the Save icon in the Operation panel

We'll use the same operation name we already gave it. Then, select the collection it belongs to (the one we just created earlier!).

https://studio.apollographql.com

Filling in the operation details in the operation collection modal

We'll hit Save, and success!

We can see the operation name under this shared collection, and we can see a bookmark icon in the tab that also tells us that this operation is saved. It's ready to use whenever we need it!

Practice

Which of these are benefits of using the Explorer?
Which of these are benefits of using operation collections?

Key takeaways

  • Operation collections help you store and organize commonly used operations so you can access them more quickly and share them with team members.
  • You can save collections that are visible only for yourself (personal) or visible to the whole organization (shared).

Up next

This is great, we can already send queries to our supergraph! Now let's make sure other people can use it too. In the next lesson, we'll learn a couple ways to enable the best API experience for our users.

Previous
Next

Share your questions and comments about this lesson

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.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              GraphQL

              An open-source query language and specification for APIs that enables clients to request specific data, promoting efficiency and flexibility in data retrieval.

              operations

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              fields

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              operation name

              The name of a particular query, mutation, or subscription. You should provide a name for every operation to improve logging and debugging. For example:

              mutation AddTodo($type: String!) {
              addTodo(type: $type) {
              id
              type
              }
              }
              query GetHuman {
              human(id: "200") {
              name
              height(unit: "meters")
              }
              }

              The operations above are named AddTodo and GetHuman.

              operation name

              The name of a particular query, mutation, or subscription. You should provide a name for every operation to improve logging and debugging. For example:

              mutation AddTodo($type: String!) {
              addTodo(type: $type) {
              id
              type
              }
              }
              query GetHuman {
              human(id: "200") {
              name
              height(unit: "meters")
              }
              }

              The operations above are named AddTodo and GetHuman.

              Operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              NEW COURSE ALERT

              Introducing Apollo Connectors

              Connectors are the new and easy way to get started with GraphQL, using existing REST APIs.

              Say goodbye to GraphQL servers and resolvers—now, everything happens in the schema!

              Take the course