Class: GraphQL::Decorate::Decoration

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/decorate/decoration.rb

Overview

Handles decorating an value at runtime given its current field.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(undecorated_field) ⇒ Decoration

Returns a new instance of Decoration.

Parameters:



15
16
17
# File 'lib/graphql/decorate/decoration.rb', line 15

def initialize(undecorated_field)
  @undecorated_field = undecorated_field
end

Class Method Details

.decorate(undecorated_field) ⇒ Object

Resolve the undecorated_field.value with decoration.

Parameters:

Returns:

  • (Object)

    Decorated undecorated_field.value if possible, otherwise the original undecorated_field.value.



10
11
12
# File 'lib/graphql/decorate/decoration.rb', line 10

def self.decorate(undecorated_field)
  new(undecorated_field).decorate
end

Instance Method Details

#decorateObject

Returns Decorated undecorated_field.value if possible, otherwise the original undecorated_field.value.

Returns:

  • (Object)

    Decorated undecorated_field.value if possible, otherwise the original undecorated_field.value.



20
21
22
23
24
25
26
27
# File 'lib/graphql/decorate/decoration.rb', line 20

def decorate
  if undecorated_field.decorator_class
    GraphQL::Decorate.configuration.evaluate_decorator.call(undecorated_field.decorator_class,
                                                            undecorated_field.value, undecorated_field.)
  else
    undecorated_field.value
  end
end