Browse Source

Renamed input parameter in stories and logs to filter, made filter optional for stories query

1.0
Gisle Aune 7 years ago
parent
commit
ba49b1fd30
  1. 29
      resolver/log.go
  2. 24
      resolver/story.go
  3. 10
      schema/root.graphql
  4. 4
      schema/types/log.graphql
  5. 3
      schema/types/story.graphql

29
resolver/log.go

@ -46,7 +46,7 @@ func (r *QueryResolver) Log(ctx context.Context, args *LogArgs) (*LogResolver, e
// LogQueryArgs is args for the logs query
type LogQueryArgs struct {
Input *struct {
Filter *struct {
Search *string
Characters *[]string
Channels *[]string
@ -61,41 +61,40 @@ func (r *QueryResolver) Logs(ctx context.Context, args *LogQueryArgs) ([]*LogRes
var logs []log.Log
var err error
input := args.Input
filter := args.Filter
if input != nil {
// Parse input
if filter != nil {
limit := 100
search := ""
if input.Search != nil {
search = *input.Search
if filter.Search != nil {
search = *filter.Search
limit = 0
}
channels := []string(nil)
if input.Channels != nil {
channels = *input.Channels
if filter.Channels != nil {
channels = *filter.Channels
limit = 0
}
characters := []string(nil)
if input.Characters != nil {
characters = *input.Characters
if filter.Characters != nil {
characters = *filter.Characters
limit = 0
}
events := []string(nil)
if input.Events != nil {
events = *input.Events
if filter.Events != nil {
events = *filter.Events
limit = 0
}
if input.Limit != nil {
limit = int(*input.Limit)
if filter.Limit != nil {
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)
if err != nil {

24
resolver/story.go

@ -29,7 +29,7 @@ func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*StoryResol
// StoriesArg is args for stories query
type StoriesArg struct {
Input *struct {
Filter *struct {
Author *string
Tags *[]TagInput
EarliestFictionalDate *string
@ -40,16 +40,16 @@ type StoriesArg struct {
// Stories implements the stories query
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*StoryResolver, error) {
input := args.Input
filter := args.Filter
author := ""
if input.Author != nil {
author = *input.Author
if filter != nil && filter.Author != nil {
author = *filter.Author
}
tags := make([]story.Tag, 0, 8)
if input.Tags != nil {
for _, tagInput := range *input.Tags {
if filter != nil && filter.Tags != nil {
for _, tagInput := range *filter.Tags {
tags = append(tags, story.Tag{
Kind: tagInput.Kind,
Name: tagInput.Name,
@ -59,24 +59,24 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*Story
earliest := time.Time{}
err := error(nil)
if input.EarliestFictionalDate != nil {
earliest, err = time.Parse(time.RFC3339Nano, *input.EarliestFictionalDate)
if filter != nil && filter.EarliestFictionalDate != nil {
earliest, err = time.Parse(time.RFC3339Nano, *filter.EarliestFictionalDate)
if err != nil {
return nil, err
}
}
latest := time.Time{}
if input.LatestFictionalDate != nil {
latest, err = time.Parse(time.RFC3339Nano, *input.LatestFictionalDate)
if filter != nil && filter.LatestFictionalDate != nil {
latest, err = time.Parse(time.RFC3339Nano, *filter.LatestFictionalDate)
if err != nil {
return nil, err
}
}
limit := 30
if input.Limit != nil {
limit = int(*input.Limit)
if filter != nil && filter.Limit != nil {
limit = int(*filter.Limit)
}
stories, err := story.List(author, tags, earliest, latest, limit)

10
schema/root.graphql

@ -17,15 +17,15 @@ type Query {
# Find log by ID
log(id: String): Log
# Find logs by a list of IDs
logs(input: LogQueryInput): [LogHeader!]!
# Find logs
logs(filter: LogsFilter): [LogHeader!]!
# Find post by ID
# Find post by ID.
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
# 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!]!
@ -40,7 +40,7 @@ type Query {
story(id: String!): Story
# Find stories
stories(input: StoriesQueryInput!): [Story!]!
stories(filter: StoriesFilter): [Story!]!
# Find story chapter by ID

4
schema/types/log.graphql

@ -36,8 +36,8 @@ type Log {
posts(kinds:[String!]): [Post!]!
}
# Input for logs query
input LogQueryInput {
# Filter for logs query
input LogsFilter {
# Channels to limit results to (inclusive)
channels: [String!]

3
schema/types/story.graphql

@ -35,7 +35,8 @@ type Story {
updatedDate: String!
}
input StoriesQueryInput {
# Filter for stories query.
input StoriesFilter {
# What author to query for
author: String

Loading…
Cancel
Save