class GraphQL::Schema::Timeout

This plugin will stop resolving new fields after max_seconds have elapsed. After the time has passed, any remaining fields will be nil, with errors added to the errors key. Any already-resolved fields will be in the data key, so you’ll get a partial response.

You can subclass GraphQL::Schema::Timeout and override max_seconds and/or handle_timeout to provide custom logic when a timeout error occurs.

Note that this will stop a query in between field resolutions, but it doesn’t interrupt long-running resolve functions. Be sure to use timeout options for external connections. For more info, see www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/

Examples

Example: Stop resolving fields after 2 seconds

class MySchema < GraphQL::Schema
  use GraphQL::Schema::Timeout, max_seconds: 2
end

Example: Notifying Bugsnag and logging a timeout

class MyTimeout < GraphQL::Schema::Timeout
  def handle_timeout(error, query)
     Rails.logger.warn("GraphQL Timeout: #{error.message}: #{query.query_string}")
     Bugsnag.notify(error, {query_string: query.query_string})
  end
end

class MySchema < GraphQL::Schema
  use MyTimeout, max_seconds: 2
end