5. The track datafetcher

🎯 Your goal for this step:

Add a datafetcher method for the Track.artist

Track data fetcher tasks

Solution: The track datafetcher

package com.example.soundtracks.datafetchers;
import com.example.soundtracks.datasources.SpotifyClient;
import com.example.soundtracks.models.MappedTrack;
import com.example.soundtracks.models.MappedArtist;
import com.netflix.graphql.dgs.*;
public class TrackDataFetcher {
private final SpotifyClient spotifyClient;
public TrackDataFetcher(SpotifyClient spotifyClient) {
this.spotifyClient = spotifyClient;
@DgsData(parentType="Track", field="artist")
public MappedArtist getArtist(DgsDataFetchingEnvironment dfe) {
MappedTrack track = dfe.getSource();
String artistId = track.getArtistId();
return spotifyClient.artistRequest(artistId);

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.