GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

49 lines
992 B

package queries
import (
"context"
"errors"
"git.aiterp.net/rpdata/api/graphql/loader"
"git.aiterp.net/rpdata/api/graphql/resolver/types"
"git.aiterp.net/rpdata/api/model/log"
)
// LogsArgs is args for the logs query
type LogsArgs struct {
Filter *log.Filter
}
// Logs resolves the logs query
func (r *QueryResolver) Logs(ctx context.Context, args *LogsArgs) ([]*types.LogResolver, error) {
var logs []log.Log
filter := args.Filter
if filter == nil {
filter = log.NewFilter().WithLimit(100)
}
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.Channel)
}
}
resolvers := make([]*types.LogResolver, len(logs))
for i := range logs {
resolvers[i] = &types.LogResolver{L: logs[i]}
}
return resolvers, nil
}