Add more fields to api.yml

This commit is contained in:
Alberto Miedes Garcés
2017-01-09 14:11:51 +01:00
parent b0bd30e3d1
commit 6940b90260
6 changed files with 17 additions and 3 deletions

View File

@@ -19,6 +19,8 @@ class Comment < ActiveRecord::Base
belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true
belongs_to :user, -> { with_hidden }
has_many :votes, -> { for_comments }, foreign_key: 'votable_id'
before_save :calculate_confidence_score
scope :for_render, -> { with_hidden.includes(user: :organization) }

View File

@@ -17,6 +17,7 @@ class Debate < ActiveRecord::Base
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :geozone
has_many :comments, as: :commentable
has_many :votes, -> { for_debates }, foreign_key: 'votable_id'
validates :title, presence: true
validates :description, presence: true

View File

@@ -19,6 +19,7 @@ class Proposal < ActiveRecord::Base
belongs_to :geozone
has_many :comments, as: :commentable
has_many :proposal_notifications
has_many :votes, -> { for_proposals }, foreign_key: 'votable_id'
validates :title, presence: true
validates :question, presence: true

View File

@@ -1,5 +1,9 @@
class Vote < ActsAsVotable::Vote
scope :for_debates, -> { where(votable_type: 'Debate') }
scope :for_proposals, -> { where(votable_type: 'Proposal') }
scope :for_comments, -> { where(votable_type: 'Comment') }
scope :public_for_api, -> do
joins("FULL OUTER JOIN debates ON votable_type = 'Debate' AND votable_id = debates.id").
joins("FULL OUTER JOIN proposals ON votable_type = 'Proposal' AND votable_id = proposals.id").

View File

@@ -1,7 +1,10 @@
User:
fields:
id: integer
username: string
id: integer
username: string
debates: [Debate]
proposals: [Proposal]
comments: [Comment]
Voter:
fields:
gender: string
@@ -24,6 +27,7 @@ Debate:
geozone: Geozone
comments: [Comment]
public_author: User
votes: [Vote]
Proposal:
fields:
id: integer
@@ -45,6 +49,7 @@ Proposal:
comments: [Comment]
proposal_notifications: [ProposalNotification]
public_author: User
votes: [Vote]
Comment:
fields:
id: integer
@@ -58,6 +63,7 @@ Comment:
ancestry: string
confidence_score: integer
public_author: User
votes: [Vote]
Geozone:
fields:
id: integer

View File

@@ -9,7 +9,7 @@ QueryType = query_type_creator.create
ConsulSchema = GraphQL::Schema.define do
query QueryType
max_depth 10
max_depth 12
resolve_type -> (object, ctx) do
type_name = object.class.name # look up types by class name