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 s and updating the .

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 query 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

  • Cat-stronomy, an introduction

  • 4

  • 8

  • Ox

  • The Night Sky

  • Kitty space suit, all you need to know

  • 10

  • Xo

  • Exploring Time and Space

  • Ab

Previous
Next