1. Project setup

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 Java & DGS!

Before going any further, make sure you know:

  • How to write ()
  • How to create datafetcher classes
  • How to access from datafetcher class methods

You'll also need to use these technologies:

  • Java basics
  • Domain Service (DGS) framework

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 datafetchers.

This project picks up where Intro to GraphQL with Java & DGS 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-dgs-lab.git

Project structure

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

Here's a look at the file structure. Our server's main function is located in the SoundtracksApplication.java file, and we have three folders that contain the logic that utilizes the DGS framework: datasources, datafetchers, and models.

📦 odyssey-dgs-lab
┣ 📂 gradle/wrapper
┣ 📂 src
┃ ┣ 📂 main
┃ ┃ ┣ 📂 java/com/example/soundtracks
┃ ┃ ┃ ┣ 📂 datafetchers
┃ ┃ ┃ ┣ 📂 datasources
┃ ┃ ┃ ┣ 📂 models
┃ ┃ ┃ ┣ 📄 SoundtracksApplication.java
┃ ┃ ┃ ┗ 📄 Webconfiguration.java
┃ ┃ ┗ 📂 resources
┃ ┗ 📂 test/java/com/example/soundtracks
┣ 📄 .gitignore
┣ 📄 README.md
┣ 📄 build.gradle.kts
┣ 📄 gradlew
┣ 📄 gradlew.batch
┗ 📄 settings.gradle.kts

Open up the project in the IDE of your choice.

Next, navigate to the main SoundtracksApplication file located in the com.example.soundtracks package. If you're using IntelliJ, click the green play button in the margin next to the main function, or the one located at the top of the interface.

Alternatively, you can open a new terminal to the root of your project and run the following command:

./gradlew bootRun

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:8080/graphql.


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 {
tracks {

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


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 datafetcher method 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!


Share your questions and comments about this lesson

This course is currently in

. 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.