package resolvers import ( "context" "errors" "git.aiterp.net/rpdata/api/graph2/graphcore" "git.aiterp.net/rpdata/api/models" ) // Queries func (r *queryResolver) Character(ctx context.Context, id *string, nick *string) (*models.Character, error) { if id != nil { return r.s.Characters.Find(ctx, *id) } else if nick != nil { return r.s.Characters.FindNick(ctx, *nick) } else { return nil, errors.New("You must specify either an ID or a nick") } } func (r *queryResolver) Characters(ctx context.Context, filter *models.CharacterFilter) ([]*models.Character, error) { if filter == nil { filter = &models.CharacterFilter{} } return r.s.Characters.List(ctx, *filter) } // Mutations func (r *mutationResolver) AddCharacter(ctx context.Context, input graphcore.CharacterAddInput) (*models.Character, error) { author := "" if input.Author != nil { author = *input.Author } shortName := "" if input.ShortName != nil { shortName = *input.ShortName } description := "" if input.Description != nil { description = *input.Description } return r.s.Characters.Create(ctx, input.Nick, input.Name, shortName, author, description) } func (r *mutationResolver) AddCharacterNick(ctx context.Context, input graphcore.CharacterNickInput) (*models.Character, error) { return r.s.Characters.AddNick(ctx, input.ID, input.Nick) } func (r *mutationResolver) RemoveCharacterNick(ctx context.Context, input graphcore.CharacterNickInput) (*models.Character, error) { return r.s.Characters.RemoveNick(ctx, input.ID, input.Nick) } func (r *mutationResolver) EditCharacter(ctx context.Context, input graphcore.CharacterEditInput) (*models.Character, error) { return r.s.Characters.Update(ctx, input.ID, input.Name, input.ShortName, input.Description) } func (r *mutationResolver) RemoveCharacter(ctx context.Context, input graphcore.CharacterRemoveInput) (*models.Character, error) { return r.s.Characters.Delete(ctx, input.ID) }