ashkan18/graphlient

adding extensions to ExecutionError

RealSilo opened this issue · 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

Sounds like a good idea! PRs welcome.

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 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 PRs always welcome!

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