graphlient icon indicating copy to clipboard operation
graphlient copied to clipboard

adding extensions to ExecutionError

Open RealSilo opened this issue 6 years ago • 5 comments

Hey,

I think it would be great to have extensions with code (see here: http://graphql-ruby.org/errors/execution_errors.html) to the Graphlient::Errors::ExecutionError class.

So it could be used in tests as:

rescue Graphlient::Errors::ExecutionError => e
  expect(e.message).to eq('My error message')
  expect(e.extensions.code).to eq('UNAUTHORIZED')
end

RealSilo avatar Nov 08 '18 00:11 RealSilo

Sounds like a good idea! PRs welcome.

dblock avatar Nov 08 '18 16:11 dblock

The code used in the GraphQL Ruby documentation is just an example of what the server could return to you. Also, the ExecutionError holds a reference to the response object so you could actually get the extensions out of it:

JSON.parse(execution_error.response.body, symbolize_names: true)[:extensions]

If you are requesting to add an alias, then yes, that seems like a useful helper method. However, if you meant to mutate the extensions, it could be surprising as it could override what the server really wants to tell you.

yuki24 avatar Nov 08 '18 19:11 yuki24

@yuki24 I know it's only recommended https://facebook.github.io/graphql/draft/#example-fce18 at the moment but as I see everybody is using it (from startups to big companies).

Thanks for the example on how to parse the keys. I think it's a bit awkward though. It seems to be way easier to use e.extensions.code.

@dblock Let me know if you still want me to open a PR based on @yuki24 's comments.

RealSilo avatar Nov 09 '18 20:11 RealSilo

@RealSilo PRs always welcome!

dblock avatar Nov 09 '18 21:11 dblock

Sounds good. I will try to open a PR this weekend.

RealSilo avatar Nov 09 '18 22:11 RealSilo