api/graph: Add User.tracker query

Replace the tracker, trackerByName and trackerByOwner queries with a new
User.tracker query which is more graph-like.

References: https://todo.sr.ht/~sircmpwn/sr.ht/309
This commit is contained in:
Adnan Maolood 2022-04-28 10:26:44 -04:00 committed by Drew DeVault
parent 8dd35065ed
commit 646b1e55db
2 changed files with 8 additions and 31 deletions

View File

@ -69,6 +69,9 @@ type User implements Entity {
location: String
bio: String
"Returns a specific tracker."
tracker(name: String!): Tracker @access(scope: TRACKERS, kind: RO)
trackers(cursor: Cursor): TrackerCursor! @access(scope: TRACKERS, kind: RO)
}
@ -644,20 +647,6 @@ type Query {
"""
trackers(cursor: Cursor): TrackerCursor @access(scope: TRACKERS, kind: RO)
"Returns a specific tracker by ID."
tracker(id: Int!): Tracker @access(scope: TRACKERS, kind: RO)
"Returns a specific tracker, owned by the authenticated user."
trackerByName(name: String!): Tracker @access(scope: TRACKERS, kind: RO)
"""
Returns a specific tracker, owned by the given canonical name (e.g.
"~sircmpwn").
"""
trackerByOwner(owner: String!, tracker: String!): Tracker @access(scope: TRACKERS, kind: RO)
# TODO: Add ticket by tracker ID and ticket ID
"""
List of events which the authenticated user is subscribed to or implicated
in, ordered by the event date (recent events first).

View File

@ -2088,23 +2088,6 @@ func (r *queryResolver) Trackers(ctx context.Context, cursor *coremodel.Cursor)
return &model.TrackerCursor{trackers, cursor}, nil
}
func (r *queryResolver) Tracker(ctx context.Context, id int) (*model.Tracker, error) {
return loaders.ForContext(ctx).TrackersByID.Load(id)
}
func (r *queryResolver) TrackerByName(ctx context.Context, name string) (*model.Tracker, error) {
return loaders.ForContext(ctx).TrackersByName.Load(name)
}
func (r *queryResolver) TrackerByOwner(ctx context.Context, owner string, tracker string) (*model.Tracker, error) {
if strings.HasPrefix(owner, "~") {
owner = owner[1:]
} else {
return nil, fmt.Errorf("Expected owner to be a canonical name")
}
return loaders.ForContext(ctx).TrackersByOwnerName.Load([2]string{owner, tracker})
}
func (r *queryResolver) Events(ctx context.Context, cursor *coremodel.Cursor) (*model.EventCursor, error) {
if cursor == nil {
cursor = coremodel.NewCursor(nil)
@ -2923,6 +2906,11 @@ func (r *trackerWebhookSubscriptionResolver) Tracker(ctx context.Context, obj *m
return loaders.ForContext(ctx).TrackersByID.Load(obj.TrackerID)
}
func (r *userResolver) Tracker(ctx context.Context, obj *model.User, name string) (*model.Tracker, error) {
// TODO: TrackersByOwnerIDTrackerName loader
return loaders.ForContext(ctx).TrackersByOwnerName.Load([2]string{obj.Username, name})
}
func (r *userResolver) Trackers(ctx context.Context, obj *model.User, cursor *coremodel.Cursor) (*model.TrackerCursor, error) {
if cursor == nil {
cursor = coremodel.NewCursor(nil)