Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. The query below is the one I use to retrieve all topics with the top level names (e.g: Economics), for the Flashcards main page (Known/Unknown/Starred modals):
  2.  
  3. ```graphql
  4. query FLASHCARDS_QUESTION_TOPICS($enrollmentDetailId: Int!) {
  5. person {
  6. learner {
  7. flashcards(enrollmentDetailId: $enrollmentDetailId) {
  8. nodes {
  9. nodeId
  10. title
  11. userStats{
  12. bookmarkedQuestionCount
  13. questionCount
  14. answered
  15. incorrect
  16. }
  17. }
  18. }
  19. }
  20. }
  21. }
  22. ```
  23.  
  24. We also have the same Known/Unknown/Starred piles on the Flashcards Test Results Page.
  25.  
  26. For that reason, in order to have the top level Topics for a Test, we would require to also have a topics list there, except this time filtered by topics of that quiz only (instead of all possible existing topics).
  27.  
  28. I tried using what you suggested `test->question->Node->title` but the problem with that is the values returning are not top level enough (I receive "Module 29.3: Multiperiod Models" instead of "Economics" for example).
  29.  
  30. Also, even if the node titles were returned in the level expected, I'd have to extract the topics from each question in order to generate the topics list dynamically.
  31.  
  32. Then, every time the user selected a topic card, I'd be retrieving all questions for that topic but would have to filter out most and preserve only the ones we're looking to show the student (the ones for that given quiz), which in the end I believe would not be recommended for purposes of performance and code maintainability
  33.  
  34. The queries I was looking for are similar to the pseudocodes below:
  35.  
  36. ### Get topics by test id:
  37.  
  38. ```graphql
  39. query TEST_TOPICS_BY_ID($enrollmentDetailId: Int!, $testId: Int!) {
  40. person {
  41. learner {
  42. flashcards(enrollmentDetailId: $enrollmentDetailId) {
  43. nodes(testId: $testId) {
  44. title
  45. nodeId
  46. userStats{
  47. bookmarkedQuestionCount
  48. questionCount
  49. answered
  50. incorrect
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. ```
  58.  
  59. And then, when the student selects a Topic in the Test Results page:
  60.  
  61. ### Get all questions for the topic, by test id
  62.  
  63. ```graphql
  64. query QUESTIONS_BY_TOPIC($parentNodeId: Int!, $enrollmentDetailId: Int!, $testId: Int!)
  65. person {
  66. learner {
  67. flashcards(enrollmentDetailId: $enrollmentDetailId) {
  68. nodes(parentNodeId: $parentNodeId, testId: $testId) {
  69. questions
  70. }
  71. }
  72. }
  73. }
  74. }
  75.  
  76. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement