diff --git a/app/graph/types/comment_type.rb b/app/graph/types/comment_type.rb index 9078257af..36a9f709e 100644 --- a/app/graph/types/comment_type.rb +++ b/app/graph/types/comment_type.rb @@ -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 diff --git a/app/graph/types/commentable_interface.rb b/app/graph/types/commentable_interface.rb new file mode 100644 index 000000000..3bbe96c4f --- /dev/null +++ b/app/graph/types/commentable_interface.rb @@ -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 diff --git a/app/graph/types/debate_type.rb b/app/graph/types/debate_type.rb index 095d50688..1cae3a2a4 100644 --- a/app/graph/types/debate_type.rb +++ b/app/graph/types/debate_type.rb @@ -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" diff --git a/app/graph/types/proposal_type.rb b/app/graph/types/proposal_type.rb index 8456f0a4f..007b5824c 100644 --- a/app/graph/types/proposal_type.rb +++ b/app/graph/types/proposal_type.rb @@ -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"