Fetching Content with GraphQL
In our admin experience we offer several different content types: Courses, Videos, Blogs, Scorms, Articles, and more. Although these objects are presented differently, on the backend many of them overlap. It’s important to understand how content data is structured so that you can fetch the appropriate data with our GraphQL API.
Courses
Courses are one of our most complex content types. At its root each course belongs to a courseGroup. Courses then have sections, sections have lessons, and lessons have topics. Examples of topics are quizzes, tests, or text pages.
The CatalogContent
Query
To get the IDs of the courses in your learning instance you can call the CatalogContent
query. You would typically use this query to build your Catalog Page.
CatalogContent(page: 1) {
contentItems {
title
displayCourse <-- pass this ID to CourseById
}
}
The CourseById
Query
You can then use the IDs returned from CatalogContent
to call CourseById
to fetch the various sections, lessons, and topics that a course has. This will give the outline of the course and you can also fetch more data about a specific course than you can with the CatalogContent
query.
CourseById(id: “sample-id”) {
Sections {
Lessons {
Topics {
...on ArticlePage {
title
id
type
}
...on QuizPage {
title
id
type
}
}
}
}
}
The Pages
Query
Now that you have the ids of the various topics in the course you can call the Pages
query to get more data about the specific topics themselves. For example, if you have a quiz topic with the Pages
query you can get the quiz questions, the answers, and how long it usually takes to complete the quiz.
Pages(identifiers: [String!]!) {
... on QuizPage {
title
questions {
body
choices {
value
correct
}
}
}
}
Videos, Blogs, Articles
Under the hood, Videos, Blogs, and Articles are also all stored as course objects but they have just one topic associated with them. Fetching the data for a Blog is very similar to fetching data for a normal course. You’d follow a similar pattern of calling CatalogContent
, then calling CourseById
, and then calling Pages
. Blogs, Videos, and Articles are all available under the ArticlePage type.
query Pages($identifiers: [String!]!) {
Pages(identifiers: $identifiers) {
... on ArticlePage {
videoAsset
languages {
language
label
title
subtitle
body
copyright
}
}
}
}
ILT’s
ILTs or Instructor Led Training is another content type and is also stored as courseGroup objects. Most of the information surrounding ILT’s is at the CourseById level and doesn’t require you to call the Pages query. With ILTs, you can have one ILT with multiple sessions. This structure corresponds to one parent courseGroup and then multiple child courses for each session. Here is an example of how you could fetch an ILT with multiple sessions:
query CourseById($id: ID!) {
CourseById(id: $id) {
title
slug
courseGroup {
description
asset
courses {
title
courseStartDate
courseEndDate
}
}
}
}
Learning Paths
The CatalogContent
Query
You can use the CatalogContent
query to fetch all the Learning Paths in your instance and basic informtaiton about them such as their title and description.
CatalogContent(page: 1) {
contentItems {
title
slug <-- pass this to LearningPathBySlug
}
}
The LearningPathBySlug
Query
The LearningPathBySlug
query allows you to fetch general and specific information about the Learning Path such as it's title, description, the titles of the milestones, and the content of each milestone
query LearningPathBySlug($slug: Slug!) {
LearningPathBySlug(slug: $slug) {
milestones {
name
id
contentItems {
id
title
kind
}
}
}
}
The Milestone
Query
The Milestone
query allows you to fetch information about a specific Milestone rather than every Milestone in the Learning Path.
query Milestone($id: ID!) {
Milestone(id: $id) {
name
id
contentItems {
id
title
kind
}
}
}
Still have a question?
Get your questions answered in our Developer Discord.