Renamed input parameter in stories and logs to filter, made filter optional for stories query
This commit is contained in:
+14
-15
@@ -46,7 +46,7 @@ func (r *QueryResolver) Log(ctx context.Context, args *LogArgs) (*LogResolver, e
|
|||||||
|
|
||||||
// LogQueryArgs is args for the logs query
|
// LogQueryArgs is args for the logs query
|
||||||
type LogQueryArgs struct {
|
type LogQueryArgs struct {
|
||||||
Input *struct {
|
Filter *struct {
|
||||||
Search *string
|
Search *string
|
||||||
Characters *[]string
|
Characters *[]string
|
||||||
Channels *[]string
|
Channels *[]string
|
||||||
@@ -61,41 +61,40 @@ func (r *QueryResolver) Logs(ctx context.Context, args *LogQueryArgs) ([]*LogRes
|
|||||||
var logs []log.Log
|
var logs []log.Log
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
input := args.Input
|
filter := args.Filter
|
||||||
|
|
||||||
if input != nil {
|
if filter != nil {
|
||||||
// Parse input
|
|
||||||
limit := 100
|
limit := 100
|
||||||
search := ""
|
search := ""
|
||||||
|
|
||||||
if input.Search != nil {
|
if filter.Search != nil {
|
||||||
search = *input.Search
|
search = *filter.Search
|
||||||
limit = 0
|
limit = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
channels := []string(nil)
|
channels := []string(nil)
|
||||||
if input.Channels != nil {
|
if filter.Channels != nil {
|
||||||
channels = *input.Channels
|
channels = *filter.Channels
|
||||||
limit = 0
|
limit = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
characters := []string(nil)
|
characters := []string(nil)
|
||||||
if input.Characters != nil {
|
if filter.Characters != nil {
|
||||||
characters = *input.Characters
|
characters = *filter.Characters
|
||||||
limit = 0
|
limit = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
events := []string(nil)
|
events := []string(nil)
|
||||||
if input.Events != nil {
|
if filter.Events != nil {
|
||||||
events = *input.Events
|
events = *filter.Events
|
||||||
limit = 0
|
limit = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.Limit != nil {
|
if filter.Limit != nil {
|
||||||
limit = int(*input.Limit)
|
limit = int(*filter.Limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
open := input.Open != nil && *input.Open == true
|
open := filter.Open != nil && *filter.Open == true
|
||||||
|
|
||||||
logs, err = log.ListSearch(search, channels, characters, events, open, limit)
|
logs, err = log.ListSearch(search, channels, characters, events, open, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+12
-12
@@ -29,7 +29,7 @@ func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*StoryResol
|
|||||||
|
|
||||||
// StoriesArg is args for stories query
|
// StoriesArg is args for stories query
|
||||||
type StoriesArg struct {
|
type StoriesArg struct {
|
||||||
Input *struct {
|
Filter *struct {
|
||||||
Author *string
|
Author *string
|
||||||
Tags *[]TagInput
|
Tags *[]TagInput
|
||||||
EarliestFictionalDate *string
|
EarliestFictionalDate *string
|
||||||
@@ -40,16 +40,16 @@ type StoriesArg struct {
|
|||||||
|
|
||||||
// Stories implements the stories query
|
// Stories implements the stories query
|
||||||
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*StoryResolver, error) {
|
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*StoryResolver, error) {
|
||||||
input := args.Input
|
filter := args.Filter
|
||||||
|
|
||||||
author := ""
|
author := ""
|
||||||
if input.Author != nil {
|
if filter != nil && filter.Author != nil {
|
||||||
author = *input.Author
|
author = *filter.Author
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := make([]story.Tag, 0, 8)
|
tags := make([]story.Tag, 0, 8)
|
||||||
if input.Tags != nil {
|
if filter != nil && filter.Tags != nil {
|
||||||
for _, tagInput := range *input.Tags {
|
for _, tagInput := range *filter.Tags {
|
||||||
tags = append(tags, story.Tag{
|
tags = append(tags, story.Tag{
|
||||||
Kind: tagInput.Kind,
|
Kind: tagInput.Kind,
|
||||||
Name: tagInput.Name,
|
Name: tagInput.Name,
|
||||||
@@ -59,24 +59,24 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*Story
|
|||||||
|
|
||||||
earliest := time.Time{}
|
earliest := time.Time{}
|
||||||
err := error(nil)
|
err := error(nil)
|
||||||
if input.EarliestFictionalDate != nil {
|
if filter != nil && filter.EarliestFictionalDate != nil {
|
||||||
earliest, err = time.Parse(time.RFC3339Nano, *input.EarliestFictionalDate)
|
earliest, err = time.Parse(time.RFC3339Nano, *filter.EarliestFictionalDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
latest := time.Time{}
|
latest := time.Time{}
|
||||||
if input.LatestFictionalDate != nil {
|
if filter != nil && filter.LatestFictionalDate != nil {
|
||||||
latest, err = time.Parse(time.RFC3339Nano, *input.LatestFictionalDate)
|
latest, err = time.Parse(time.RFC3339Nano, *filter.LatestFictionalDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
limit := 30
|
limit := 30
|
||||||
if input.Limit != nil {
|
if filter != nil && filter.Limit != nil {
|
||||||
limit = int(*input.Limit)
|
limit = int(*filter.Limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
stories, err := story.List(author, tags, earliest, latest, limit)
|
stories, err := story.List(author, tags, earliest, latest, limit)
|
||||||
|
|||||||
+5
-5
@@ -17,15 +17,15 @@ type Query {
|
|||||||
# Find log by ID
|
# Find log by ID
|
||||||
log(id: String): Log
|
log(id: String): Log
|
||||||
|
|
||||||
# Find logs by a list of IDs
|
# Find logs
|
||||||
logs(input: LogQueryInput): [LogHeader!]!
|
logs(filter: LogsFilter): [LogHeader!]!
|
||||||
|
|
||||||
|
|
||||||
# Find post by ID
|
# Find post by ID.
|
||||||
post(id: String!): Post
|
post(id: String!): Post
|
||||||
|
|
||||||
# Find posts by IDs. It's meant to allow other parts of the UI to link to a cluster of posts, e.g. for a room description for the
|
# Find posts by IDs. It's meant to allow other parts of the UI to link to a cluster of posts, e.g. for a room description for the
|
||||||
# Mapp should it ever become a thing.
|
# Mapp should it ever become a thing. This does not have a filter, since it's meant to be queried in the logs' response's selection set.
|
||||||
posts(ids: [String!]!): [Post!]!
|
posts(ids: [String!]!): [Post!]!
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ type Query {
|
|||||||
story(id: String!): Story
|
story(id: String!): Story
|
||||||
|
|
||||||
# Find stories
|
# Find stories
|
||||||
stories(input: StoriesQueryInput!): [Story!]!
|
stories(filter: StoriesFilter): [Story!]!
|
||||||
|
|
||||||
|
|
||||||
# Find story chapter by ID
|
# Find story chapter by ID
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ type Log {
|
|||||||
posts(kinds:[String!]): [Post!]!
|
posts(kinds:[String!]): [Post!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
# Input for logs query
|
# Filter for logs query
|
||||||
input LogQueryInput {
|
input LogsFilter {
|
||||||
# Channels to limit results to (inclusive)
|
# Channels to limit results to (inclusive)
|
||||||
channels: [String!]
|
channels: [String!]
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ type Story {
|
|||||||
updatedDate: String!
|
updatedDate: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
input StoriesQueryInput {
|
# Filter for stories query.
|
||||||
|
input StoriesFilter {
|
||||||
# What author to query for
|
# What author to query for
|
||||||
author: String
|
author: String
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user