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 resolvers 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 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"
}
Loading...
Previous
Next