Browse Source
Moved LogResolver and PostResolver into resolvers/types package, updated references to it.
1.0
Moved LogResolver and PostResolver into resolvers/types package, updated references to it.
1.0
Gisle Aune
7 years ago
4 changed files with 187 additions and 171 deletions
@ -0,0 +1,117 @@ |
|||
package types |
|||
|
|||
import ( |
|||
"context" |
|||
"errors" |
|||
"time" |
|||
|
|||
"git.aiterp.net/rpdata/api/loader" |
|||
"git.aiterp.net/rpdata/api/model/log" |
|||
) |
|||
|
|||
// LogResolver for the Log graphql type
|
|||
type LogResolver struct{ L log.Log } |
|||
|
|||
// ID resolves Log.id
|
|||
func (r *LogResolver) ID() string { |
|||
return r.L.ID |
|||
} |
|||
|
|||
// ShortID resolves Log.shortId
|
|||
func (r *LogResolver) ShortID() string { |
|||
return r.L.ShortID |
|||
} |
|||
|
|||
// Date resolves Log.date
|
|||
func (r *LogResolver) Date() string { |
|||
return r.L.Date.Format(time.RFC3339Nano) |
|||
} |
|||
|
|||
// ChannelName resolves Log.channelName
|
|||
func (r *LogResolver) ChannelName() string { |
|||
return r.L.Channel |
|||
} |
|||
|
|||
// Channel resolves Log.channe
|
|||
func (r *LogResolver) Channel(ctx context.Context) (*ChannelResolver, error) { |
|||
loader := loader.FromContext(ctx) |
|||
if loader == nil { |
|||
return nil, errors.New("no loader") |
|||
} |
|||
|
|||
channel, err := loader.Channel("name", r.L.Channel) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
|
|||
return &ChannelResolver{C: channel}, nil |
|||
} |
|||
|
|||
// Title resolves Log.title
|
|||
func (r *LogResolver) Title() string { |
|||
return r.L.Title |
|||
} |
|||
|
|||
// Event resolves Log.event
|
|||
func (r *LogResolver) Event() string { |
|||
return r.L.Event |
|||
} |
|||
|
|||
// Description resolves Log.description
|
|||
func (r *LogResolver) Description() string { |
|||
return r.L.Description |
|||
} |
|||
|
|||
// Open resolves Log.open
|
|||
func (r *LogResolver) Open() bool { |
|||
return r.L.Open |
|||
} |
|||
|
|||
// Characters resolves Log.characters
|
|||
func (r *LogResolver) Characters(ctx context.Context) ([]*CharacterResolver, error) { |
|||
loader := loader.FromContext(ctx) |
|||
if loader == nil { |
|||
return nil, errors.New("no loader") |
|||
} |
|||
|
|||
chars, err := loader.Characters("id", r.L.CharacterIDs...) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
|
|||
resolvers := make([]*CharacterResolver, 0, len(chars)) |
|||
for i := range chars { |
|||
if chars[i].ID == "" { |
|||
continue |
|||
} |
|||
|
|||
resolvers = append(resolvers, &CharacterResolver{C: chars[i]}) |
|||
} |
|||
|
|||
return resolvers, nil |
|||
} |
|||
|
|||
// Posts resolves Log.posts
|
|||
func (r *LogResolver) Posts(ctx context.Context, args *LogPostArgs) ([]*PostResolver, error) { |
|||
var kinds []string |
|||
if args.Kinds != nil { |
|||
kinds = *args.Kinds |
|||
} |
|||
|
|||
posts, err := r.L.Posts(kinds...) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
|
|||
resolvers := make([]*PostResolver, len(posts)) |
|||
for i := range posts { |
|||
resolvers[i] = &PostResolver{posts[i]} |
|||
} |
|||
|
|||
return resolvers, nil |
|||
} |
|||
|
|||
// LogPostArgs is an arg
|
|||
type LogPostArgs struct { |
|||
Kinds *[]string |
|||
} |
@ -0,0 +1,45 @@ |
|||
package types |
|||
|
|||
import ( |
|||
"time" |
|||
|
|||
"git.aiterp.net/rpdata/api/model/log" |
|||
) |
|||
|
|||
// PostResolver for the Post graphql type
|
|||
type PostResolver struct{ P log.Post } |
|||
|
|||
// ID resolves Post.id
|
|||
func (r *PostResolver) ID() string { |
|||
return r.P.ID |
|||
} |
|||
|
|||
// LogID resolves Post.logId
|
|||
func (r *PostResolver) LogID() string { |
|||
return r.P.LogID |
|||
} |
|||
|
|||
// Time resolves Post.time
|
|||
func (r *PostResolver) Time() string { |
|||
return r.P.Time.Format(time.RFC3339Nano) |
|||
} |
|||
|
|||
// Kind resolves Post.logId
|
|||
func (r *PostResolver) Kind() string { |
|||
return r.P.Kind |
|||
} |
|||
|
|||
// Nick resolves Post.nick
|
|||
func (r *PostResolver) Nick() string { |
|||
return r.P.Nick |
|||
} |
|||
|
|||
// Text resolves Post.text
|
|||
func (r *PostResolver) Text() string { |
|||
return r.P.Text |
|||
} |
|||
|
|||
// Position resolves Post.text
|
|||
func (r *PostResolver) Position() int32 { |
|||
return int32(r.P.Position) |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue