README.md in rack-graphql-2.6.1 vs README.md in rack-graphql-2.7.0

- old
+ new

@@ -27,10 +27,11 @@ app_name: 'your-service-name', # optional, used for health endpoint content context_handler: YourGraphqlContextHandler, # optional, empty `proc` by default log_exception_backtrace: !A9n.env.production?, # optional, `false` default # `true` when `RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE` env var is set to `'1'` or `'true'` health_route: true, # optional, true by default + health_on_root_path: health_route, # optional, health_route value by default (mind map '/' is covering '/any/path-123') logger: A9n.logger, # optional, not set by default error_status_code_map: { IamTeapotError => 418 }, # optional re_raise_exceptions: true, # optional, false by default ) ``` @@ -85,35 +86,34 @@ ### Error tracking/reporting To respect the graphql spec, all errors need to be returned as json and `rack-graphql` catches all exceptions and does NOT re-raise them. You can change this behavior via `re_raise_exceptions` argument. Because of this, using error tracking middleware (`use Sentry::Rack::CaptureExceptions`, `use Raven::Rack`) does not take any effect for graphql requests. -To use Sentry or other reporting tool for graphql queries, you can use `GraphQL::Schema` middleware: +To use Sentry or other reporting tool for graphql queries, you should handle it on graphql schema level: ```ruby -class GraphqlErrorTrackerMiddleware - def self.call(parent_type, parent_object, field_definition, field_args, query_context) - yield - rescue StandardError => e +class MySchema < GraphQL::Schema + rescue_from StandardError do |e, obj, args, ctx, field| extra = { - parent_type: parent_type.inspect, - parent_object: parent_object.inspect, - field_definition: field_definition.to_s, - field_args: field_args&.to_h, - query_context: query_context&.to_h + args: args, + field: field.inspect, + context: ctx } Sentry.capture_exception(e, extra: extra) + # re-raise to be handled by rack middleware raise + # or return execution error + ::GraphQL::ExecutionError.new( + exception.class.to_s, + options: { "http_status" => 500 }, + extensions: { + "code" => exception.class.to_s, + "http_status" => 500, + "details" => exception.inspect + } + ) end end - -# MySchema.middleware GraphqlErrorTrackerMiddleware -# or -# GraphQL::Schema.middleware GraphqlErrorTrackerMiddleware -# or -# class MySchema < GraphQL::Schema -# middleware GraphqlErrorTrackerMiddleware -# end ``` ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/RenoFi/rack-graphql. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.