Class: GraphQL::Cache::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/cache/fetcher.rb

Overview

Represents the "instrumenter" passed to GraphQL::Schema#instrument when the plugin in initialized (i.e. use GraphQL::Cache)

Instance Method Summary collapse

Instance Method Details

#instrument(type, field) ⇒ GraphQL::Schema::Field

Redefines the given field's resolve proc to use our custom cache wrapping resolver proc. Called from graphql-ruby internals. This is the "instrumenter" entrypoint.

Parameters:

  • type (GraphQL::Schema::Object)

    graphql-ruby passes the defined type for the field being instrumented

  • field (GraphQL::Schema::Field)

    graphql-ruby passes the field definition to be re-defined

Returns:

  • (GraphQL::Schema::Field)


14
15
16
17
18
19
20
21
# File 'lib/graphql/cache/fetcher.rb', line 14

def instrument(type, field)
  return field unless field.[:cache]

  cached_resolve_proc = cached_resolve(type, field)

  # Return a copy of `field`, with the new resolve proc
  field.redefine { resolve(cached_resolve_proc) }
end