Created CommentableInterface

This commit is contained in:
Alberto Miedes Garcés
2016-09-30 12:03:37 +02:00
parent c4c6b1b9f7
commit afd0e98cea
4 changed files with 28 additions and 0 deletions

View File

@@ -17,4 +17,5 @@ CommentType = GraphQL::ObjectType.define do
# Linked resources
field :user, !UserType, "User who made this comment"
field :commentable, CommentableInterface, "Element which was commented"
end

View File

@@ -0,0 +1,21 @@
CommentableInterface = GraphQL::InterfaceType.define do
name "Commentable"
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"
field :author_id, types.Int, "ID of the author of this commentable"
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"
field :geozone, GeozoneType, "Geozone affected by this commentable"
end
# Then, object types may include it:
CoffeeType = GraphQL::ObjectType.define do
# ...
interfaces([BeverageInterface])
end

View File

@@ -1,6 +1,9 @@
DebateType = GraphQL::ObjectType.define do
name "Debate"
description "A single debate entry with associated info"
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"

View File

@@ -1,6 +1,9 @@
ProposalType = GraphQL::ObjectType.define do
name "Proposal"
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"