Odyssey

Lift-off III: Arguments

Feature OverviewUpdating our schemaGraphQL argumentsResolver args parameterResolver chainsQuery building in Apollo SandboxBuilding the track pageThe useQuery hook - with variablesNavigating to the track page
2. Updating our schema
3m
You're currently on an older version of this course. View course changelog.

👀 Reviewing our design

Let's start with the mockup of the Track page our design team provided us with. Here we'll need to display more information about a track than what's contained in a card on the homepage.

A mockup of the Track page showing a track thumbnail, title, and data about its modules

In addition to what we had in our card, a track needs to have:

  • a description
  • the number of views
  • the list of modules included in that track

For each module, we want:

  • the title
  • the length

✍️ Updating the schema

Let's open up the schema.js file in the server/src folder.

We'll start by updating the Track type. We'll add the description (which is a String) and the numberOfViews (an integer, Int). Oh, and let's not forget to give our fields nice comments!

Add the following fields inside our schema's Track type:

server/src/schema.js
"The track's complete description, can be in Markdown format"
description: String
"The number of times a track has been viewed"
numberOfViews: Int

Next, what should we do about our track's modules?

Putting our business glasses on, it looks reasonable to assume that a module should be a standalone type: a single track might include any number of modules, and one module might be part of multiple tracks. So, we'll create a separate Module type.

A module has an id, which is required. It also has a title, which is a required String and a length, which is an Int. We'll add comments for this type and its fields as well.

Add the following to our schema's typeDefs:

server/src/schema.js
"A Module is a single unit of teaching. Multiple Modules compose a Track"
type Module {
id: ID!
"The Module's title"
title: String!
"The Module's length in minutes"
length: Int
}
Which of these are reasons to create a separate Module type?

Now that we have our Module type, let's go back to our Track type.

We know that a Track can have multiple modules, so let's add a field to Track called modules, which returns an array of Module objects. This array can't be null so we add an exclamation point at the end, and the entries in the array can't be null either, so we add another exclamation point after Module.

Add the following field to our schema's Track type:

"The track's complete array of Modules"
modules: [Module!]!
Given this schema field: missions: [Mission!], which of the following statement is true:

Perfect, we have our types updated according to our client's needs. Are we done with the schema definition? Not quite! For the moment, we only have a tracksForHome query that returns all of the tracks at once.

In the next lesson, we'll update our schema to retrieve a specific track, using arguments.

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.

              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
              }
              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
              }
              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
              }
              field

              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
              }
              field

              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.

              arguments

              A key-value pair associated with a particular schema field that lets operations pass data to that field's resolver.

              Argument values can be hardcoded as literal values (shown below for clarity) or provided via GraphQL variables (recommended).

              query GetHuman {
              human(id: "200") {
              name
              height(unit: "meters")
              }
              }

              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