~sircmpwn/sr.ht-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
6 4

[PATCH todo.sr.ht] api: Add labelByName resolver

Details
Message ID
<20230314122110.103078-1-admin@xenrox.net>
DKIM signature
pass
Download raw message
Patch: +33 -0
The authorization check is already done by the fetchTrackersByOwnerName
loader.
---
v2: Make labelByName nullable

This resolver would be really useful for hut, so that users can
delete/update/assign labels by their unique name instead of by the ID.

I have left out any permission checks since that is already handled.
Or do you prefer to still include them and double check?

 api/graph/schema.graphqls     |  1 +
 api/graph/schema.resolvers.go | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/api/graph/schema.graphqls b/api/graph/schema.graphqls
index 5d0c15e..e168083 100644
--- a/api/graph/schema.graphqls
+++ b/api/graph/schema.graphqls
@@ -117,6 +117,7 @@ type Tracker {

  ticket(id: Int!): Ticket! @access(scope: TICKETS, kind: RO)
  tickets(cursor: Cursor): TicketCursor! @access(scope: TICKETS, kind: RO)
  labelByName(name: String!): Label
  labels(cursor: Cursor): LabelCursor!

  """
diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go
index a6d5c2f..daf60ee 100644
--- a/api/graph/schema.resolvers.go
+++ b/api/graph/schema.resolvers.go
@@ -2969,6 +2969,38 @@ func (r *trackerResolver) Tickets(ctx context.Context, obj *model.Tracker, curso
	return &model.TicketCursor{tickets, cursor}, nil
}

// LabelByName is the resolver for the labelByName field.
func (r *trackerResolver) LabelByName(ctx context.Context, obj *model.Tracker, name string) (*model.Label, error) {
	label := (&model.Label{}).As(`l`)
	if err := database.WithTx(ctx, &sql.TxOptions{
		Isolation: 0,
		ReadOnly:  true,
	}, func(tx *sql.Tx) error {
		row := database.
			Select(ctx, label).
			From(`label l`).
			Where(sq.And{
				sq.Expr(`l.name = ?`, name),
				sq.Expr(`l.tracker_id = ?`, obj.ID),
			}).
			RunWith(tx).
			QueryRowContext(ctx)

		if err := row.Scan(database.Scan(ctx, label)...); err != nil {
			return err
		}

		return nil
	}); err != nil {
		if err == sql.ErrNoRows {
			return nil, nil
		}
		return nil, err
	}

	return label, nil
}

// Labels is the resolver for the labels field.
func (r *trackerResolver) Labels(ctx context.Context, obj *model.Tracker, cursor *coremodel.Cursor) (*model.LabelCursor, error) {
	if cursor == nil {

base-commit: 573e3b244b78ce4b8d864d3929b856ba87520f33
-- 
2.39.2

[todo.sr.ht/patches] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CR63RPC503QE.1L0RIDGJ6ZVB9@cirno2>
In-Reply-To
<20230314122110.103078-1-admin@xenrox.net> (view parent)
DKIM signature
missing
Download raw message
todo.sr.ht/patches: FAILED in 3m59s

[api: Add labelByName resolver][0] from [Thorben Günther][1]

[0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/39706
[1]: admin@xenrox.net

✓ #957009 SUCCESS todo.sr.ht/patches/alpine.yml    https://builds.sr.ht/~sircmpwn/job/957009
✗ #957010 FAILED  todo.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/957010
✓ #957011 SUCCESS todo.sr.ht/patches/debian.yml    https://builds.sr.ht/~sircmpwn/job/957011
Details
Message ID
<6zz-JE_DGYfGFImz5QPybIMZdKVBJMi6DtQhOU4IYLkmKebTNaGLDmLBivfEhViGU61pDDB8haCJa_DItJakEf1pIFOfYAAI74Lliee_gwE=@emersion.fr>
In-Reply-To
<20230314122110.103078-1-admin@xenrox.net> (view parent)
DKIM signature
pass
Download raw message
LGTM!
Details
Message ID
<CR641D3SCGRQ.1PP8K8HLNVOJP@framework>
In-Reply-To
<20230314122110.103078-1-admin@xenrox.net> (view parent)
DKIM signature
pass
Download raw message
On Tue Mar 14, 2023 at 8:21 AM EDT, Thorben Günther wrote:
>    ticket(id: Int!): Ticket! @access(scope: TICKETS, kind: RO)
>    tickets(cursor: Cursor): TicketCursor! @access(scope: TICKETS, kind: RO)
> +  labelByName(name: String!): Label
>    labels(cursor: Cursor): LabelCursor!

Why not call this label(name)? Since I don't think we'll need any other
label field. This will make it match with User.tracker(name).
Details
Message ID
<20230314134619.xnl5ief3bhcwn7kd@xenrox.net>
In-Reply-To
<CR641D3SCGRQ.1PP8K8HLNVOJP@framework> (view parent)
DKIM signature
pass
Download raw message
On Tue, Mar 14, 2023 at 08:37:55AM -0400, Adnan Maolood wrote:
> On Tue Mar 14, 2023 at 8:21 AM EDT, Thorben Günther wrote:
> >    ticket(id: Int!): Ticket! @access(scope: TICKETS, kind: RO)
> >    tickets(cursor: Cursor): TicketCursor! @access(scope: TICKETS, kind: RO)
> > +  labelByName(name: String!): Label
> >    labels(cursor: Cursor): LabelCursor!
>
> Why not call this label(name)? Since I don't think we'll need any other
> label field. This will make it match with User.tracker(name).

Okay, if you don't plan to introduce a labelByID field, I'll send a v3
with the rename.
Details
Message ID
<AhqzFWrD6MnfFNpyulHDQjSsZdGtubJ9KzTTWp1hNmEZfZ_w3OZPrEZpIHg6NzHhWJNBKXstsC9ZIFiuW-OtAzQJJouOJVAjJ1qLk5uL-MU=@emersion.fr>
In-Reply-To
<20230314134619.xnl5ief3bhcwn7kd@xenrox.net> (view parent)
DKIM signature
pass
Download raw message
On Tuesday, March 14th, 2023 at 14:46, Thorben Günther <admin@xenrox.net> wrote:

> On Tue, Mar 14, 2023 at 08:37:55AM -0400, Adnan Maolood wrote:
> 
> > On Tue Mar 14, 2023 at 8:21 AM EDT, Thorben Günther wrote:
> > 
> > > ticket(id: Int!): Ticket! @access(scope: TICKETS, kind: RO)
> > > tickets(cursor: Cursor): TicketCursor! @access(scope: TICKETS, kind: RO)
> > > + labelByName(name: String!): Label
> > > labels(cursor: Cursor): LabelCursor!
> > 
> > Why not call this label(name)? Since I don't think we'll need any other
> > label field. This will make it match with User.tracker(name).
> 
> Okay, if you don't plan to introduce a labelByID field, I'll send a v3
> with the rename.

It seems pretty common in GraphQL APIs to have a single query with
multiple possible filters, e.g.

    label(name: String, id: Int)
Details
Message ID
<U5D8LiCYb76DrXhq07p0PmjmtwuSzOjE7CtBvM9sP4JumNyVQQo3DYNufDfE_sWr9uv4vT-12TdpQOsjyqEAv_VvPno5XJuja7IuTez3Xeo=@emersion.fr>
In-Reply-To
<20230314122110.103078-1-admin@xenrox.net> (view parent)
DKIM signature
pass
Download raw message
LGTM
Reply to thread Export thread (mbox)