Expose public_author for proposals
This commit is contained in:
9
app/models/concerns/has_public_author.rb
Normal file
9
app/models/concerns/has_public_author.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module HasPublicAuthor
|
||||
def public_author_id
|
||||
public_author.try(:id)
|
||||
end
|
||||
|
||||
def public_author
|
||||
self.author.public_activity? ? self.author : nil
|
||||
end
|
||||
end
|
||||
9
app/models/concerns/has_public_author_types.rb
Normal file
9
app/models/concerns/has_public_author_types.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module HasPublicAuthorTypes
|
||||
def public_author_id_type
|
||||
GraphQL::INT_TYPE
|
||||
end
|
||||
|
||||
def public_author_type
|
||||
TypeCreator.created_types[User]
|
||||
end
|
||||
end
|
||||
@@ -6,6 +6,8 @@ class Proposal < ActiveRecord::Base
|
||||
include Sanitizable
|
||||
include Searchable
|
||||
include Filterable
|
||||
include HasPublicAuthor
|
||||
extend HasPublicAuthorTypes
|
||||
|
||||
acts_as_votable
|
||||
acts_as_paranoid column: :hidden_at
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
API_TYPE_DEFINITIONS = {
|
||||
User => %I[ id username proposals organization ],
|
||||
Debate => %I[ id title description author_id author created_at comments ],
|
||||
Proposal => %I[ id title description author_id author created_at comments ],
|
||||
Proposal => %I[ id title description author_id author public_author_id public_author created_at comments ],
|
||||
Comment => %I[ id body user_id user commentable_id ],
|
||||
Organization => %I[ id name ]
|
||||
}
|
||||
|
||||
type_creator = GraphQL::TypeCreator.new
|
||||
TypeCreator = GraphQL::TypeCreator.new
|
||||
|
||||
API_TYPE_DEFINITIONS.each do |model, fields|
|
||||
type_creator.create(model, fields)
|
||||
TypeCreator.create(model, fields)
|
||||
end
|
||||
|
||||
ConsulSchema = GraphQL::Schema.define do
|
||||
@@ -29,7 +29,7 @@ QueryRoot = GraphQL::ObjectType.define do
|
||||
name "Query"
|
||||
description "The query root for this schema"
|
||||
|
||||
type_creator.created_types.each do |model, created_type|
|
||||
TypeCreator.created_types.each do |model, created_type|
|
||||
|
||||
# create an entry field to retrive a single object
|
||||
field model.name.underscore.to_sym do
|
||||
|
||||
@@ -22,17 +22,18 @@ module GraphQL
|
||||
name(model.name)
|
||||
description("#{model.model_name.human}")
|
||||
|
||||
# Make a field for each column
|
||||
# Make a field for each column, association or method
|
||||
field_names.each do |field_name|
|
||||
if model.column_names.include?(field_name.to_s)
|
||||
field(field_name.to_s, TYPES_CONVERSION[model.columns_hash[field_name.to_s].type])
|
||||
else
|
||||
association = type_creator.class.association?(model, field_name)
|
||||
elsif association = type_creator.class.association?(model, field_name)
|
||||
if type_creator.class.needs_pagination?(association)
|
||||
connection association.name, -> { type_creator.created_types[association.klass].connection_type }
|
||||
else
|
||||
field association.name, -> { type_creator.created_types[association.klass] }
|
||||
end
|
||||
else
|
||||
field field_name.to_s, model.send("#{field_name}_type".to_sym)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user