This commit is contained in:
@@ -1 +1,96 @@
|
|||||||
package resolver
|
package resolver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.aiterp.net/rpdata/api/model/story"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StoryResolver for the Story graphql type
|
||||||
|
type StoryResolver struct{ S story.Story }
|
||||||
|
|
||||||
|
// StoryArgs is args for channel query
|
||||||
|
type StoryArgs struct {
|
||||||
|
ID string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Story implements the channel query
|
||||||
|
func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*StoryResolver, error) {
|
||||||
|
story, err := story.FindID(args.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &StoryResolver{S: story}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID resolves Story.id
|
||||||
|
func (r *StoryResolver) ID() string {
|
||||||
|
return r.S.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Author resolves Story.author
|
||||||
|
func (r *StoryResolver) Author() string {
|
||||||
|
return r.S.Author
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name resolves Story.name
|
||||||
|
func (r *StoryResolver) Name() string {
|
||||||
|
return r.S.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Category resolves Story.category
|
||||||
|
func (r *StoryResolver) Category() string {
|
||||||
|
return r.S.Category
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open resolves Story.open
|
||||||
|
func (r *StoryResolver) Open() bool {
|
||||||
|
return r.S.Open
|
||||||
|
}
|
||||||
|
|
||||||
|
// Listed resolves Story.listed
|
||||||
|
func (r *StoryResolver) Listed() bool {
|
||||||
|
return r.S.Listed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tags resolves Story.tags
|
||||||
|
func (r *StoryResolver) Tags() []*TagResolver {
|
||||||
|
resolvers := make([]*TagResolver, len(r.S.Tags))
|
||||||
|
for i, tag := range r.S.Tags {
|
||||||
|
resolvers[i] = &TagResolver{T: tag}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolvers
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chapters resolves Story.chapters
|
||||||
|
func (r *StoryResolver) Chapters() ([]*ChapterResolver, error) {
|
||||||
|
chapters, err := r.S.Chapters()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resolvers := make([]*ChapterResolver, len(chapters))
|
||||||
|
for i, chapter := range chapters {
|
||||||
|
resolvers[i] = &ChapterResolver{C: chapter}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolvers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedDate resolves Story.createdDate
|
||||||
|
func (r *StoryResolver) CreatedDate() string {
|
||||||
|
return r.S.CreatedDate.Format(time.RFC3339Nano)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FictionalDate resolves Story.fictionalDate
|
||||||
|
func (r *StoryResolver) FictionalDate() string {
|
||||||
|
return r.S.FictionalDate.Format(time.RFC3339Nano)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedDate resolves Story.updatedDate
|
||||||
|
func (r *StoryResolver) UpdatedDate() string {
|
||||||
|
return r.S.UpdatedDate.Format(time.RFC3339Nano)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package resolver
|
||||||
|
|
||||||
|
import "git.aiterp.net/rpdata/api/model/story"
|
||||||
|
|
||||||
|
// TagResolver for the Tag graphql type
|
||||||
|
type TagResolver struct{ T story.Tag }
|
||||||
|
|
||||||
|
// Kind resolves Tag.kind
|
||||||
|
func (r *TagResolver) Kind() string {
|
||||||
|
return r.T.Kind
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name resolves Tag.name
|
||||||
|
func (r *TagResolver) Name() string {
|
||||||
|
return r.T.Name
|
||||||
|
}
|
||||||
@@ -36,6 +36,10 @@ type Query {
|
|||||||
files(includePublic: Boolean, mimeTypes: [String!]): [File!]!
|
files(includePublic: Boolean, mimeTypes: [String!]): [File!]!
|
||||||
|
|
||||||
|
|
||||||
|
# Find story by ID
|
||||||
|
story(id: String!): Story
|
||||||
|
|
||||||
|
|
||||||
# Find story chapter by ID
|
# Find story chapter by ID
|
||||||
chapter(id: String!): Chapter
|
chapter(id: String!): Chapter
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ type Story {
|
|||||||
# The tags for this tory
|
# The tags for this tory
|
||||||
tags: [Tag!]!
|
tags: [Tag!]!
|
||||||
|
|
||||||
|
# The chapters of this story
|
||||||
|
chapters: [Chapter!]!
|
||||||
|
|
||||||
# The date the story was created (RFC3339 format).
|
# The date the story was created (RFC3339 format).
|
||||||
createdDate: String!
|
createdDate: String!
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,15 @@ type Tag {
|
|||||||
name: String!
|
name: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# A Tag is a means of associating stories that have details in common with one another.
|
||||||
|
input TagInput {
|
||||||
|
# The tag's kind
|
||||||
|
kind: TagKind!
|
||||||
|
|
||||||
|
# The tag's name
|
||||||
|
name: String!
|
||||||
|
}
|
||||||
|
|
||||||
# Allowed values for Tag.kind
|
# Allowed values for Tag.kind
|
||||||
enum TagKind {
|
enum TagKind {
|
||||||
# An organization is a catch all term for in-universe corporations, teams, groups, cults, forces, etc...
|
# An organization is a catch all term for in-universe corporations, teams, groups, cults, forces, etc...
|
||||||
|
|||||||
Reference in New Issue
Block a user