class GraphQL::Schema::FieldExtension

which could cause all kinds of issues due to race conditions.
The instance is frozen so that instance variables aren’t modified during query execution,
is created, and its hooks are applied whenever that field is called.
When a extension is added to a field with ‘extension(MyExtension)`, a `MyExtension` instance
Extend this class to make field-level customizations to resolve behavior.

def after_define

Returns:
  • (void) -
def after_define
end

def after_define_apply

Other tags:
    Api: - private
def after_define_apply
  after_define
  if (configs = self.class.default_argument_configurations)
    existing_keywords = field.all_argument_definitions.map(&:keyword)
    existing_keywords.uniq!
    @added_default_arguments = []
    configs.each do |config|
      argument_args, argument_kwargs = config
      arg_name = argument_args[0]
      if !existing_keywords.include?(arg_name)
        @added_default_arguments << arg_name
        field.argument(*argument_args, **argument_kwargs)
      end
    end
  end
  if !(extras = self.class.extras).empty?
    @added_extras = extras - field.extras
    field.extras(@added_extras)
  else
    @added_extras = nil
  end
  freeze
end

def after_resolve(object:, arguments:, context:, value:, memo:)

Returns:
  • (Object) - The return value for this field.

Parameters:
  • memo (Object) -- The third value yielded by {#resolve}, or `nil` if there wasn't one
  • value (Object) -- Whatever the field previously returned
  • context (Query::Context) -- the context for this query
  • arguments (Hash) -- Ruby keyword arguments for resolving this field
  • object (Object) -- The object the field is being resolved on
def after_resolve(object:, arguments:, context:, value:, memo:)
  value
end

def apply

Returns:
  • (void) -
def apply
end

def default_argument(*argument_args, **argument_kwargs)

Other tags:
    See: HasArguments#argument -
    See: Argument#initialize -
def default_argument(*argument_args, **argument_kwargs)
  configs = @own_default_argument_configurations ||= []
  configs << [argument_args, argument_kwargs]
end

def default_argument_configurations

Returns:
  • (Array(Array, Hash), nil) - A list of default argument configs, or `nil` if there aren't any
def default_argument_configurations
  args = superclass.respond_to?(:default_argument_configurations) ? superclass.default_argument_configurations : nil
  if @own_default_argument_configurations
    if args
      args.concat(@own_default_argument_configurations)
    else
      args = @own_default_argument_configurations.dup
    end
  end
  args
end

def extras(new_extras = nil)

Returns:
  • (Array) - any extras assigned to this extension

Parameters:
  • new_extras (Array) -- If provided, assign extras used by this extension
def extras(new_extras = nil)
  if new_extras
    @own_extras = new_extras
  end
  inherited_extras = self.superclass.respond_to?(:extras) ? superclass.extras : nil
  if @own_extras
    if inherited_extras
      inherited_extras + @own_extras
    else
      @own_extras
    end
  elsif inherited_extras
    inherited_extras
  else
    GraphQL::EmptyObjects::EMPTY_ARRAY
  end
end

def initialize(field:, options:)

Parameters:
  • options (Object) -- The second argument to `extension`, or `{}` if nothing was passed.
  • field (GraphQL::Schema::Field) -- The field where this extension was mounted
def initialize(field:, options:)
  @field = field
  @options = options || {}
  @added_default_arguments = nil
  apply
end

def resolve(object:, arguments:, context:)

Returns:
  • (Object) - The return value for this field.

Other tags:
    Yieldparam: memo - Any extension-specific value which will be passed to {#after_resolve} later
    Yieldparam: arguments - The keyword arguments to continue resolving with
    Yieldparam: object - The object to continue resolving the field on

Parameters:
  • context (Query::Context) -- the context for this query
  • arguments (Hash) -- Ruby keyword arguments for resolving this field
  • object (Object) -- The object the field is being resolved on
def resolve(object:, arguments:, context:)
  yield(object, arguments, nil)
end