Skip to main content

Working with the Quiz Object

Quizzes have more moving pieces than a typical content page — you fetch data, then accept submissions back from the learner.

1. Fetching the Quiz Questions

Use the Pages query to load the question and choice data so you can render the quiz UI.

query Pages($identifiers: [String!]!) {
  Pages(identifiers: $identifiers) {
    ... on QuizPage {
      title
      questions {
        body
        choices {
          value
          correct
        }
      }
    }
  }
}

2. Creating an Assessment Attempt

Use LoadAssessmentAttemptWithQuestions to create a new attempt for the learner. Given Helium's headless nature, you decide when — many apps create the attempt as soon as the learner lands on the quiz page.

query {
  LoadAssessmentAttemptWithQuestions(
    id: $id
    courseId: $courseId
    topicType: $topicType
  ) {
    id
    status
    grade
  }
}

3. Updating the Assessment Attempt

Each time the learner answers a question, call UpdateAssessmentAttempt with the active question.

mutation UpdateAssessmentAttempt(
  $activeQuestion: QuestionInput,
  $assessmentAttempt: AssessmentAttemptInput
) {
  UpdateAssessmentAttempt(
    activeQuestion: $activeQuestion,
    assessmentAttempt: $assessmentAttempt
  ) {
      id
      grade
  }
}

// SAMPLE VARIABLES
{
  "assessmentAttempt": {
    "id": "{{ id from LoadAssessmentAttemptWithQuestions }}",
    "status": "started"
  },
  "activeQuestion": {
    "body": "<p>Who is the current quarterback for the Eagles?</p>",
    "mustSelectAllCorrectChoices": true,
    "selectedChoice": {
      "value": "Jalen Hurts",
      "correct": true
    }
  }
}

4. Submitting the Assessment Attempt

When the learner clicks submit, call UpdateAssessmentAttempt one more time with status finished.

mutation UpdateAssessmentAttempt(
  $assessmentAttempt: AssessmentAttemptInput
) {
  UpdateAssessmentAttempt(
    assessmentAttempt: $assessmentAttempt
  ) {
      id
      grade
  }
}

// SAMPLE VARIABLES
{
  "assessmentAttempt": {
    "id": "{{ id from LoadAssessmentAttemptWithQuestions }}",
    "status": "finished"
  }
}