5. Adding the resolver
3m

🎯 Your goal for this step:

Add a function for the Track.artist

Track.artist resolver tasks

Solution: The Track.artist resolver

resolvers.ts
// ... other resolvers
Track: {
durationMs: (parent) => {
return parent.duration_ms;
},
artist: async ({ artists }, _, { dataSources }) => {
const artist = artists?.[0];
if (!artist) {
return null;
}
const { id, name, genres, followers, uri } = await dataSources.spotifyAPI.getArtist(artist.id);
return {
id,
name,
uri,
genres,
followers: followers?.total
}
}
}
Previous

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.