Odyssey

Growing your GraphQL API with Java & DGS
deprecated

Project setupAdding the Artist typeThe Artist data sourceUpdating modelsThe track datafetcherWrapping up
4. Updating models
3m

🎯 Your goal for this step:

Update the MappedTrack model with a property that identifies its primary artist

Updating model tasks

Solution: Updating models

models/MappedTrack
public class MappedTrack extends Track {
// ...other MappedTrack methods
private String artistId;
@JsonSetter("track")
public void setTrackProperties(JsonNode trackObject) {
// other setter method calls
this.setArtistId(trackObject.get("artists").get(0).get("id").asText());
}
public void setArtistId(String artistId) {
this.artistId = artistId;
}
public String getArtistId() {
return this.artistId;
}
}
Previous
Next

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.

              NEW COURSE ALERT

              Introducing Apollo Connectors

              Connectors are the new and easy way to get started with GraphQL, using existing REST APIs.

              Say goodbye to GraphQL servers and resolvers—now, everything happens in the schema!

              Take the course