Browse Source

Updated resolvers to be compatible with gqlgen 0.9

thegreatrefactor
Gisle Aune 6 years ago
parent
commit
015bdfd2e8
  1. 6
      go.mod
  2. 6
      go.sum
  3. 23
      graph2/queries/changes.go
  4. 14
      graph2/queries/channel.go
  5. 14
      graph2/queries/character.go
  6. 14
      graph2/queries/file.go
  7. 15
      graph2/queries/log.go
  8. 23
      graph2/queries/post.go
  9. 25
      graph2/queries/story.go
  10. 14
      graph2/queries/tags.go
  11. 14
      graph2/queries/unknownnicks.go
  12. 14
      graph2/types/chapter.go
  13. 32
      graph2/types/log.go
  14. 14
      graph2/types/story.go

6
go.mod

@ -3,7 +3,7 @@ module git.aiterp.net/rpdata/api
go 1.12 go 1.12
require ( require (
github.com/99designs/gqlgen v0.8.0
github.com/99designs/gqlgen v0.9.0
github.com/agnivade/levenshtein v1.0.1 github.com/agnivade/levenshtein v1.0.1
github.com/beorn7/perks v1.0.0 // indirect github.com/beorn7/perks v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew v1.1.1
@ -29,12 +29,12 @@ require (
github.com/sirupsen/logrus v1.2.0 github.com/sirupsen/logrus v1.2.0
github.com/stretchr/testify v1.3.0 github.com/stretchr/testify v1.3.0
github.com/urfave/cli v1.20.0 github.com/urfave/cli v1.20.0
github.com/vektah/gqlparser v1.1.0
github.com/vektah/gqlparser v1.1.2
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/net v0.0.0-20190514140710-3ec191127204 golang.org/x/net v0.0.0-20190514140710-3ec191127204
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
golang.org/x/text v0.3.0 golang.org/x/text v0.3.0
golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6
golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd
google.golang.org/appengine v1.1.0 google.golang.org/appengine v1.1.0
gopkg.in/yaml.v2 v2.2.2 gopkg.in/yaml.v2 v2.2.2
) )

6
go.sum

@ -4,6 +4,8 @@ github.com/99designs/gqlgen v0.8.0 h1:ZBteuSgeeFwn+mztjDqQZQdVa9pqslmPnDeCovcnc0
github.com/99designs/gqlgen v0.8.0/go.mod h1:st7qHA6ssU3uRZkmv+wzrzgX4srvIqEIdE5iuRW8GhE= github.com/99designs/gqlgen v0.8.0/go.mod h1:st7qHA6ssU3uRZkmv+wzrzgX4srvIqEIdE5iuRW8GhE=
github.com/99designs/gqlgen v0.8.3 h1:I6bMglXNKkn4KlvkSMzqZw53e1N2FF9Gud4NmsOxqiA= github.com/99designs/gqlgen v0.8.3 h1:I6bMglXNKkn4KlvkSMzqZw53e1N2FF9Gud4NmsOxqiA=
github.com/99designs/gqlgen v0.8.3/go.mod h1:aLyJw9xUgdJxZ8EqNQxo2pGFhXXJ/hq8t7J4yn8TgI4= github.com/99designs/gqlgen v0.8.3/go.mod h1:aLyJw9xUgdJxZ8EqNQxo2pGFhXXJ/hq8t7J4yn8TgI4=
github.com/99designs/gqlgen v0.9.0 h1:g1arBPML74Vqv0L3Q+TqIhGXLspV+2MYtRLkBxuZrlE=
github.com/99designs/gqlgen v0.9.0/go.mod h1:HrrG7ic9EgLPsULxsZh/Ti+p0HNWgR3XRuvnD0pb5KY=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/agnivade/levenshtein v1.0.0 h1:q+77q31bLT5jhN3BHKA1276nUEdbz7XjDa0o5dRKcZ0= github.com/agnivade/levenshtein v1.0.0 h1:q+77q31bLT5jhN3BHKA1276nUEdbz7XjDa0o5dRKcZ0=
github.com/agnivade/levenshtein v1.0.0/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/agnivade/levenshtein v1.0.0/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
@ -103,6 +105,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/vektah/dataloaden v0.2.0/go.mod h1:vxM6NuRlgiR0M6wbVTJeKp9vQIs81ZMfCYO+4yq/jbE= github.com/vektah/dataloaden v0.2.0/go.mod h1:vxM6NuRlgiR0M6wbVTJeKp9vQIs81ZMfCYO+4yq/jbE=
github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e/go.mod h1:/HUdMve7rvxZma+2ZELQeNh88+003LL7Pf/CZ089j8U=
github.com/vektah/gqlparser v0.0.0-20180831041411-14e83ae06ec1 h1:FYOXUtr3sYR9shto7Q/aQ1B0Onyk77aws9wGOORiz+I= github.com/vektah/gqlparser v0.0.0-20180831041411-14e83ae06ec1 h1:FYOXUtr3sYR9shto7Q/aQ1B0Onyk77aws9wGOORiz+I=
github.com/vektah/gqlparser v0.0.0-20180831041411-14e83ae06ec1/go.mod h1:K4QdSSpS2XiHHwzb18kWh3iBljB8rLC8okGXsnQy3Nc= github.com/vektah/gqlparser v0.0.0-20180831041411-14e83ae06ec1/go.mod h1:K4QdSSpS2XiHHwzb18kWh3iBljB8rLC8okGXsnQy3Nc=
github.com/vektah/gqlparser v1.1.0 h1:3668p2gUlO+PiS81x957Rpr3/FPRWG6cxgCXAvTS1hw= github.com/vektah/gqlparser v1.1.0 h1:3668p2gUlO+PiS81x957Rpr3/FPRWG6cxgCXAvTS1hw=
@ -124,6 +127,7 @@ golang.org/x/net v0.0.0-20190514140710-3ec191127204 h1:4yG6GqBtw9C+UrLp6s2wtSnia
golang.org/x/net v0.0.0-20190514140710-3ec191127204/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190514140710-3ec191127204/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180416112224-2f57af4873d0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180416112224-2f57af4873d0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -137,6 +141,8 @@ golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1 h1:dzEuQYa6+a3gROnSlgly5ER
golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6 h1:iZgcI2DDp6zW5v9Z/5+f0NuqoxNdmzg4hivjk2WLXpY= golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6 h1:iZgcI2DDp6zW5v9Z/5+f0NuqoxNdmzg4hivjk2WLXpY=
golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd h1:oMEQDWVXVNpceQoVd1JN3CQ7LYJJzs5qWqZIUcxXHHw=
golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

23
graph2/queries/changes.go

@ -10,16 +10,31 @@ import (
/// Queries /// Queries
func (r *resolver) Changes(ctx context.Context, filter *changes.Filter) ([]models.Change, error) {
return changes.List(filter)
func (r *resolver) Changes(ctx context.Context, filter *changes.Filter) ([]*models.Change, error) {
changes, err := changes.List(filter)
if err != nil {
return nil, err
}
changes2 := make([]*models.Change, len(changes))
for i, change := range changes {
changes2[i] = &change
}
return changes2, nil
} }
/// Subscriptions /// Subscriptions
func (r *subscriptionResolver) Changes(ctx context.Context, keys []models.ChangeKey) (<-chan *models.Change, error) {
func (r *subscriptionResolver) Changes(ctx context.Context, keys []*models.ChangeKey) (<-chan *models.Change, error) {
if len(keys) == 0 { if len(keys) == 0 {
return nil, errors.New("At least one key is required for a subscription") return nil, errors.New("At least one key is required for a subscription")
} }
return changes.Subscribe(ctx, keys, false), nil
keys2 := make([]models.ChangeKey, len(keys))
for i := range keys {
keys2[i] = *keys[i]
}
return changes.Subscribe(ctx, keys2, false), nil
} }

14
graph2/queries/channel.go

@ -23,8 +23,18 @@ func (r *resolver) Channel(ctx context.Context, name string) (*models.Channel, e
return &channel, nil return &channel, nil
} }
func (r *resolver) Channels(ctx context.Context, filter *channels.Filter) ([]models.Channel, error) {
return channels.List(filter)
func (r *resolver) Channels(ctx context.Context, filter *channels.Filter) ([]*models.Channel, error) {
channels, err := channels.List(filter)
if err != nil {
return nil, err
}
channels2 := make([]*models.Channel, len(channels))
for i, channel := range channels {
channels2[i] = &channel
}
return channels2, nil
} }
// Mutations // Mutations

14
graph2/queries/character.go

@ -36,8 +36,18 @@ func (r *resolver) Character(ctx context.Context, id *string, nick *string) (*mo
} }
} }
func (r *resolver) Characters(ctx context.Context, filter *characters.Filter) ([]models.Character, error) {
return characters.List(filter)
func (r *resolver) Characters(ctx context.Context, filter *characters.Filter) ([]*models.Character, error) {
characters, err := characters.List(filter)
if err != nil {
return nil, err
}
characters2 := make([]*models.Character, len(characters))
for i, character := range characters {
characters2[i] = &character
}
return characters2, nil
} }
// Mutations // Mutations

14
graph2/queries/file.go

@ -17,7 +17,7 @@ func (r *resolver) File(ctx context.Context, id string) (*models.File, error) {
return &file, nil return &file, nil
} }
func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]models.File, error) {
func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]*models.File, error) {
token := auth.TokenFromContext(ctx) token := auth.TokenFromContext(ctx)
if filter == nil { if filter == nil {
@ -33,7 +33,17 @@ func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]models.Fi
filter.Public = &trueValue filter.Public = &trueValue
} }
return files.List(filter)
files, err := files.List(filter)
if err != nil {
return nil, err
}
files2 := make([]*models.File, len(files))
for i, file := range files {
files2[i] = &file
}
return files2, nil
} }
var trueValue = true var trueValue = true

15
graph2/queries/log.go

@ -29,7 +29,7 @@ func (r *resolver) Log(ctx context.Context, id string) (*models.Log, error) {
return &log, nil return &log, nil
} }
func (r *resolver) Logs(ctx context.Context, filter *logs.Filter) ([]models.Log, error) {
func (r *resolver) Logs(ctx context.Context, filter *logs.Filter) ([]*models.Log, error) {
logs, err := logs.List(filter) logs, err := logs.List(filter)
if err != nil { if err != nil {
return nil, err return nil, err
@ -56,7 +56,12 @@ func (r *resolver) Logs(ctx context.Context, filter *logs.Filter) ([]models.Log,
} }
} }
return logs, nil
logs2 := make([]*models.Log, len(logs))
for i, log := range logs {
logs2[i] = &log
}
return logs2, nil
} }
// Mutations // Mutations
@ -102,7 +107,7 @@ func (r *mutationResolver) AddLog(ctx context.Context, input input.LogAddInput)
return &log, nil return &log, nil
} }
func (r *mutationResolver) ImportLog(ctx context.Context, input input.LogImportInput) ([]models.Log, error) {
func (r *mutationResolver) ImportLog(ctx context.Context, input input.LogImportInput) ([]*models.Log, error) {
token := auth.TokenFromContext(ctx) token := auth.TokenFromContext(ctx)
if !token.Authenticated() || !token.Permitted("log.add") { if !token.Authenticated() || !token.Permitted("log.add") {
return nil, errors.New("You are not permitted to add logs") return nil, errors.New("You are not permitted to add logs")
@ -128,7 +133,7 @@ func (r *mutationResolver) ImportLog(ctx context.Context, input input.LogImportI
return nil, err return nil, err
} }
newLogs := make([]models.Log, 0, len(results))
newLogs := make([]*models.Log, 0, len(results))
for _, result := range results { for _, result := range results {
go func(result logs.ImportedLog) { go func(result logs.ImportedLog) {
changes.Submit("Log", "add", token.UserID, true, changekeys.Many(result.Log), result.Log) changes.Submit("Log", "add", token.UserID, true, changekeys.Many(result.Log), result.Log)
@ -140,7 +145,7 @@ func (r *mutationResolver) ImportLog(ctx context.Context, input input.LogImportI
log = result.Log log = result.Log
} }
newLogs = append(newLogs, log)
newLogs = append(newLogs, &log)
} }
return newLogs, nil return newLogs, nil

23
graph2/queries/post.go

@ -25,7 +25,7 @@ func (r *resolver) Post(ctx context.Context, id string) (*models.Post, error) {
return &post, nil return &post, nil
} }
func (r *resolver) Posts(ctx context.Context, filter *posts.Filter) ([]models.Post, error) {
func (r *resolver) Posts(ctx context.Context, filter *posts.Filter) ([]*models.Post, error) {
// Some sanity checks to avoid querying an insame amount of posts. // Some sanity checks to avoid querying an insame amount of posts.
if filter == nil { if filter == nil {
filter = &posts.Filter{Limit: 256} filter = &posts.Filter{Limit: 256}
@ -43,7 +43,17 @@ func (r *resolver) Posts(ctx context.Context, filter *posts.Filter) ([]models.Po
} }
} }
return posts.List(filter)
posts, err := posts.List(filter)
if err != nil {
return nil, err
}
posts2 := make([]*models.Post, len(posts))
for i, post := range posts {
posts2[i] = &post
}
return posts2, nil
} }
// Mutation // Mutation
@ -109,7 +119,7 @@ func (r *mutationResolver) EditPost(ctx context.Context, input input.PostEditInp
return &post, nil return &post, nil
} }
func (r *mutationResolver) MovePost(ctx context.Context, input input.PostMoveInput) ([]models.Post, error) {
func (r *mutationResolver) MovePost(ctx context.Context, input input.PostMoveInput) ([]*models.Post, error) {
token := auth.TokenFromContext(ctx) token := auth.TokenFromContext(ctx)
if !token.Authenticated() || !token.Permitted("post.move") { if !token.Authenticated() || !token.Permitted("post.move") {
return nil, errors.New("You are not permitted to edit logs") return nil, errors.New("You are not permitted to edit logs")
@ -134,7 +144,12 @@ func (r *mutationResolver) MovePost(ctx context.Context, input input.PostMoveInp
changes.Submit("Post", "move", token.UserID, true, changekeys.Many(log, posts), posts) changes.Submit("Post", "move", token.UserID, true, changekeys.Many(log, posts), posts)
}() }()
return posts, nil
posts2 := make([]*models.Post, len(posts))
for i, post := range posts {
posts2[i] = &post
}
return posts2, nil
} }
func (r *mutationResolver) RemovePost(ctx context.Context, input input.PostRemoveInput) (*models.Post, error) { func (r *mutationResolver) RemovePost(ctx context.Context, input input.PostRemoveInput) (*models.Post, error) {

25
graph2/queries/story.go

@ -24,7 +24,7 @@ func (r *resolver) Story(ctx context.Context, id string) (*models.Story, error)
return &story, nil return &story, nil
} }
func (r *resolver) Stories(ctx context.Context, filter *stories.Filter) ([]models.Story, error) {
func (r *resolver) Stories(ctx context.Context, filter *stories.Filter) ([]*models.Story, error) {
if filter != nil { if filter != nil {
if filter.Unlisted != nil && *filter.Unlisted == true { if filter.Unlisted != nil && *filter.Unlisted == true {
token := auth.TokenFromContext(ctx) token := auth.TokenFromContext(ctx)
@ -38,7 +38,17 @@ func (r *resolver) Stories(ctx context.Context, filter *stories.Filter) ([]model
} }
} }
return stories.List(filter)
stories, err := stories.List(filter)
if err != nil {
return nil, err
}
stories2 := make([]*models.Story, len(stories))
for i, story := range stories {
stories2[i] = &story
}
return stories2, nil
} }
// Mutations // Mutations
@ -66,7 +76,12 @@ func (r *mutationResolver) AddStory(ctx context.Context, input input.StoryAddInp
listed := input.Listed != nil && *input.Listed listed := input.Listed != nil && *input.Listed
open := input.Open != nil && *input.Open open := input.Open != nil && *input.Open
story, err := stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate)
tags := make([]models.Tag, len(input.Tags))
for i := range input.Tags {
tags[i] = *input.Tags[i]
}
story, err := stories.Add(input.Name, author, input.Category, listed, open, tags, time.Now(), fictionalDate)
if err != nil { if err != nil {
return nil, errors.New("Failed to add story: " + err.Error()) return nil, errors.New("Failed to add story: " + err.Error())
} }
@ -94,7 +109,7 @@ func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTag
} }
} }
story, err = stories.AddTag(story, input.Tag)
story, err = stories.AddTag(story, *input.Tag)
if err != nil { if err != nil {
return nil, errors.New("Failed to add story: " + err.Error()) return nil, errors.New("Failed to add story: " + err.Error())
} }
@ -122,7 +137,7 @@ func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.Story
} }
} }
story, err = stories.RemoveTag(story, input.Tag)
story, err = stories.RemoveTag(story, *input.Tag)
if err != nil { if err != nil {
return nil, errors.New("Failed to add story: " + err.Error()) return nil, errors.New("Failed to add story: " + err.Error())
} }

14
graph2/queries/tags.go

@ -7,6 +7,16 @@ import (
"git.aiterp.net/rpdata/api/models/tags" "git.aiterp.net/rpdata/api/models/tags"
) )
func (r *resolver) Tags(ctx context.Context) ([]models.Tag, error) {
return tags.List()
func (r *resolver) Tags(ctx context.Context) ([]*models.Tag, error) {
tags, err := tags.List()
if err != nil {
return nil, err
}
tags2 := make([]*models.Tag, len(tags))
for i, tag := range tags {
tags2[i] = &tag
}
return tags2, nil
} }

14
graph2/queries/unknownnicks.go

@ -11,7 +11,7 @@ import (
/// Queries /// Queries
func (r *resolver) UnknownNicks(ctx context.Context, filter *input.UnknownNicksFilter) ([]models.UnknownNick, error) {
func (r *resolver) UnknownNicks(ctx context.Context, filter *input.UnknownNicksFilter) ([]*models.UnknownNick, error) {
limit := 100 limit := 100
if filter != nil { if filter != nil {
if filter.Limit > 0 { if filter.Limit > 0 {
@ -19,5 +19,15 @@ func (r *resolver) UnknownNicks(ctx context.Context, filter *input.UnknownNicksF
} }
} }
return unknownnicks.List(limit)
nicks, err := unknownnicks.List(limit)
if err != nil {
return nil, err
}
nicks2 := make([]*models.UnknownNick, len(nicks))
for i, nick := range nicks {
nicks2[i] = &nick
}
return nicks2, nil
} }

14
graph2/types/chapter.go

@ -19,7 +19,7 @@ func (r *chapterResolver) FictionalDate(ctx context.Context, chapter *models.Cha
return &chapter.FictionalDate, nil return &chapter.FictionalDate, nil
} }
func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter, limit *int) ([]models.Comment, error) {
func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter, limit *int) ([]*models.Comment, error) {
limitValue := 0 limitValue := 0
if limit != nil { if limit != nil {
if *limit < 0 { if *limit < 0 {
@ -33,7 +33,17 @@ func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter,
return nil, nil return nil, nil
} }
return comments.ListChapterID(chapter.ID, limitValue)
comments, err := comments.ListChapterID(chapter.ID, limitValue)
if err != nil {
return nil, err
}
comments2 := make([]*models.Comment, len(comments))
for i, comment := range comments {
comments2[i] = &comment
}
return comments2, nil
} }
// ChapterResolver is a resolver // ChapterResolver is a resolver

32
graph2/types/log.go

@ -20,21 +20,37 @@ func (r *logResolver) Channel(ctx context.Context, log *models.Log) (*models.Cha
return loader.Channel("name", log.ChannelName) return loader.Channel("name", log.ChannelName)
} }
func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]models.Character, error) {
func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]*models.Character, error) {
loader := loader.FromContext(ctx) loader := loader.FromContext(ctx)
if loader == nil { if loader == nil {
return nil, errors.New("no loader") return nil, errors.New("no loader")
} }
return loader.Characters("id", log.CharacterIDs...)
characters, err := loader.Characters("id", log.CharacterIDs...)
if err != nil {
return nil, err
}
characters2 := make([]*models.Character, len(characters))
for i, character := range characters {
characters2[i] = &character
}
return characters2, nil
} }
func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]models.Post, error) {
return posts.List(&posts.Filter{
LogID: &log.ShortID,
Kind: kinds,
Limit: 0,
})
func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]*models.Post, error) {
posts, err := posts.List(&posts.Filter{LogID: &log.ShortID, Kind: kinds, Limit: 0})
if err != nil {
return nil, err
}
posts2 := make([]*models.Post, len(posts))
for i, post := range posts {
posts2[i] = &post
}
return posts2, nil
} }
// LogResolver is a resolver // LogResolver is a resolver

14
graph2/types/story.go

@ -19,8 +19,18 @@ func (r *storyResolver) FictionalDate(ctx context.Context, story *models.Story)
return &story.FictionalDate, nil return &story.FictionalDate, nil
} }
func (r *storyResolver) Chapters(ctx context.Context, story *models.Story) ([]models.Chapter, error) {
return chapters.ListStoryID(story.ID)
func (r *storyResolver) Chapters(ctx context.Context, story *models.Story) ([]*models.Chapter, error) {
chapters, err := chapters.ListStoryID(story.ID)
if err != nil {
return nil, err
}
chapters2 := make([]*models.Chapter, len(chapters))
for i, chapter := range chapters {
chapters2[i] = &chapter
}
return chapters2, nil
} }
// StoryResolver is a resolver // StoryResolver is a resolver

Loading…
Cancel
Save