Add quiz and discussion to GraphQL

Closes RECNVS-28

Test Plan:

- Create a quiz (legacy) and verify that you can access the quiz
  ID through the quiz field on an Assignment through GraphQL
- Create a graded discussion and verify that you can access the
  discussion ID through the discussion field on an Assignment
  through GraphQL

Change-Id: Ifb6d812d0f48d9c5088735b4df656abfe361ffb1
Reviewed-on: https://gerrit.instructure.com/133078
Reviewed-by: Cameron Matheson <cameron@instructure.com>
Tested-by: Jenkins
QA-Review: Collin Parrish <cparrish@instructure.com>
Product-Review: Michael Jasper <mjasper@instructure.com>
This commit is contained in:
Michael Jasper 2017-11-16 13:34:15 -07:00
parent 3a4b8ff885
commit 1178c4cb2b
6 changed files with 148 additions and 0 deletions

View File

@ -22,6 +22,18 @@ module Types
"when this assignment is due",
property: :due_at
field :quiz, Types::QuizType, resolve: -> (assignment, _, _) {
Loaders::AssociationLoader.for(Assignment, :quiz)
.load(assignment)
.then { assignment.quiz }
}
field :discussion, Types::DiscussionType, resolve: -> (assignment, _, _) {
Loaders::AssociationLoader.for(Assignment, :discussion_topic)
.load(assignment)
.then { assignment.discussion_topic }
}
field :htmlUrl, UrlType, resolve: ->(assignment, _, ctx) {
Rails.application.routes.url_helpers.course_assignment_url(
course_id: assignment.context_id,

View File

@ -0,0 +1,29 @@
#
# Copyright (C) 2017 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module Types
DiscussionType = GraphQL::ObjectType.define do
name "Discussion"
implements GraphQL::Relay::Node.interface
interfaces [Interfaces::TimestampInterface]
global_id_field :id
field :_id, !types.ID, "legacy canvas id", property: :id
end
end

View File

@ -0,0 +1,29 @@
#
# Copyright (C) 2017 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module Types
QuizType = GraphQL::ObjectType.define do
name "Quiz"
implements GraphQL::Relay::Node.interface
interfaces [Interfaces::TimestampInterface]
global_id_field :id
field :_id, !types.ID, "legacy canvas id", property: :id
end
end

View File

@ -3,6 +3,7 @@ type Assignment implements Node, Timestamped {
_id: ID!
createdAt: Time
description: String
discussion: Discussion
# when this assignment is due
dueAt: String
@ -16,6 +17,7 @@ type Assignment implements Node, Timestamped {
# determines the order this assignment is displayed in in its assignment group
position: Int
quiz: Quiz
updatedAt: Time
}
@ -218,6 +220,14 @@ enum CourseWorkflowState {
deleted
}
type Discussion implements Node, Timestamped {
# legacy canvas id
_id: ID!
createdAt: Time
id: ID!
updatedAt: Time
}
type Enrollment implements Node, Timestamped {
# legacy canvas id
_id: ID!
@ -368,6 +378,14 @@ type Query {
): Node
}
type Quiz implements Node, Timestamped {
# legacy canvas id
_id: ID!
createdAt: Time
id: ID!
updatedAt: Time
}
type Section implements Node, Timestamped {
# legacy canvas id
_id: ID!

View File

@ -0,0 +1,30 @@
#
# Copyright (C) 2017 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../helpers/graphql_type_tester')
describe Types::DiscussionType do
let_once(:discussion) { group_discussion_assignment()}
let(:discussion_type) { GraphQLTypeTester.new(Types::QuizType, discussion) }
it "works" do
expect(discussion_type._id).to eq discussion.id
end
end

View File

@ -0,0 +1,30 @@
#
# Copyright (C) 2017 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../helpers/graphql_type_tester')
describe Types::QuizType do
let_once(:quiz) { quiz_with_submission()}
let(:quiz_type) { GraphQLTypeTester.new(Types::QuizType, quiz) }
it "works" do
expect(quiz_type._id).to eq quiz.id
end
end