1. Course overview and setup
3m

👋 Welcome to Intro to GraphQL with Java & DGS!

Your journey begins now! Ready to embark?

In this series, we'll start from scratch and build a full-fledged using the Spotify API.

In this lesson, we will:

  • Learn about what we're building, and the technologies that help us build it
  • Set up our project environment

What is GraphQL?

Let's begin with the most important question of the course. What is GraphQL?

is the developer-friendly language for the modern web. It transforms how apps fetch data from an API, enabling you to get exactly what you need with a single query—instead of wrangling responses from a patchwork of REST endpoints.

With a strongly typed schema at its core, helps you define relationships between data across any number of systems, empowering you to focus on what your data can do instead of where it's stored.

Throughout this course, we're going to learn how fits into our existing architecture and how it works with existing REST APIs and other . We'll learn how to use queries, , , the schema, and in our GraphQL API. Get ready to roll up your sleeves, write some code, test your understanding, and build something cool!

A diagram showing GraphQL as the contact point between multiple clients and the complex architecture of a modern backend

What is DGS?

by itself is a specification, a language for APIs. To implement GraphQL in a server, we typically use a GraphQL framework.

DGS, or Domain Graph Service, is a framework created by the Netflix team that enables in a Spring Boot application with just a few dependencies. As we explore the fundamental topics of GraphQL, we'll learn to work with DGS annotations and methods, and see how we can wire up our Java classes with GraphQL capabilities.

https://netflix.github.io/dgs/

The DGS homepage, with the title GraphQL Made Easy for Spring Boot

Prerequisites

We'll start with a boilerplate Spring Boot project and gradually add our DGS dependencies.

To follow along...

What we're building

Listen up! Ready to tune into what we're building in this course? Drumroll please! 🥁

If you couldn't tell from all those music-related cues, we're building a music catalog API called MusicMatcher that helps us find the right soundtrack for the right moment.

Mockup of MusicMatcher

For this first iteration of MusicMatcher, we'll focus on playlists: showcasing featured playlists, listing a playlist's tracks, and adding tracks. In future courses, we'll add more features like pagination, authentication, intermediate schema design concepts, and federation.

Clone the repository

In the directory of your choice with your preferred terminal, clone the app's starter repository:

git clone https://github.com/apollographql-education/intro-dgs.git
Task!

Note: If you get stuck at any time during the course, feel free to check out the final branch for some help.

Project structure

Our project already contains the files we need to get started and run our Spring Boot server, but we'll work primarily out of the java and resources packages highlighted below.

📦 intro-dgs
┣ 📂 gradle
┣ 📂 src
┃ ┣ 📂 main
┃ ┃ ┣ 📂 java
┃ ┃ ┃ ┣ 📂 com.example.soundtracks
┃ ┃ ┃ ┃ ┣ 📄 SoundtracksApplication
┃ ┃ ┃ ┃ ┣ 📄 WebConfiguration
┃ ┃ ┣ 📂 resources
┃ ┣ 📂 test
┣ 📄 build.gradle.kts
┣ 📄 gradlew
┣ 📄 gradlew.bat
┣ 📄 settings.gradle.kts
┗ 📄 README.md

Now, open the repository in your favorite IDE. We're using IntelliJ IDEA Community Edition in our examples.

Let's build and run the app

In your IDE, open the main SoundtracksApplication file located in the com.example.soundtracks package. This is the starting point for our app.

@SpringBootApplication
public class SoundtracksApplication {
public static void main(String[] args) {
SpringApplication.run(SoundtracksApplication.class, args);
}
}

In IntelliJ, we have the handy 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

In the IDE Run output, we should see that our app is running!

> Task :SoundtracksApplication.main()
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.2.0)
Task!

Of course, it's not doing much yet. Let's jump in!

💾 Data!

Throughout the course, we'll build the API that serves (and updates) data for playlists and their tracks.

Mockup of MusicMatcher

This mockup shows a grid of featured playlists. For each playlist, we can start to see which pieces of data we need: a name and a description.

We need even more data to create a view for a specific playlist.

Here we can see the specific elements that make up each track contained in a playlist: its name, link, duration, and whether it's considered explicit.

A mockup of a specific Playlist page, showing a list of tracks

To represent these different pieces in , we can think about our data as a collection of objects (such as playlists and tracks) and relationships between objects (such as each playlist having at least one track).

Now, if we think of each object as a node and each relationship as an edge between two nodes, we can envision our entire data model as a collection of nodes and edges. This is called our application's graph.

A data graph visual, with a Playlist node and several edges pointing to its properties. One of the edges, tracks, points to a list of Track nodes.

Practice

Which of these accurately describes a graph in GraphQL?

Key takeaways

  • enables precise data retrieval with a single , eliminating the need to navigate multiple REST endpoints on the client app side.
  • Domain Service (DGS) is a Netflix-developed framework for Java developers.
  • enables us to build APIs by describing our data in terms of (nodes) and relationships (edges).

Up next

We've laid the groundwork for the tools we'll use, but we still need to talk about HOW they actually work together. In the next lesson, we'll jump into the basics and follow the journey of a .

Next

Share your questions and comments about this lesson

This course is currently in

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