graph2: Added Log type and queries, moved loader out of old graphql pkg.
the build failed

This commit is contained in:
2018-09-15 13:14:05 +02:00
parent 0444911e73
commit 2b05d90f4a
10 changed files with 215 additions and 66 deletions
+4
View File
@@ -23,5 +23,9 @@ models:
model: git.aiterp.net/rpdata/api/model/channel.Filter
Post:
model: git.aiterp.net/rpdata/api/model/log.Post
Log:
model: git.aiterp.net/rpdata/api/model/log.Log
LogsFilter:
model: git.aiterp.net/rpdata/api/model/log.Filter
Date:
model: git.aiterp.net/rpdata/api/model/scalars.Date
+34
View File
@@ -0,0 +1,34 @@
package queries
import (
"context"
"errors"
"git.aiterp.net/rpdata/api/internal/loader"
"git.aiterp.net/rpdata/api/model/log"
)
func (r *resolver) Log(ctx context.Context, id string) (log.Log, error) {
return log.FindID(id)
}
func (r *resolver) Logs(ctx context.Context, filter *log.Filter) ([]log.Log, error) {
logs, err := log.List(filter)
if err != nil {
return nil, err
}
if len(logs) >= 100 {
loader := loader.FromContext(ctx)
if loader == nil {
return nil, errors.New("no loader")
}
for _, log := range logs {
loader.PrimeCharacters("id", log.CharacterIDs...)
loader.PrimeChannels("name", log.ChannelName)
}
}
return logs, nil
}
+8
View File
@@ -25,9 +25,17 @@ type Query {
posts(ids: [String!]!): [Post!]!
# Find log by ID
log(id: String!): Log!
# Find logs
logs(filter: LogsFilter): [Log!]!
# Find all distinct tags used in stories
tags: [Tag!]!
}
# A Date represents a RFC3339 encoded date with up to millisecond precision.
scalar Date
+97
View File
@@ -0,0 +1,97 @@
# A Log is the "file" of an RP session
type Log {
# A unique identifier for the log.
id: String!
# A secondary unique identifier for the log. This is a lot shorter and more suitable for storage when
# the link doesn't need to be as expressive.
shortId: String!
# The date for a log.
date: Date!
# The channel of a log.
channelName: String!
# Information about the channel this log is in.
channel: Channel!
# The session's title.
title: String!
# The log's event, which is the same as the tags in the previous logbot site.
# Empty string means that it's no event.
event: String!
# The description of a session, which is empty if unset.
description: String!
# Whether the log session is open.
open: Boolean!
# The characters involved in the log file.
characters: [Character!]!
# The posts of the logfile, which can be filtered by kinds.
posts(kinds:[String!]): [Post!]!
}
# Filter for logs query
input LogsFilter {
# Channels to limit results to (inclusive)
channels: [String!]
# Events to limit results to (inclusive)
events: [String!]
# Characters to limit results to (exclusive)
characters: [String!]
# Search post content
search: String
# Limit by whether it's open or not
open: Boolean
# Limit the amount of results you get back
limit: Int
}
# Input for addLog mutation
input LogAddInput {
# The date of the log.
date: Date!
# The channel where the log is set
channel: String!
# Optional: The log title
title: String
# Optional: Whether the log is open
open: Boolean
# Optional: The log event name
event: String
# Optional: A short description of the log
description: String
}
# Input for addLog mutation
input LogEditInput {
# The id of the log
id: String!
# The log title
title: String
# The log event name
event: String
# A short description of the log
description: String
# Open/close the log
open: Boolean
}