~xenrox/hut#48: 
Experimental "debug" flag

To show how exactly GraphQL is used.

Can probably inject into RoundTrip.

Status
REPORTED
Submitter
~xenrox
Assigned to
No-one
Submitted
6 months ago
Updated
6 months ago
Labels
discussion enhancement

~xenrox referenced this from #23 6 months ago

~xenrox 6 months ago*

Right now you can already take a look at our operations.graphql files to see hut's queries and mutations (e.g. for meta).

~xenrox 6 months ago

~mcepl, ~jschmidt: I've added a simple "debug" flag in a branch.

Would be great if you could take a look at it and share some feedback. I personally don't see much usefulness/appeal in it but maybe it is useful to you.

Besides I will probably work on structured output, I have an idea, but it will increase maintenance burden so no promises yet.

~jschmidt 6 months ago

Would be great if you could take a look at it and share some feedback. I personally don't see much usefulness/appeal in it but maybe it is useful to you.

Here is my journey through that new feature (thanks):

[hut]$ ./hut --debug builds list
{{"query":"query jobs ($cursor: Cursor) {\n\tjobs(cursor: $cursor) {\n\t\t... jobs\n\t}\n}\nfragment jobs on JobCursor {\n\tresults {\n\t\tid\n\t\tstatus\n\t\tnote\n\t\ttags\n\t\ttasks {\n\t\t\tname\n\t\t\tstatus\n\t\t}\n\t}\n\tcursor\n}\n","variables":{"cursor":null}}
}
#1239925 - copy-on-select-2/commits/implement-sourcehut-builds/.build.yml: ✔ SUCCESS
✔ make  
[...]
:{{"query":"query jobs ($cursor: Cursor) {\n\tjobs(cursor: $cursor) {\n\t\t... jobs\n\t}\n}\nfragment jobs on JobCursor {\n\tresults {\n\t\tid\n\t\tstatus\n\t\tnote\n\t\ttags\n\t\ttasks {\n\t\t\tname\n\t\t\tstatus\n\t\t}\n\t}\n\tcursor\n}\n","variables":{"cursor":"gAAAAABmZ20mwWV870mNOhm-NXIvtTrofygLvocVJlFGBaNmM-Qroyk1qFoMeVcMXfn1yQL33gIRK5z_Zu1FCRqTgqgwYPrPJHjeBspW6jXTFLyX-09BUn7jpXFtwjdMAxJznQ-tCtbR"}}
}

Uh. Right, debug output and pagerified output surely don't go well together. Plus the repeating requests are confusing. We could force single-paged output in debug mode, but sometimes one probably would actually like to debug paged output. So for the time being let's do:

[hut]$ ./hut --debug builds list 1>/dev/null
{{"query":"query jobs ($cursor: Cursor) {\n\tjobs(cursor: $cursor) {\n\t\t... jobs\n\t}\n}\nfragment jobs on JobCursor {\n\tresults {\n\t\tid\n\t\tstatus\n\t\tnote\n\t\ttags\n\t\ttasks {\n\t\t\tname\n\t\t\tstatus\n\t\t}\n\t}\n\tcursor\n}\n","variables":{"cursor":null}}
}

That's better, at least for the purpose of extracting the response body or the GraphQL query. Next try (one of the rare occasions where 2>&1 1>... is actually TRT!):

[hut]$ ./hut --debug builds list 2>&1 1>/dev/null | jq
parse error: Objects must consist of key:value pairs at line 2, column 1

Hu? Oops, there is an extra pair of braces around the body. Where does that come from? Haven't seen or used that up-to-now, but then I'm a relative GraphQL newbie. Getting rid of the braces the quick-and-dirty way:

[hut]$ ./hut --debug builds list 2>&1 1>/dev/null | sed 's/^.//' | jq
{
  "query": "query jobs ($cursor: Cursor) {\n\tjobs(cursor: $cursor) {\n\t\t... jobs\n\t}\n}\nfragment jobs on JobCursor {\n\tresults {\n\t\tid\n\t\tstatus\n\t\tnote\n\t\ttags\n\t\ttasks {\n\t\t\tname\n\t\t\tstatus\n\t\t}\n\t}\n\tcursor\n}\n",
  "variables": {
    "cursor": null
  }
}

That's better and looks familiar to what I use when doing GraphQL with cURL. Now for the GraphQL itself:

[hut]$ ./hut --debug builds list 2>&1 1>/dev/null | sed 's/^.//' | jq -r '.query' | tr '\t' ' '
query jobs ($cursor: Cursor) {
 jobs(cursor: $cursor) {
  ... jobs
 }
}
fragment jobs on JobCursor {
 results {
  id
  status
  note
  tags
  tasks {
   name
   status
  }
 }
 cursor
}

To summarize, the new debug option provides:

  • debugging of the body
  • the option to extract the request body in a way that could be used for cURL
  • the option to extract the GraphQL in a way that could be used for hut graphql

Only it's a bit involved to get to the latter two. One could add examples along the lines of mine above. Or one could extend the syntax of the debug option to more easily get there. The point is:

Besides I will probably work on structured output, I have an idea, but it will increase maintenance burden so no promises yet.

I think if there were an option available so that something along the lines of the following would work really easily:

hut --debug=graphql builds list > example.graphql
# fiddle with example.graphql
hut graphql --var=... --cursor=... < example.graphql

then you could perfectly well do without structured output, because then users would have an option to easily generate structured output at their will.

~jschmidt 6 months ago

I forgot this last one example which already works on your new branch and hopefully shows what I'm writing about at the end of my previous post:

[hut]$ ./hut --debug builds list 2>&1 1>/dev/null | sed 's/^.//' | jq -r '.query' | ./hut graphql --stdin builds | head -4
{
  "jobs": {
    "results": [
      {

~mcepl 6 months ago*

On Mon Jun 10, 2024 at 10:56 PM CEST, ~xenrox wrote:

Would be great if you could take a look at it and share some feedback. I personally don't see much usefulness/appeal in it but maybe it is useful to you.

Seems to work as expected, except for replacing all sequences of white space just with one space character, would improve readability of the output a lot.

Thank you!

Matěj

~xenrox 6 months ago

Thorben Günther referenced this ticket in commit 8cb8edb.

~xenrox 6 months ago

I have merged this in its current form for now and will revisit in the future to improve it a bit. The secondary outer curly brackets shouldn't be there for sure.

Register here or Log in to comment, or comment via email.