Graphql-ruby: Raising exceptions on failed execution

Created on 13 Mar 2020  路  5Comments  路  Source: rmosolgo/graphql-ruby

Is there a way to raise exceptions when a query fails to execute, for example in development? I'm using an SSR setup that gobbles up GraphQL's thoughtful response when I have bad server-side queries, causing much confusion. I would love for my server to come to a crashing halt when a bad query arises so that it's abundantly clear.

Most helpful comment

decisions are driven by GH's needs

Yes, I work for GitHub and GraphQL-Ruby powers GitHub's GraphQL API. A lot of my work in the last couple of years has been aimed at fixing GitHub's problems, namely:

  • Big schema problems
  • Runtime & memory performance and observability problems
  • Complicated authorization problems
  • Developer experience problems

I'm really happy to have invested there, but it leaves some other areas less developed:

  • Onboarding & new project flow
  • Getting-started docs
  • Integrations with popular clients

needs of the community

In my personal time, I do my best fixing bugs and supporting graphql-pro customers. Also, I work hard to help folks who want to contribute their own fixes and improvements to graphql-ruby! Of course, lots of people download the gem and they're unhappy about one thing or another, but I accept that I can't do it _all_!

All 5 comments

How about checking for errors in the result, and raising an error if there are any?

result = MySchema.execute(...)
if result["errors"].present? && Rails.env.development?
  raise "A GraphQL query failed with errors: #{result["errors"].inspect}"
end 

?

There's nothing special in GraphQL-Ruby for this, but let me know if you have trouble with that!

Brilliant, exactly what I was looking for. Thank you!

Side note, @rmosolgo, because I've been really curious: is this the GraphQL implementation that GitHub uses for their main public API? I see that you have the "staff" badge on your avatar and I think that you mentioned in another issue something about how GH uses this gem.

I'm wondering, if you're able to share, how much of the design decisions are driven by GH's needs vs. the needs of the community. That's not a negative comment on or criticism stemming from this current issue or any other in particular...I love the project, keep up the great work :-)

decisions are driven by GH's needs

Yes, I work for GitHub and GraphQL-Ruby powers GitHub's GraphQL API. A lot of my work in the last couple of years has been aimed at fixing GitHub's problems, namely:

  • Big schema problems
  • Runtime & memory performance and observability problems
  • Complicated authorization problems
  • Developer experience problems

I'm really happy to have invested there, but it leaves some other areas less developed:

  • Onboarding & new project flow
  • Getting-started docs
  • Integrations with popular clients

needs of the community

In my personal time, I do my best fixing bugs and supporting graphql-pro customers. Also, I work hard to help folks who want to contribute their own fixes and improvements to graphql-ruby! Of course, lots of people download the gem and they're unhappy about one thing or another, but I accept that I can't do it _all_!

Was this page helpful?
0 / 5 - 0 ratings