diff --git a/app/graphql/types/base_object.rb b/app/graphql/types/base_object.rb index 252294d44..3397275d2 100644 --- a/app/graphql/types/base_object.rb +++ b/app/graphql/types/base_object.rb @@ -30,5 +30,9 @@ module Types argument :id, ID, required: true, default_value: false end end + + def self.collection_field(field_name, type, ...) + field(field_name, type.connection_type, ...) + end end end diff --git a/app/graphql/types/budget_investment_type.rb b/app/graphql/types/budget_investment_type.rb index 15b1bd0d1..ded6b6bd9 100644 --- a/app/graphql/types/budget_investment_type.rb +++ b/app/graphql/types/budget_investment_type.rb @@ -7,8 +7,8 @@ module Types field :title, String, null: true field :description, String, null: true field :location, String, null: true - field :comments, Types::CommentType.connection_type, null: true + collection_field :comments, Types::CommentType, null: true field :comments_count, Integer, null: true - field :milestones, Types::MilestoneType.connection_type, null: true + collection_field :milestones, Types::MilestoneType, null: true end end diff --git a/app/graphql/types/budget_type.rb b/app/graphql/types/budget_type.rb index b31294196..1c32a3c4b 100644 --- a/app/graphql/types/budget_type.rb +++ b/app/graphql/types/budget_type.rb @@ -3,7 +3,7 @@ module Types field :id, ID, null: false field :name, String, null: true field :phase, String, null: true - field :investments, Types::BudgetInvestmentType.connection_type, "Returns all investments", null: false + collection_field :investments, Types::BudgetInvestmentType, "Returns all investments", null: false object_by_id_field :investment, Types::BudgetInvestmentType, "Returns investment for ID", null: false def investments diff --git a/app/graphql/types/comment_type.rb b/app/graphql/types/comment_type.rb index f022d1f0c..e7c72b667 100644 --- a/app/graphql/types/comment_type.rb +++ b/app/graphql/types/comment_type.rb @@ -11,6 +11,6 @@ module Types field :id, ID, null: false field :public_author, Types::UserType, null: true field :public_created_at, String, null: true - field :votes_for, Types::VoteType.connection_type, null: true + collection_field :votes_for, Types::VoteType, null: true end end diff --git a/app/graphql/types/debate_type.rb b/app/graphql/types/debate_type.rb index a5edaf313..35e3f5db0 100644 --- a/app/graphql/types/debate_type.rb +++ b/app/graphql/types/debate_type.rb @@ -3,7 +3,7 @@ module Types field :cached_votes_down, Integer, null: true field :cached_votes_total, Integer, null: true field :cached_votes_up, Integer, null: true - field :comments, Types::CommentType.connection_type, null: true + collection_field :comments, Types::CommentType, null: true field :comments_count, Integer, null: true field :confidence_score, Integer, null: true field :description, String, null: true @@ -11,9 +11,9 @@ module Types field :id, ID, null: false field :public_author, Types::UserType, null: true field :public_created_at, String, null: true - field :tags, Types::TagType.connection_type, null: true + collection_field :tags, Types::TagType, null: true field :title, String, null: true - field :votes_for, Types::VoteType.connection_type, null: true + collection_field :votes_for, Types::VoteType, null: true def tags object.tags.public_for_api diff --git a/app/graphql/types/proposal_type.rb b/app/graphql/types/proposal_type.rb index 7d9eb78a6..fc512dfae 100644 --- a/app/graphql/types/proposal_type.rb +++ b/app/graphql/types/proposal_type.rb @@ -1,7 +1,7 @@ module Types class ProposalType < Types::BaseObject field :cached_votes_up, Integer, null: true - field :comments, Types::CommentType.connection_type, null: true + collection_field :comments, Types::CommentType, null: true field :comments_count, Integer, null: true field :confidence_score, Integer, null: true field :description, String, null: true @@ -9,18 +9,18 @@ module Types field :geozone_id, Integer, null: true field :hot_score, Integer, null: true field :id, ID, null: false - field :proposal_notifications, Types::ProposalNotificationType.connection_type, null: true + collection_field :proposal_notifications, Types::ProposalNotificationType, null: true field :public_author, Types::UserType, null: true field :public_created_at, String, null: true field :retired_at, GraphQL::Types::ISO8601DateTime, null: true field :retired_explanation, String, null: true field :retired_reason, String, null: true field :summary, String, null: true - field :tags, Types::TagType.connection_type, null: true + collection_field :tags, Types::TagType, null: true field :title, String, null: true field :video_url, String, null: true - field :votes_for, Types::VoteType.connection_type, null: true - field :milestones, Types::MilestoneType.connection_type, null: true + collection_field :votes_for, Types::VoteType, null: true + collection_field :milestones, Types::MilestoneType, null: true def tags object.tags.public_for_api diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index ce06a04a8..73eb4e92e 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -1,10 +1,7 @@ module Types class QueryType < Types::BaseObject def self.collection_and_object_by_id_fields(name, type) - field name.to_s.pluralize.to_sym, - type.connection_type, - "Returns all #{name.to_s.pluralize}", - null: false + collection_field name.to_s.pluralize.to_sym, type, "Returns all #{name.to_s.pluralize}", null: false object_by_id_field name, type, "Returns #{name} for ID", null: false end diff --git a/app/graphql/types/user_type.rb b/app/graphql/types/user_type.rb index 57713ed92..059994fb5 100644 --- a/app/graphql/types/user_type.rb +++ b/app/graphql/types/user_type.rb @@ -1,9 +1,9 @@ module Types class UserType < Types::BaseObject field :id, ID, null: false - field :public_comments, Types::CommentType.connection_type, null: true - field :public_debates, Types::DebateType.connection_type, null: true - field :public_proposals, Types::ProposalType.connection_type, null: true + collection_field :public_comments, Types::CommentType, null: true + collection_field :public_debates, Types::DebateType, null: true + collection_field :public_proposals, Types::ProposalType, null: true field :username, String, null: true end end