14. Exercise: Write resolvers for the track and module pages
1m

Instructions

Use what you've learned to write the rest of the resolvers needed to make the queries on the track and module pages work.

Track details page

query GetTrackDetails($trackId: ID!) {
track(id: $trackId) {
id
title
author {
id
name
photo
}
thumbnail
length
modulesCount
numberOfViews
modules {
id
title
length
}
description
}
}

Variables:

{"trackId": "c_0"}

Module details page

query GetModuleAndParentTrack($moduleId: ID!, $trackId: ID!) {
module(id: $moduleId) {
id
title
content
videoUrl
}
track(id: $trackId) {
id
title
modules {
id
title
length
}
}
}

Variables:

{"moduleId": "l_0", "trackId": "c_0"}
  • Resource: Catstronauts REST API

Remember: The general process for writing a resolver:

  1. Add a resolver function skeleton to our resolver map.
  2. Find the data source method that returns the data we need.
  3. Use the data source method in our resolver function.

Hints

  • Test out each query one field at a time. Then once all fields return data correctly, try the full query.
  • You may not need to write resolvers for every field. Use Sandbox to check which default resolvers already return the right data for you!

Solution

Here's what your resolver map should look like when you're finished:

Task!

Well done, you've now finished all the read operations for the Catstronauts API!

Previous
Next