+68
-2
@@ -10,12 +10,12 @@ import (
|
||||
// StoryResolver for the Story graphql type
|
||||
type StoryResolver struct{ S story.Story }
|
||||
|
||||
// StoryArgs is args for channel query
|
||||
// StoryArgs is args for story query
|
||||
type StoryArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Story implements the channel query
|
||||
// Story implements the story query
|
||||
func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*StoryResolver, error) {
|
||||
story, err := story.FindID(args.ID)
|
||||
if err != nil {
|
||||
@@ -25,6 +25,72 @@ func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*StoryResol
|
||||
return &StoryResolver{S: story}, nil
|
||||
}
|
||||
|
||||
// StoriesArg is args for stories query
|
||||
type StoriesArg struct {
|
||||
Input *StoriesInput
|
||||
}
|
||||
|
||||
// StoriesInput resolves the TagInput input
|
||||
type StoriesInput struct {
|
||||
Author *string
|
||||
Tags *[]TagInput
|
||||
EarliestFictionalDate *string
|
||||
LatestFictionalDate *string
|
||||
Limit *int32
|
||||
}
|
||||
|
||||
// Stories implements the stories query
|
||||
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*StoryResolver, error) {
|
||||
author := ""
|
||||
if args.Input.Author != nil {
|
||||
author = *args.Input.Author
|
||||
}
|
||||
|
||||
tags := make([]story.Tag, 0, 8)
|
||||
if args.Input.Tags != nil {
|
||||
for _, tagInput := range *args.Input.Tags {
|
||||
tags = append(tags, story.Tag{
|
||||
Kind: tagInput.Kind,
|
||||
Name: tagInput.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
earliest := time.Time{}
|
||||
err := error(nil)
|
||||
if args.Input.EarliestFictionalDate != nil {
|
||||
earliest, err = time.Parse(time.RFC3339Nano, *args.Input.EarliestFictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
latest := time.Time{}
|
||||
if args.Input.LatestFictionalDate != nil {
|
||||
latest, err = time.Parse(time.RFC3339Nano, *args.Input.LatestFictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
limit := 30
|
||||
if args.Input.Limit != nil {
|
||||
limit = int(*args.Input.Limit)
|
||||
}
|
||||
|
||||
stories, err := story.List(author, tags, earliest, latest, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*StoryResolver, len(stories))
|
||||
for i, story := range stories {
|
||||
resolvers[i] = &StoryResolver{S: story}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
// ID resolves Story.id
|
||||
func (r *StoryResolver) ID() string {
|
||||
return r.S.ID
|
||||
|
||||
@@ -5,6 +5,12 @@ import "git.aiterp.net/rpdata/api/model/story"
|
||||
// TagResolver for the Tag graphql type
|
||||
type TagResolver struct{ T story.Tag }
|
||||
|
||||
// TagInput resolves the TagInput input
|
||||
type TagInput struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
|
||||
// Kind resolves Tag.kind
|
||||
func (r *TagResolver) Kind() string {
|
||||
return r.T.Kind
|
||||
|
||||
+4
-1
@@ -38,7 +38,10 @@ type Query {
|
||||
|
||||
# Find story by ID
|
||||
story(id: String!): Story
|
||||
|
||||
|
||||
# Find stories
|
||||
stories(input: StoriesQueryInput!): [Story!]!
|
||||
|
||||
|
||||
# Find story chapter by ID
|
||||
chapter(id: String!): Chapter
|
||||
|
||||
@@ -35,6 +35,23 @@ type Story {
|
||||
fictionalDate: String!
|
||||
}
|
||||
|
||||
input StoriesQueryInput {
|
||||
# What author to query for
|
||||
author: String
|
||||
|
||||
# What tags to query for
|
||||
tags: [TagInput!]
|
||||
|
||||
# The earliest fictionalDate
|
||||
earliestFictionalDate: String
|
||||
|
||||
# The latest fictionalDate
|
||||
latestFictionalDate: String
|
||||
|
||||
# The max amount of stories to get (default: 30)
|
||||
limit: Int
|
||||
}
|
||||
|
||||
# Possible values for Story.category
|
||||
enum StoryCategory {
|
||||
# Description and content of a document or item
|
||||
|
||||
Reference in New Issue
Block a user