|
|
package resolvers
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
import ( "context"
"git.aiterp.net/stufflog/server/graph/graphcore" "git.aiterp.net/stufflog/server/graph/graphutil" "git.aiterp.net/stufflog/server/graph/loaders" "git.aiterp.net/stufflog/server/internal/slerrors" "git.aiterp.net/stufflog/server/models" )
func (r *issueResolver) Project(ctx context.Context, obj *models.Issue) (*models.Project, error) { return r.Database.Projects().Find(ctx, obj.ProjectID) }
func (r *issueResolver) Owner(ctx context.Context, obj *models.Issue) (*models.User, error) { if obj.OwnerID == "" { return nil, nil }
// Shortcut: if only ID is needed, resolve with empty user.
if !graphutil.SelectsAnyField(ctx, "name", "active", "admin") { return &models.User{ID: obj.OwnerID}, nil }
return loaders.UserLoaderFromContext(ctx).Load(obj.OwnerID) }
func (r *issueResolver) Assignee(ctx context.Context, obj *models.Issue) (*models.User, error) { if obj.AssigneeID == "" { return nil, nil }
// Shortcut: if only ID is needed, resolve with empty user.
if !graphutil.SelectsAnyField(ctx, "name", "active", "admin") { return &models.User{ID: obj.AssigneeID}, nil }
return loaders.UserLoaderFromContext(ctx).Load(obj.AssigneeID) }
func (r *issueResolver) Status(ctx context.Context, obj *models.Issue) (*models.ProjectStatus, error) { // Shortcut: if description isn't needed, resolve this with issue's properties.
if !graphutil.SelectsAnyField(ctx, "description") { return &models.ProjectStatus{ ProjectID: obj.ProjectID, Stage: obj.StatusStage, Name: obj.StatusName, Description: "FAKE", }, nil }
status, err := r.Database.ProjectStatuses().Find(ctx, obj.ProjectID, obj.StatusName) if slerrors.IsNotFound(err) { return &models.ProjectStatus{ ProjectID: obj.ProjectID, Stage: obj.StatusStage, Name: obj.StatusName, Description: "(Deleted or unknown status)", }, nil } else if err != nil { return nil, err }
// If the stage doesn't match, sneakily correct it for next time.
if status.Stage != obj.StatusStage { updatedIssue := *obj updatedIssue.StatusStage = status.Stage _ = r.Database.Issues().Save(ctx, updatedIssue) }
return status, nil }
func (r *issueResolver) Tasks(ctx context.Context, obj *models.Issue, filter *models.IssueTaskFilter) ([]*models.IssueTask, error) { if filter == nil { filter = &models.IssueTaskFilter{} } filter.IssueTaskIDs = []string{obj.ID}
return r.Database.IssueTasks().List(ctx, *filter) }
// Issue returns graphcore.IssueResolver implementation.
func (r *Resolver) Issue() graphcore.IssueResolver { return &issueResolver{r} }
type issueResolver struct{ *Resolver }
|