class GraphQL::Schema::Timeout


end
use MyTimeout, max_seconds: 2
class MySchema < GraphQL::Schema
end
end
Bugsnag.notify(error, {query_string: query.query_string})
Rails.logger.warn(“GraphQL Timeout: #{error.message}: #{query.query_string}”)
def handle_timeout(error, query)
class MyTimeout < GraphQL::Schema::Timeout
@example Notifying Bugsnag and logging a timeout
end
use GraphQL::Schema::Timeout, max_seconds: 2
class MySchema < GraphQL::Schema
@example Stop resolving fields after 2 seconds
/
timeout options for external connections. For more info, see
it doesn’t interrupt long-running ‘resolve` functions. Be sure to use
Note that this will stop a query _in between_ field resolutions, but
to provide custom logic when a timeout error occurs.
You can subclass `GraphQL::Schema::Timeout` and override `max_seconds` and/or `handle_timeout`
you’ll get a partial response.
to the ‘errors` key. Any already-resolved fields will be in the `data` key, so
After the time has passed, any remaining fields will be `nil`, with errors added
This plugin will stop resolving new fields after `max_seconds` have elapsed.

def self.use(schema, max_seconds: nil)

def self.use(schema, max_seconds: nil)
  timeout = self.new(max_seconds: max_seconds)
  schema.trace_with(self::Trace, timeout: timeout)
end

def handle_timeout(error, query)

Parameters:
  • query (GraphQL::Error) --
  • error (GraphQL::Schema::Timeout::TimeoutError) --
def handle_timeout(error, query)
  # override to do something interesting
end

def initialize(max_seconds:)

def initialize(max_seconds:)
  @max_seconds = max_seconds
end

def max_seconds(query)

Returns:
  • (Integer, false) - The number of seconds after which to interrupt query execution and call {#handle_error}, or `false` to bypass the timeout.

Parameters:
  • query (GraphQL::Query) -- The query that's about to run
def max_seconds(query)
  @max_seconds
end