Class: GraphqlRails::Model::CallGraphqlModelMethod

Inherits:
Object
  • Object
show all
Includes:
Service
Defined in:
lib/graphql_rails/model/call_graphql_model_method.rb

Overview

Executes model method and adds additional meta data if needed

Constant Summary collapse

PAGINATION_KEYS =
%i[before after first last].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.instance_cacheObject (readonly)

Returns the value of attribute instance_cache.



16
17
18
# File 'lib/graphql_rails/model/call_graphql_model_method.rb', line 16

def instance_cache
  @instance_cache
end

Class Method Details

.call(*_args, **kwargs) ⇒ Object



18
19
20
21
22
# File 'lib/graphql_rails/model/call_graphql_model_method.rb', line 18

def call(*_args, **kwargs)
  cache_key = kwargs[:attribute_config].object_id
  @instance_cache[cache_key] ||= new
  @instance_cache[cache_key].call_with_args(**kwargs)
end

Instance Method Details

#call_with_args(model:, method_keyword_arguments:, graphql_context:, attribute_config:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/graphql_rails/model/call_graphql_model_method.rb', line 25

def call_with_args(model:, method_keyword_arguments:, graphql_context:, attribute_config:)
  @model = model
  @method_keyword_arguments = method_keyword_arguments
  @graphql_context = graphql_context
  @attribute_config = attribute_config

  with_graphql_context do
    run_method
  end
end