GraphQLStudentContextTray.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import $ from "jquery";
  2. import React from "react";
  3. import {
  4. ApolloProvider,
  5. ApolloClient,
  6. createNetworkInterface,
  7. gql,
  8. graphql
  9. } from "react-apollo";
  10. import StudentContextTray from "jsx/context_cards/StudentContextTray";
  11. const client = new ApolloClient({
  12. networkInterface: createNetworkInterface({
  13. uri: "/api/graphql",
  14. opts: {
  15. headers: {
  16. "X-Requested-With": "XMLHttpRequest",
  17. "X-CSRF-Token": $.cookie("_csrf_token") // TODO: probably need to move this io a middleware (http://dev.apollodata.com/core/network.html)
  18. },
  19. credentials: "same-origin"
  20. }
  21. })
  22. });
  23. /*
  24. * TODO: is loading grades or enrollments slowing this query way down?
  25. */
  26. const GraphQLStudentContextCard = graphql(
  27. gql`
  28. query StudentContextCard(
  29. $courseId: ID!
  30. $studentId: ID!
  31. ) {
  32. course: legacyNode(type: Course, _id: $courseId) {
  33. ... on Course {
  34. _id
  35. name
  36. permissions {
  37. become_user: becomeUser
  38. manage_grades: manageGrades
  39. send_messages: sendMessages
  40. view_all_grades: viewAllGrades
  41. view_analytics: viewAnalytics
  42. }
  43. submissionsConnection(
  44. first: 10
  45. orderBy: [{ field: gradedAt, direction: descending }]
  46. studentIds: [$studentId]
  47. ) {
  48. edges {
  49. submission: node {
  50. id
  51. score
  52. grade
  53. excused
  54. user { _id }
  55. assignment {
  56. name
  57. html_url: htmlUrl
  58. points_possible: pointsPossible
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. user: legacyNode(type: User, _id: $studentId) {
  66. ... on User {
  67. _id
  68. short_name: shortName
  69. avatar_url: avatarUrl
  70. enrollments(courseId: $courseId) {
  71. last_activity_at: lastActivityAt
  72. section { name }
  73. grades {
  74. current_grade: currentGrade
  75. current_score: currentScore
  76. }
  77. }
  78. analytics: summaryAnalytics(courseId: $courseId) {
  79. page_views: pageViews {
  80. total
  81. max
  82. level
  83. }
  84. participations {
  85. total
  86. max
  87. level
  88. }
  89. tardiness_breakdown: tardinessBreakdown {
  90. late
  91. missing
  92. on_time: onTime
  93. }
  94. }
  95. }
  96. }
  97. }
  98. `,
  99. {
  100. options: props => ({
  101. variables: {
  102. courseId: props.courseId,
  103. studentId: props.studentId,
  104. }
  105. })
  106. }
  107. )(StudentContextTray);
  108. export default props => {
  109. return (
  110. <ApolloProvider client={client}>
  111. <GraphQLStudentContextCard {...props} />
  112. </ApolloProvider>
  113. );
  114. };