add subjects and reviwers query
This commit is contained in:
9
app/graphql/types/axis_type.rb
Normal file
9
app/graphql/types/axis_type.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Types
|
||||
class AxisType < Types::BaseObject
|
||||
field :id, ID, null: false
|
||||
field :name, String, null: false
|
||||
field :subjects, [SubjectType], null: false
|
||||
end
|
||||
end
|
||||
9
app/graphql/types/category_type.rb
Normal file
9
app/graphql/types/category_type.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Types
|
||||
class CategoryType < Types::BaseObject
|
||||
field :id, ID, null: false
|
||||
field :name, String, null: false
|
||||
field :subjects, [SubjectType], null: false
|
||||
end
|
||||
end
|
||||
@@ -1,19 +1,27 @@
|
||||
module Types
|
||||
class QueryType < Types::BaseObject
|
||||
# Add `node(id: ID!) and `nodes(ids: [ID!]!)`
|
||||
include GraphQL::Types::Relay::HasNodeField
|
||||
include GraphQL::Types::Relay::HasNodesField
|
||||
|
||||
field :questions, QuestionType.connection_type, null: false do
|
||||
argument :where, Inputs::QuestionWhereInput, required: false
|
||||
end
|
||||
|
||||
field :subjects, SubjectType.connection_type, null: false
|
||||
field :reviewers, UserType.connection_type, null: false
|
||||
field :current_user, Types::UserType, null: true
|
||||
|
||||
def questions(where: nil)
|
||||
Resolvers::QuestionsQueryResolver.new(Question, context: context, where: where).resolve
|
||||
end
|
||||
|
||||
def subjects
|
||||
Resolvers::SubjectsQueryResolver.new(context).resolve
|
||||
end
|
||||
|
||||
def reviewers
|
||||
Resolvers::ReviewersQueryResolver.new(context).resolve
|
||||
end
|
||||
|
||||
def current_user
|
||||
context[:current_user]
|
||||
end
|
||||
|
||||
25
app/graphql/types/subject_type.rb
Normal file
25
app/graphql/types/subject_type.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Types
|
||||
class SubjectType < Types::BaseObject
|
||||
field :id, ID, null: false
|
||||
field :name, String, null: false
|
||||
|
||||
field :axis, AxisType, null: false
|
||||
def axis
|
||||
dataloader.with(Sources::ActiveRecord, Axis).load(object.axis_id)
|
||||
end
|
||||
|
||||
field :category, CategoryType, null: false
|
||||
def category
|
||||
dataloader.with(Sources::ActiveRecord, Category).load(object.category_id)
|
||||
end
|
||||
|
||||
field :questions, QuestionType.connection_type, null: false do
|
||||
argument :where, Inputs::QuestionWhereInput, required: false
|
||||
end
|
||||
def questions(where: nil)
|
||||
Resolvers::QuestionsQueryResolver.new(object.questions, context: context, where: where).resolve
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user