models, graph2: Added Comment type and queries, and hooked it up to chapter.
the build was successful

This commit is contained in:
2019-01-14 17:03:16 +01:00
parent 53a86c0b9c
commit d22ab387dd
14 changed files with 306 additions and 8 deletions
+4
View File
@@ -35,6 +35,10 @@ models:
model: git.aiterp.net/rpdata/api/models/logs.Filter
LogImporter:
model: git.aiterp.net/rpdata/api/models.LogImporter
Comment:
model: git.aiterp.net/rpdata/api/models.Comment
ChapterCommentMode:
model: git.aiterp.net/rpdata/api/models.ChapterCommentMode
Chapter:
model: git.aiterp.net/rpdata/api/models.Chapter
fields:
+4
View File
@@ -34,6 +34,10 @@ func (r *rootResolver) Log() LogResolver {
return &types.LogResolver
}
func (r *rootResolver) Comment() CommentResolver {
return &types.CommentResolver
}
func (r *rootResolver) Chapter() ChapterResolver {
return &types.ChapterResolver
}
+15
View File
@@ -0,0 +1,15 @@
package queries
import (
"context"
"git.aiterp.net/rpdata/api/models/comments"
"git.aiterp.net/rpdata/api/models"
)
// Queries
func (r *resolver) Comment(ctx context.Context, id string) (models.Comment, error) {
return comments.Find(id)
}
+4
View File
@@ -41,6 +41,10 @@ type Query {
chapter(id: String!): Chapter!
# Find comment by ID
comment(id: String!): Comment!
# Find all distinct tags used in stories
tags: [Tag!]!
+29
View File
@@ -20,6 +20,35 @@ type Chapter {
# The date of edit.
editedDate: Date!
"The comment mode."
commentMode: ChapterCommentMode!
"Whether the author has locket comments."
commentsLocked: Boolean!
"A shorthand for checking whether a logged-in user can comment on this chapter."
canComment: Boolean!
"Get all chapter comments."
comments(limit: Int): [Comment!]!
}
"""
The possibles modes of comments for a chapter.
"""
enum ChapterCommentMode {
"Comments are disabled and hidden."
Disabled
"Comments should be shown as typical news article comments."
Article
"Comments should be shown in a compact form suitable for many small messages."
Chat
"Comments are going to be shown as omni-tool messages."
Message
}
# Input for addChapter mutation
+31
View File
@@ -0,0 +1,31 @@
"""
A Comment represents a comment to a story chapter.
"""
type Comment {
"A unique ID of the change."
id: String!
"subject"
subject: String!
"The comment's author."
author: String!
"The displayed name of the character. This may be the same as character.name, but it does not need to be."
characterName: String!
"The character associated with the comment."
character: Character
"The fictional (IC) date of the comment."
fictionalDate: Date
"The date of creation."
createdDate: Date!
"The date of the last edit."
editedDate: Date!
"The markdown source of the comment."
source: String!
}
+15
View File
@@ -2,9 +2,11 @@ package types
import (
"context"
"errors"
"time"
"git.aiterp.net/rpdata/api/models"
"git.aiterp.net/rpdata/api/models/comments"
)
type chapterResolver struct{}
@@ -17,5 +19,18 @@ func (r *chapterResolver) FictionalDate(ctx context.Context, chapter *models.Cha
return &chapter.FictionalDate, nil
}
func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter, limit *int) ([]models.Comment, error) {
limitValue := 0
if limit != nil {
if *limit < 0 {
return nil, errors.New("Limit cannot be negative")
}
limitValue = *limit
}
return comments.ListChapterID(chapter.ID, limitValue)
}
// ChapterResolver is a resolver
var ChapterResolver chapterResolver
+27
View File
@@ -0,0 +1,27 @@
package types
import (
"context"
"git.aiterp.net/rpdata/api/models/characters"
"git.aiterp.net/rpdata/api/models"
)
type commentResolver struct{}
func (r *commentResolver) Character(ctx context.Context, obj *models.Comment) (*models.Character, error) {
if obj.CharacterID == "" {
return nil, nil
}
character, err := characters.FindID(obj.CharacterID)
if err != nil {
return nil, err
}
return &character, nil
}
// CommentResolver is a resolver
var CommentResolver commentResolver