Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding extensions to ExecutionError #53

Open
RealSilo opened this issue Nov 8, 2018 · 5 comments
Open

adding extensions to ExecutionError #53

RealSilo opened this issue Nov 8, 2018 · 5 comments

Comments

@RealSilo
Copy link

RealSilo commented Nov 8, 2018

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
@dblock
Copy link
Collaborator

dblock commented Nov 8, 2018

Sounds like a good idea! PRs welcome.

@yuki24
Copy link
Collaborator

yuki24 commented Nov 8, 2018

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.

@RealSilo
Copy link
Author

RealSilo commented Nov 9, 2018

@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.

@dblock
Copy link
Collaborator

dblock commented Nov 9, 2018

@RealSilo PRs always welcome!

@RealSilo
Copy link
Author

RealSilo commented Nov 9, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants