Get Result from apollo client error undefined

Get Result from apollo client error undefined


0

I’m trying to use the result I’m getting from my apollo client. but it keeps giving me error of undefined although the request send was success in network. It means I cannot get access to the result like normal!
the code in my store is:

async questionSearch({ commit }, data) {
const ALL_QUESTION_SEARCH = gql`
  query searchQuestion(
    $token: String
    $bookId: String!
    $page: Int
    $keyword: String
    $field: String
    $source: String
    $fromYear: Int
    $toYear: Int
    $topic: String
    $minDifficultyLevelId: Int
    $maxDifficultyLevelId: Int
    $starred: Boolean
  ) {
    searchQuestion(
      args: {
        token: $token
        bookId: $bookId
        page: $page
        keyword: $keyword
        field: $field
        source: $source
        fromYear: $fromYear
        toYear: $toYear
        topic: $topic
        minDifficultyLevelId: $minDifficultyLevelId
        maxDifficultyLevelId: $maxDifficultyLevelId
        starred: $starred
      }
    ) {
      question {
        information {
          bookId
          topic
          isRoot
          childCount
          parentId
        }
        stats {
          like
          difficultyLevelId
        }
        source {
          name
          publishYear
          field
        }
        content {
          question
          type
          answers {
            id
            text
            isTrue
          }
        }
        key {
          description
        }
        rowNumber
        sortingInformation {
          season
          section
          subSection
          index
        }
        starred
        id
        isAnswered
        answers {
          bookId
          questionId
          answerId
          isTrue
          timestamp
          userId
        }
      }
    }
  }
`
const { result, error } = useQuery(ALL_QUESTION_SEARCH, {
  bookId: data.bookId,
  page: data.page,
  keyword: data.keyword,
  field: data.field,
  source: data.source,
  fromYear: data.fromYear,
  toYear: data.toYear,
  topic: data.topic,
  minDifficultyLevelId: data.minDifficultyLevelId,
  maxDifficultyLevelId: data.maxDifficultyLevelId,
  starred: data.starred,
  token: localStorage.getItem('token'),
})
// const response = useResult(result)
commit('questions', result)
commit('setSuccess', error)

},

and I’m calling my function like this:

async searchQuestions() {
  let form = {
    bookId: this.id,
    page: this.page || '',
    keyword: this.keyword || '',
    field: this.field || '',
    source: this.source || '',
    fromYear: this.fromYear || 1364,
    toYear: this.toYear || 1402,
    topic: this.book_topic || '',
    minDifficultyLevelId: this.minDifficultyLevelId || 0,
    maxDifficultyLevelId: this.maxDifficultyLevelId || 40,
    difficultyLevel: this.difficultyLevel || 40,
    starred: this.starred || false,
  }
  await this.questionSearch(form).then(() => {
    console.log(this.getQuestions)
    this.questionList = this.getQuestions.question
    console.log(this.questionList)
  })
},

But even in console.log it returns undefined.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'question')

How should I be able to access my data and display it in my template then? the actual console of my result in store is like:
enter image description here


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *