add coursesConnection to Terms

refs: GQL-62

Test plan:
  * query term
  * term should have courses

Change-Id: Ib933f2199bffd5d2599a1ee654a93417337e4356
Reviewed-on: https://gerrit.instructure.com/192614
Tested-by: Jenkins
Reviewed-by: Cameron Matheson <cameron@instructure.com>
QA-Review: Cameron Matheson <cameron@instructure.com>
Product-Review: Cameron Matheson <cameron@instructure.com>
This commit is contained in:
cmena 2019-05-08 10:48:04 -06:00 committed by Chris Mena
parent c6cec68b67
commit a64f8549cd
5 changed files with 101 additions and 2 deletions

View File

@ -22,6 +22,12 @@ module Types
description "Contains grade information for a course or grading period"
class GradeState < BaseEnum
graphql_name "GradeState"
value "active"
value "deleted"
end
field :current_score, Float, <<~DESC, null: true
The current score includes all graded assignments, excluding muted submissions.
DESC
@ -59,6 +65,8 @@ module Types
load_association :grading_period
end
field :state, GradeState, method: :workflow_state, null: false
field :assignment_group, AssignmentGroupType, null: true
def assignment_group
load_association(:assignment_group)

View File

@ -21,11 +21,23 @@ module Types
implements GraphQL::Types::Relay::Node
graphql_name "Term"
alias term object
global_id_field :id
field :_id, ID, "legacy canvas id", method: :id, null: false
field :name, String, null: true
field :start_at, DateTimeType, null: true
field :end_at, DateTimeType, null: true
field :courses_connection, CourseType.connection_type, null: true do
description "courses for this term"
end
def courses_connection
load_association(:root_account).then do |account|
next unless account.grants_any_right?(current_user, :manage_courses, :manage_account_settings)
term.courses
end
end
end
end

View File

@ -752,6 +752,41 @@ type Course implements AssignmentsConnectionInterface & Node & Timestamped {
): UserConnection
}
"""
The connection type for Course.
"""
type CourseConnection {
"""
A list of edges.
"""
edges: [CourseEdge]
"""
A list of nodes.
"""
nodes: [Course]
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
"""
An edge in a connection.
"""
type CourseEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: Course
}
"""
Users in a course can be returned based on these enrollment states
"""
@ -1002,6 +1037,11 @@ type File implements ModuleItemInterface & Node & Timestamped {
url: URL
}
enum GradeState {
active
deleted
}
"""
Contains grade information for a course or grading period
"""
@ -1032,6 +1072,7 @@ type Grades {
The override score. Supersedes the computed final score if set.
"""
overrideScore: Float
state: GradeState!
unpostedCurrentGrade: String
"""
@ -2466,6 +2507,31 @@ type Term implements Node {
legacy canvas id
"""
_id: ID!
"""
courses for this term
"""
coursesConnection(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): CourseConnection
endAt: DateTime
id: ID!
name: String

View File

@ -107,5 +107,9 @@ describe Types::GradesType do
it "resolves the gradingPeriod field to the score's associated grading period" do
expect(resolve_grades_field("gradingPeriod { title }")).to eq 'Pleistocene'
end
it "resolves the state field to the Score's workflow_state" do
expect(resolve_grades_field("state")).to eq 'active'
end
end
end

View File

@ -25,14 +25,23 @@ describe Types::TermType do
course_with_student(active_all: true)
@term = @course.enrollment_term
@term_type = GraphQLTypeTester.new(@term, current_user: @teacher)
@admin = account_admin_user
end
it "works" do
expect(@term_type.resolve("_id")).to eq @term.id.to_s
expect(@term_type.resolve("name")).to eq @term.name
expect(@term_type.resolve("_id", current_user: @teacher)).to eq @term.id.to_s
expect(@term_type.resolve("name", current_user: @teacher)).to eq @term.name
end
it "requires read permission" do
expect(@term_type.resolve("_id", current_user: @student)).to be_nil
end
it 'should have coursesConnection' do
expect(@term_type.resolve("coursesConnection { nodes { _id } }", current_user: @admin)).to eq [@course.id.to_s]
end
it 'should require admin privilege' do
expect(@term_type.resolve("coursesConnection { nodes { _id } }", current_user: @student)).to be_nil
end
end