graphman icon indicating copy to clipboard operation
graphman copied to clipboard

feat: improve error message when the request fails

Open jmfayard opened this issue 1 year ago • 5 comments

Hello, graphman worked with my local backend, nice <3

I tried to do that

# create a new token
$ open https://github.com/settings/tokens/new
$ export GITHUB_TOKEN="xxxxxxxx"
# works for me
$ curl -H "Authorization: bearer $GITHUB_TOKEN" https://api.github.com/graphql
$ alias graphman="deno  run  https://deno.land/x/[email protected]/src/index.ts"
$ graphman https://api.github.com/graphql --auth="bearer $GTHUB_TOKEN"
Creating the postman collection for https://api.github.com/graphql
⚠️  ️Deno requests net access to "api.github.com". Run again with --allow-net to bypass this prompt.
   Allow? [y/n (y = yes allow, n = no deny)]  y
error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__schema')
  const queryTypeName = introspectionQuery.__schema.queryType
                                           ^
    at createPostmanCollection (https://deno.land/x/[email protected]/src/lib.ts:308:44)
    at async https://deno.land/x/[email protected]/src/index.ts:38:20

Reference: https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#communicating-with-graphql

EDIT:

The actual issue is the lack of a good error message when the http call fails

As it turns out it was a typo (thanks for the comments)

$ graphman https://api.github.com/graphql --auth="bearer $GITHUB_TOKEN"
Collection saved at ./out/api.github.com-GraphMan.postman_collection.json
Import it in postman and complete the queries ! 🚀

jmfayard avatar Aug 10 '22 15:08 jmfayard

Thanks for reporting, will investigate ASAP!

nohehf avatar Aug 10 '22 23:08 nohehf

https://api.github.com/graphql --auth="bearer $GTHUB_TOKEN"

Hello @jmfayard,

On my end everything is working properly, can you take away my doubt and re-try with a correct environment variable ? I suspect a typo error as $GTHUB_TOKEN is missing a I.

@nohehf, maybe it miss a bit of feedback whenever the request failed to get a correct introspection. - Here it would deny the request for invalid auth. I suggest that you print the response received on 401, 500 etc, as well as when the payload is a valid graphql payload and contains an error key.

nullswan avatar Aug 10 '22 23:08 nullswan

Oh yes, thanks @c3b5aw it must be a typo. You're right, we should raise a special error for this. I'll make sure to do it in the refactor #2

nohehf avatar Aug 11 '22 07:08 nohehf

@c3b5aw @nohehf it was indeed a typo and the issue is the cryptic error message, I updated the ticket.

Another question: could you clarify in the README how to bypass those warnings?

It was unclear to me where to put the arguments, I'm not familiar with deno.

⚠️  ️Deno requests net access to "api.github.com". Run again with --allow-net to bypass this prompt.
   Allow? [y/n (y = yes allow, n = no deny)]  y
⚠️  ️Deno requests read access to "./out/". Run again with --allow-read to bypass this prompt.
   Allow? [y/n (y = yes allow, n = no deny)]  y
⚠️  ️Deno requests write access to "./out/api.github.com-GraphMan.postman_collection.json". Run again with --allow-write to bypass this prompt.
   Allow? [y/n (y = yes allow, n = no deny)]  y
Collection saved at ./out/api.github.com-GraphMan.postman_collection.json

jmfayard avatar Aug 11 '22 10:08 jmfayard

Nice! It's deno run --allow-net --allow-read ...: https://deno.land/manual/getting_started/command_line_interface

nohehf avatar Aug 11 '22 18:08 nohehf

Hey @jmfayard, this is merged !

nohehf avatar Sep 23 '22 08:09 nohehf

😲👋

jmfayard avatar Sep 23 '22 08:09 jmfayard