Browse Source

Moved CharacterResolver into resolvers/types package, updated references to it.

1.0
Gisle Aune 6 years ago
parent
commit
53e2dfc6b6
  1. 73
      resolver/character.go
  2. 6
      resolver/log.go
  3. 45
      resolver/types/character.go

73
resolver/character.go

@ -10,11 +10,9 @@ import (
"git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/change"
"git.aiterp.net/rpdata/api/model/character" "git.aiterp.net/rpdata/api/model/character"
"git.aiterp.net/rpdata/api/model/log" "git.aiterp.net/rpdata/api/model/log"
"git.aiterp.net/rpdata/api/resolver/types"
) )
// CharacterResolver for the Character graphql type
type CharacterResolver struct{ C character.Character }
// CharacterArgs is an arg // CharacterArgs is an arg
type CharacterArgs struct { type CharacterArgs struct {
ID *string ID *string
@ -22,7 +20,7 @@ type CharacterArgs struct {
} }
// Character resolver // Character resolver
func (r *QueryResolver) Character(ctx context.Context, args *CharacterArgs) (*CharacterResolver, error) {
func (r *QueryResolver) Character(ctx context.Context, args *CharacterArgs) (*types.CharacterResolver, error) {
var char character.Character var char character.Character
var err error var err error
@ -44,7 +42,7 @@ func (r *QueryResolver) Character(ctx context.Context, args *CharacterArgs) (*Ch
return nil, err return nil, err
} }
return &CharacterResolver{C: char}, nil
return &types.CharacterResolver{C: char}, nil
} }
// CharactersArgs is an arg // CharactersArgs is an arg
@ -55,7 +53,7 @@ type CharactersArgs struct {
} }
// Characters resolves the characters query // Characters resolves the characters query
func (r *QueryResolver) Characters(ctx context.Context, args *CharactersArgs) ([]*CharacterResolver, error) {
func (r *QueryResolver) Characters(ctx context.Context, args *CharactersArgs) ([]*types.CharacterResolver, error) {
var chars []character.Character var chars []character.Character
var err error var err error
@ -79,13 +77,13 @@ func (r *QueryResolver) Characters(ctx context.Context, args *CharactersArgs) ([
return nil, err return nil, err
} }
resolvers := make([]*CharacterResolver, 0, len(chars))
resolvers := make([]*types.CharacterResolver, 0, len(chars))
for i := range chars { for i := range chars {
if chars[i].ID == "" { if chars[i].ID == "" {
continue continue
} }
resolvers = append(resolvers, &CharacterResolver{C: chars[i]})
resolvers = append(resolvers, &types.CharacterResolver{C: chars[i]})
} }
return resolvers, nil return resolvers, nil
@ -101,7 +99,7 @@ type AddCharacterInput struct {
} }
// AddCharacter resolves the addCharacter mutation // AddCharacter resolves the addCharacter mutation
func (r *MutationResolver) AddCharacter(ctx context.Context, args struct{ Input *AddCharacterInput }) (*CharacterResolver, error) {
func (r *MutationResolver) AddCharacter(ctx context.Context, args struct{ Input *AddCharacterInput }) (*types.CharacterResolver, error) {
input := args.Input input := args.Input
user := session.FromContext(ctx).User() user := session.FromContext(ctx).User()
if user == nil || !user.Permitted("member", "character.add") { if user == nil || !user.Permitted("member", "character.add") {
@ -146,7 +144,7 @@ func (r *MutationResolver) AddCharacter(ctx context.Context, args struct{ Input
log.ScheduleCharacterUpdate() log.ScheduleCharacterUpdate()
return &CharacterResolver{C: character}, nil
return &types.CharacterResolver{C: character}, nil
} }
// CharacterNickInput is args for mutation addCharacterNick/removeCharacterNick // CharacterNickInput is args for mutation addCharacterNick/removeCharacterNick
@ -156,7 +154,7 @@ type CharacterNickInput struct {
} }
// AddCharacterNick resolves the addCharacterNick mutation // AddCharacterNick resolves the addCharacterNick mutation
func (r *MutationResolver) AddCharacterNick(ctx context.Context, args struct{ Input *CharacterNickInput }) (*CharacterResolver, error) {
func (r *MutationResolver) AddCharacterNick(ctx context.Context, args struct{ Input *CharacterNickInput }) (*types.CharacterResolver, error) {
input := args.Input input := args.Input
user := session.FromContext(ctx).User() user := session.FromContext(ctx).User()
@ -183,11 +181,11 @@ func (r *MutationResolver) AddCharacterNick(ctx context.Context, args struct{ In
log.ScheduleCharacterUpdate() log.ScheduleCharacterUpdate()
return &CharacterResolver{C: character}, nil
return &types.CharacterResolver{C: character}, nil
} }
// RemoveCharacterNick resolves the removeCharacterNick mutation // RemoveCharacterNick resolves the removeCharacterNick mutation
func (r *MutationResolver) RemoveCharacterNick(ctx context.Context, args struct{ Input *CharacterNickInput }) (*CharacterResolver, error) {
func (r *MutationResolver) RemoveCharacterNick(ctx context.Context, args struct{ Input *CharacterNickInput }) (*types.CharacterResolver, error) {
input := args.Input input := args.Input
user := session.FromContext(ctx).User() user := session.FromContext(ctx).User()
@ -214,7 +212,7 @@ func (r *MutationResolver) RemoveCharacterNick(ctx context.Context, args struct{
log.ScheduleCharacterUpdate() log.ScheduleCharacterUpdate()
return &CharacterResolver{C: character}, nil
return &types.CharacterResolver{C: character}, nil
} }
// CharacterEditInput is args for mutation addCharacterNick/removeCharacterNick // CharacterEditInput is args for mutation addCharacterNick/removeCharacterNick
@ -226,7 +224,7 @@ type CharacterEditInput struct {
} }
// EditCharacter resolves the editCharacter mutation // EditCharacter resolves the editCharacter mutation
func (r *MutationResolver) EditCharacter(ctx context.Context, args struct{ Input *CharacterEditInput }) (*CharacterResolver, error) {
func (r *MutationResolver) EditCharacter(ctx context.Context, args struct{ Input *CharacterEditInput }) (*types.CharacterResolver, error) {
input := args.Input input := args.Input
user := session.FromContext(ctx).User() user := session.FromContext(ctx).User()
@ -268,11 +266,11 @@ func (r *MutationResolver) EditCharacter(ctx context.Context, args struct{ Input
"description": character.Description, "description": character.Description,
}) })
return &CharacterResolver{C: character}, nil
return &types.CharacterResolver{C: character}, nil
} }
// RemoveCharacter resolves the removeCharacter mutation // RemoveCharacter resolves the removeCharacter mutation
func (r *MutationResolver) RemoveCharacter(ctx context.Context, args struct{ ID string }) (*CharacterResolver, error) {
func (r *MutationResolver) RemoveCharacter(ctx context.Context, args struct{ ID string }) (*types.CharacterResolver, error) {
user := session.FromContext(ctx).User() user := session.FromContext(ctx).User()
if user == nil || !user.Permitted("member") { if user == nil || !user.Permitted("member") {
return nil, ErrUnauthorized return nil, ErrUnauthorized
@ -297,44 +295,5 @@ func (r *MutationResolver) RemoveCharacter(ctx context.Context, args struct{ ID
"nicks": character.Nicks, "nicks": character.Nicks,
}) })
return &CharacterResolver{C: character}, nil
}
// ID is a property resolver
func (r *CharacterResolver) ID() string {
return r.C.ID
}
// Nick is a property resolver
func (r *CharacterResolver) Nick() *string {
if len(r.C.Nicks) == 0 {
return nil
}
return &r.C.Nicks[0]
}
// Nicks is a property resolver
func (r *CharacterResolver) Nicks() []string {
return r.C.Nicks
}
// Name is a property resolver
func (r *CharacterResolver) Name() string {
return r.C.Name
}
// ShortName is a property resolver
func (r *CharacterResolver) ShortName() string {
return r.C.ShortName
}
// Author is a property resolver
func (r *CharacterResolver) Author() string {
return r.C.Author
}
// Description is a property resolver
func (r *CharacterResolver) Description() string {
return r.C.Description
return &types.CharacterResolver{C: character}, nil
} }

6
resolver/log.go

@ -294,7 +294,7 @@ func (r *LogResolver) Open() bool {
} }
// Characters resolves Log.characters // Characters resolves Log.characters
func (r *LogResolver) Characters(ctx context.Context) ([]*CharacterResolver, error) {
func (r *LogResolver) Characters(ctx context.Context) ([]*types.CharacterResolver, 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")
@ -305,13 +305,13 @@ func (r *LogResolver) Characters(ctx context.Context) ([]*CharacterResolver, err
return nil, err return nil, err
} }
resolvers := make([]*CharacterResolver, 0, len(chars))
resolvers := make([]*types.CharacterResolver, 0, len(chars))
for i := range chars { for i := range chars {
if chars[i].ID == "" { if chars[i].ID == "" {
continue continue
} }
resolvers = append(resolvers, &CharacterResolver{C: chars[i]})
resolvers = append(resolvers, &types.CharacterResolver{C: chars[i]})
} }
return resolvers, nil return resolvers, nil

45
resolver/types/character.go

@ -0,0 +1,45 @@
package types
import "git.aiterp.net/rpdata/api/model/character"
// CharacterResolver for the Character graphql type
type CharacterResolver struct{ C character.Character }
// ID is a property resolver
func (r *CharacterResolver) ID() string {
return r.C.ID
}
// Nick is a property resolver
func (r *CharacterResolver) Nick() *string {
if len(r.C.Nicks) == 0 {
return nil
}
return &r.C.Nicks[0]
}
// Nicks is a property resolver
func (r *CharacterResolver) Nicks() []string {
return r.C.Nicks
}
// Name is a property resolver
func (r *CharacterResolver) Name() string {
return r.C.Name
}
// ShortName is a property resolver
func (r *CharacterResolver) ShortName() string {
return r.C.ShortName
}
// Author is a property resolver
func (r *CharacterResolver) Author() string {
return r.C.Author
}
// Description is a property resolver
func (r *CharacterResolver) Description() string {
return r.C.Description
}
Loading…
Cancel
Save