graphql: add some top-level fields
These objects were originally accessible via the node/legacyNode, but these first-class fields will be a bit more convenient to use. Test plan: * retrieve objects from the top-level course/assignment/assignmentGroup fields Change-Id: I6f64a0841a36dabd753e8e91aa4145689d56fc1b Reviewed-on: https://gerrit.instructure.com/167469 Reviewed-by: Carl Kibler <ckibler@instructure.com> Tested-by: Jenkins QA-Review: Cameron Matheson <cameron@instructure.com> Product-Review: Cameron Matheson <cameron@instructure.com>
This commit is contained in:
parent
f3ae09158c
commit
6b0114e9d0
|
@ -31,6 +31,30 @@ module Types
|
|||
GraphQLNodeLoader.load(type, _id, context)
|
||||
end
|
||||
|
||||
field :course, Types::CourseType, null: true do
|
||||
argument :id, ID, "a graphql or legacy id", required: true,
|
||||
prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func("Course")
|
||||
end
|
||||
def course(id:)
|
||||
GraphQLNodeLoader.load("Course", id, context)
|
||||
end
|
||||
|
||||
field :assignment, Types::AssignmentType, null: true do
|
||||
argument :id, ID, "a graphql or legacy id", required: true,
|
||||
prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func("Course")
|
||||
end
|
||||
def assignment(id:)
|
||||
GraphQLNodeLoader.load("Assignment", id, context)
|
||||
end
|
||||
|
||||
field :assignment_group, Types::AssignmentGroupType, null: true do
|
||||
argument :id, ID, "a graphql or legacy id", required: true,
|
||||
prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func("Course")
|
||||
end
|
||||
def assignment_group(id:)
|
||||
GraphQLNodeLoader.load("AssignmentGroup", id, context)
|
||||
end
|
||||
|
||||
field :all_courses, [CourseType],
|
||||
"All courses viewable by the current user",
|
||||
null: true
|
||||
|
|
|
@ -747,6 +747,18 @@ type PageViewAnalysis {
|
|||
type Query {
|
||||
# All courses viewable by the current user
|
||||
allCourses: [Course!]
|
||||
assignment(
|
||||
# a graphql or legacy id
|
||||
id: ID!
|
||||
): Assignment
|
||||
assignmentGroup(
|
||||
# a graphql or legacy id
|
||||
id: ID!
|
||||
): AssignmentGroup
|
||||
course(
|
||||
# a graphql or legacy id
|
||||
id: ID!
|
||||
): Course
|
||||
|
||||
# Fetches an object given its type and legacy ID
|
||||
legacyNode(_id: ID!, type: NodeType!): Node
|
||||
|
|
|
@ -37,6 +37,19 @@ describe Types::AssignmentGroupType do
|
|||
@group_type = GraphQLTypeTester.new(@group, current_user: @student)
|
||||
end
|
||||
|
||||
context "top-level permissions" do
|
||||
it "needs read permission" do
|
||||
some_person = user_factory(active_all: true)
|
||||
expect(@group_type.resolve("_id", current_user: some_person)).to be_nil
|
||||
|
||||
expect(
|
||||
CanvasSchema.execute(<<~GQL, context: {current_user: some_person}).dig("data", "ag")
|
||||
query { ag: assignmentGroup(id: "#{@group.id}") { id } }
|
||||
GQL
|
||||
).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it "returns information about the group" do
|
||||
expect(@group_type.resolve("_id")).to eq @group.id.to_s
|
||||
expect(@group_type.resolve("name")).to eq @group.name
|
||||
|
|
|
@ -43,9 +43,20 @@ describe Types::AssignmentType do
|
|||
expect(assignment_type.resolve("muted")).to eq assignment.muted?
|
||||
end
|
||||
|
||||
it "requires read permission" do
|
||||
assignment.unpublish
|
||||
expect(assignment_type.resolve("_id")).to be_nil
|
||||
context "top-level permissions" do
|
||||
it "requires read permission" do
|
||||
assignment.unpublish
|
||||
|
||||
# node / legacy node
|
||||
expect(assignment_type.resolve("_id")).to be_nil
|
||||
|
||||
# assignment
|
||||
expect(
|
||||
CanvasSchema.execute(<<~GQL, context: {current_user: student}).dig("data", "assignment")
|
||||
query { assignment(id: "#{assignment.id.to_s}") { id } }
|
||||
GQL
|
||||
).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it "returns needsGradingCount" do
|
||||
|
|
|
@ -33,11 +33,21 @@ describe Types::CourseType do
|
|||
expect(course_type.resolve("name")).to eq course.name
|
||||
end
|
||||
|
||||
it "needs read permission" do
|
||||
course_with_student
|
||||
@course2, @student2 = @course, @student
|
||||
context "top-level permissions" do
|
||||
it "needs read permission" do
|
||||
course_with_student
|
||||
@course2, @student2 = @course, @student
|
||||
|
||||
expect(course_type.resolve("_id", current_user: @student2)).to be_nil
|
||||
# node / legacy node
|
||||
expect(course_type.resolve("_id", current_user: @student2)).to be_nil
|
||||
|
||||
# course
|
||||
expect(
|
||||
CanvasSchema.execute(<<~GQL, context: {current_user: @student2}).dig("data", "course")
|
||||
query { course(id: "#{course.id.to_s}") { id } }
|
||||
GQL
|
||||
).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "assignmentsConnection" do
|
||||
|
|
Loading…
Reference in New Issue