Found this content helpful? Log in or sign up to leave a like!

Using GraphQL to View All Module Items

jpinto
Community Member

After  @wdransfield ‌'s excellent Canvas Developer Session at INSTCON19 I was inspired to try out GraphQL and see whether we can simplify / speed up our API-based integrations. 

We're creating a tool to allow us to quickly assess whether our courses are ready to be published. I'd like to make sure that every module contains a page that starts with "Overview".

I can quite easily pull a list of all modules and the moduleitem IDs for each. It works very well - far easier than combining many API calls.

query MyQuery {  course(id: 738) {    name    modulesConnection {      nodes {        moduleItems {          _id        }        name      }    }  }}‍‍‍‍‍‍‍‍‍‍‍‍‍

If I try to go any further - for example - pull the titles of each Page - the script fails. Attempts to use the "content" attribute fail reliably.

query MyQuery {  course(id: 738) {    name    modulesConnection {      nodes {        moduleItems {          _id          content {            ... on Page {              title              _id            }          }        }        name      }    }  }}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Message: 

Error: Request failed with status code 500
at LYNF.e.exports (https://du11hjcvx0uqb.cloudfront.net/br/dist/webpack-production/main-e-154b446262.js:1693:37)
at Rn+g.e.exports (https://du11hjcvx0uqb.cloudfront.net/br/dist/webpack-production/main-e-154b446262.js:1984:29)
at XMLHttpRequest.h.<computed> (https://du11hjcvx0uqb.cloudfront.net/br/dist/webpack-production/main-e-154b446262.js:7382:1)

Is the content attribute not yet production-ready?

Thanks!