Class: GraphQL::Query::FieldResolutionStrategy
- Inherits:
-
Object
- Object
- GraphQL::Query::FieldResolutionStrategy
- Defined in:
- lib/graph_ql/query/field_resolution_strategy.rb
Defined Under Namespace
Classes: EnumResolutionStrategy, ListResolutionStrategy, NonNullResolutionStrategy, ObjectResolutionStrategy, ScalarResolutionStrategy
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#result_value ⇒ Object
readonly
Returns the value of attribute result_value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ast_field, parent_type, target, operation_resolver) ⇒ FieldResolutionStrategy
constructor
A new instance of FieldResolutionStrategy.
Constructor Details
#initialize(ast_field, parent_type, target, operation_resolver) ⇒ FieldResolutionStrategy
Returns a new instance of FieldResolutionStrategy.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graph_ql/query/field_resolution_strategy.rb', line 4 def initialize(ast_field, parent_type, target, operation_resolver) field_name = ast_field.name field = operation_resolver.query.schema.get_field(parent_type, field_name) || raise("No field found on #{parent_type.name} '#{parent_type}' for '#{field_name}'") arguments = GraphQL::Query::Arguments.new(ast_field.arguments, field.arguments, operation_resolver.variables) value = field.resolve(target, arguments, operation_resolver.context) if value.nil? @result_value = value else if value == GraphQL::Query::DEFAULT_RESOLVE begin value = target.send(field_name) rescue NoMethodError => err raise("Couldn't resolve field '#{field_name}' to #{target.class} '#{target}' (resulted in #{err})") end end resolved_type = field.type.kind.resolve(field.type, value) strategy_class = self.class.get_strategy_for_kind(resolved_type.kind) result_strategy = strategy_class.new(value, resolved_type, target, parent_type, ast_field, operation_resolver) @result_value = result_strategy.result end result_name = ast_field.alias || ast_field.name @result = { result_name => @result_value} end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
2 3 4 |
# File 'lib/graph_ql/query/field_resolution_strategy.rb', line 2 def result @result end |
#result_value ⇒ Object (readonly)
Returns the value of attribute result_value.
2 3 4 |
# File 'lib/graph_ql/query/field_resolution_strategy.rb', line 2 def result_value @result_value end |
Class Method Details
.get_strategy_for_kind(kind) ⇒ Object
28 29 30 |
# File 'lib/graph_ql/query/field_resolution_strategy.rb', line 28 def self.get_strategy_for_kind(kind) FIELD_TYPE_KIND_STRATEGIES[kind] || raise("No strategy for #{kind}") end |