2. Updating our schema
3m

👀 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 nice comments!

Add the following 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 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 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 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 that returns all of the tracks at once.

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

Previous

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.