Add support for GraphQL pagination
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
CommentableInterface = GraphQL::InterfaceType.define do
|
||||
name "Commentable"
|
||||
|
||||
# Expose fields associated with Commentable models
|
||||
|
||||
field :id, !types.ID, "ID of the commentable"
|
||||
field :title, types.String, "The title of this commentable"
|
||||
field :description, types.String, "The description of this commentable"
|
||||
@@ -8,7 +10,12 @@ CommentableInterface = GraphQL::InterfaceType.define do
|
||||
field :comments_count, types.Int, "Number of comments on this commentable"
|
||||
|
||||
# Linked resources
|
||||
|
||||
field :author, UserType, "Author of this commentable"
|
||||
field :comments, !types[!CommentType], "Comments in this commentable"
|
||||
|
||||
connection :comments, CommentType.connection_type do
|
||||
description "Comments in this commentable"
|
||||
end
|
||||
|
||||
field :geozone, GeozoneType, "Geozone affected by this commentable"
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ DebateType = GraphQL::ObjectType.define do
|
||||
interfaces([CommentableInterface])
|
||||
|
||||
# Expose fields associated with Debate model
|
||||
|
||||
field :id, !types.ID, "The id of this debate"
|
||||
field :title, types.String, "The title of this debate"
|
||||
field :description, types.String, "The description of this debate"
|
||||
@@ -19,7 +20,12 @@ DebateType = GraphQL::ObjectType.define do
|
||||
field :geozone_id, types.Int, "ID of the geozone affected by this debate"
|
||||
|
||||
# Linked resources
|
||||
|
||||
field :author, UserType, "Author of this debate"
|
||||
field :comments, !types[!CommentType], "Comments in this debate"
|
||||
|
||||
connection :comments, CommentType.connection_type do
|
||||
description "Comments in this debate"
|
||||
end
|
||||
|
||||
field :geozone, GeozoneType, "Geozone affected by this debate"
|
||||
end
|
||||
|
||||
@@ -3,8 +3,9 @@ ProposalType = GraphQL::ObjectType.define do
|
||||
description "A single proposal entry returns a proposal with author, total votes and comments"
|
||||
|
||||
interfaces([CommentableInterface])
|
||||
|
||||
|
||||
# Expose fields associated with Proposal model
|
||||
|
||||
field :id, !types.ID, "The id of this proposal"
|
||||
field :title, types.String, "The title of this proposal"
|
||||
field :description, types.String, "The description of this proposal"
|
||||
@@ -22,7 +23,12 @@ ProposalType = GraphQL::ObjectType.define do
|
||||
field :retired_explanation, types.String, "Explanation why this proposal was retired"
|
||||
|
||||
# Linked resources
|
||||
|
||||
field :author, UserType, "Author of this proposal"
|
||||
field :comments, !types[!CommentType], "Comments in this proposal"
|
||||
|
||||
connection :comments, CommentType.connection_type do
|
||||
description "Comments in this proposal"
|
||||
end
|
||||
|
||||
field :geozone, GeozoneType, "Geozone affected by this proposal"
|
||||
end
|
||||
|
||||
@@ -11,8 +11,7 @@ QueryRoot = GraphQL::ObjectType.define do
|
||||
}
|
||||
end
|
||||
|
||||
field :proposals do
|
||||
type !types[!ProposalType]
|
||||
connection :proposals, ProposalType.connection_type do
|
||||
description "Find all Proposals"
|
||||
resolve -> (object, arguments, context) {
|
||||
Proposal.all
|
||||
@@ -28,8 +27,7 @@ QueryRoot = GraphQL::ObjectType.define do
|
||||
}
|
||||
end
|
||||
|
||||
field :debates do
|
||||
type !types[!DebateType]
|
||||
connection :debates, DebateType.connection_type do
|
||||
description "Find all Debates"
|
||||
resolve -> (object, arguments, context) {
|
||||
Debate.all
|
||||
@@ -45,8 +43,7 @@ QueryRoot = GraphQL::ObjectType.define do
|
||||
}
|
||||
end
|
||||
|
||||
field :comments do
|
||||
type !types[!CommentType]
|
||||
connection :comments, CommentType.connection_type do
|
||||
description "Find all Comments"
|
||||
resolve -> (object, arguments, context) {
|
||||
Comment.all
|
||||
|
||||
Reference in New Issue
Block a user