Skip to content

Commit

Permalink
feat: add Resolving a mutation successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
mdssjc committed Mar 17, 2023
1 parent b26bb4e commit 2ca51a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions graphql/odyssey-lift-off/server/src/datasources/track-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class TrackAPI extends RESTDataSource {
getModule(moduleId) {
return this.get(`module/${moduleId}`);
}

incrementTrackViews(trackId) {
return this.patch(`track/${trackId}/numberOfViews`);
}
}

module.exports = TrackAPI;
13 changes: 13 additions & 0 deletions graphql/odyssey-lift-off/server/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ const resolvers = {
return dataSources.trackAPI.getModule(id);
},
},

Mutation: {
incrementTrackViews: async (_, { id }, { dataSources }) => {
const track = await dataSources.trackAPI.incrementTrackViews(id);
return {
code: 200,
success: true,
message: `Successfully incremented number of views for track ${id}`,
track,
};
},
},

Track: {
author: ({ authorId }, _, { dataSources }) => {
return dataSources.trackAPI.getAuthor(authorId);
Expand Down

0 comments on commit 2ca51a9

Please sign in to comment.