3m
🎯 Your goal for this step:
Add a datafetcher method for the Track.artist
field
Track data fetcher tasks
Solution: The track datafetcher
datafetchers/TrackDataFetcher
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.*;@DgsComponentpublic 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
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.