4. Resolvers & data sources
5m

🎯  Your goal is to build a single query for the Module page and confirm that it's returning live data using the Explorer.

To achieve this goal, you'll be implementing new and updating the data source.

The REST API for our data is located here: https://odyssey-lift-off-rest-api.herokuapp.com/

Data source Tasks

Data Source Solution

In datasources/track-api.js, add the following method inside the TrackAPI class:

getModule(moduleId) {
return this.get(`module/${moduleId}`);
}
Resolver Tasks

Resolver Solution

In resolvers.js, inside the Query object:

// get a single module by ID, for the module detail page
module: (_, { id }, { dataSources }) => {
return dataSources.trackAPI.getModule(id);
};
Design mockup of the Module page
Testing on Studio

Query Solution

This should be working on Studio:

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

Test these values in the Variables panel:

{
"trackId": "c_0",
"moduleId": "l_0"
}
Check your work!
After running the query in Studio, I can see that the title of module with id l_0 is 
 
, and its videoUrl's last 2 characters are 
 
. The module's parent track id c_0 has the title 
 
 and it has 
 
 modules.

Drag items from this box to the blanks above

  • Exploring Time and Space

  • Ab

  • Kitty space suit, all you need to know

  • 4

  • The Night Sky

  • Ox

  • 8

  • 10

  • Xo

  • Cat-stronomy, an introduction

Previous