README.md in rack-graphql-2.5.1 vs README.md in rack-graphql-2.6.0
- old
+ new
@@ -21,18 +21,19 @@
Add following to your `config.ru` file:
```ruby
run RackGraphql::Application.call(
- schema: YourGraqphqlSchema, # required
- 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
+ schema: YourGraqphqlSchema, # required
+ 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
- logger: A9n.logger, # optional, not set by default
+ health_route: true, # optional, true by default
+ logger: A9n.logger, # optional, not set by default
error_status_code_map: { IamTeapotError => 418 }, # optional
+ re_raise_exceptions: true, # optional, false by default
)
```
`context_handler` can be a class, object or proc. It must respond to `call` method taking `env` as an argument. It is supposed to decode or transform request properties to graphql context (eg. jwt token to user object, as shown on an example below).
@@ -77,9 +78,42 @@
RackGraphql catches all errors and respond with 500 code. By default it adds exception backtrace to the response body. If you don't want to have the backtrace in the response set:
```
RackGraphql.log_exception_backtrace = false
+```
+
+### 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:
+
+```ruby
+class GraphqlErrorTrackerMiddleware
+ def self.call(parent_type, parent_object, field_definition, field_args, query_context)
+ yield
+ rescue StandardError => e
+ 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
+ }
+ Sentry.capture_exception(e, extra: extra)
+ raise
+ 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.