1. Project setup
5m

Ready to get in the driver's seat for your next mission?

lunar rover drive

In this project-focused activity, you'll be using everything you've learned so far from Intro to GraphQL with TypeScript & Apollo Server!

Before going any further, make sure you know:

  • How to write ()
  • How to access from methods

You'll also need to use these technologies:

  • NodeJS

If you're comfortable with those, great! You'll be able to continue working on our music catalog application.

You'll carry this feature from start to finish, building onto the schema, writing methods to connect to a REST API, and implementing .

This project picks up where Intro to GraphQL with TypeScript & Apollo Server finishes, but you can certainly jump right into it if you're up for it!

The app so far...

Right now, we can our music catalog app, MusicMatcher, for featured playlists and a particular playlist. Along with data about the playlist itself, we can also see more detail about the tracks that each playlist contains.

In this hands-on lab, you'll complete the steps to bring the next feature into our API. We're going to expand our music catalog application with artists.

If you haven't completed the course, clone the project starter repo using the command below:

git clone https://github.com/apollographql-education/odyssey-typescript-lab.git

Project structure

Our project is a fully-functional, backend server application.

Here's a look at the file structure. The entrypoint of our server is the src/index.ts file. Our project is preconfigured to generate TypeScript types from the , which are outputted in src/types.ts.

📦 odyssey-typescript-lab
┣ 📂 .github
┣ 📂 src
┃ ┣ 📂 datasources
┃ ┣ 📄 context.ts
┃ ┣ 📄 graphql.d.ts
┃ ┣ 📄 index.ts
┃ ┣ 📄 models.ts
┃ ┣ 📄 resolvers.ts
┃ ┣ 📄 schema.graphql
┃ ┗ 📄 types.ts
┣ 📄 .gitattributes
┣ 📄 .gitignore
┣ 📄 codegen.ts
┣ 📄 LICENSE
┣ 📄 package-lock.json
┣ 📄 package.json
┣ 📄 README.md
┗ 📄 tsconfig.json

Next, open a terminal in the root of your application and run the following command to install dependencies and the server.

npm install && npm run dev

When the installation is complete, we should see some output that our server is running on http://localhost:4000.

Task!

Setting up the Explorer

To test queries on our , let's open up at studio.apollographql.com/sandbox. When it loads, connect it to where the server is running at http://localhost:4000.

Task!

Let's try out a to get a list of featured playlists. Copy the query below, paste it into the Explorer's Operations panel, then run it. You should get a list of playlists, along with their tracks, in the Response panel on the right-hand side.

query GetFeaturedPlaylists {
featuredPlaylists {
id
name
description
tracks {
id
name
durationMs
}
}
}

You can also try building the yourself by typing it out manually, or using the plus (⊕) buttons on the left sidebar to add each .

Task!

The objective

Your mission is to expand this API with artist data. By the end of the lab, you'll be able to run queries that include a track's artist details. This will consist of the following steps:

  • Updating the schema to include a new artist type
  • Building out the method to retrieve artist data
  • Defining the to return artist data for a particular track.

Alright, time to get your hands dirty! The next few lessons provide hints and guides to what you'll need to do. If you get stuck, you can refer to the final branch of the repo, or you can reveal the code solution for each section. Click on the "Show code" button below to take a peek:

"I am the solution you are looking for"

Ready to get started? Off you go!

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.