class GraphqlRails::Model::CallGraphqlModelMethod
Executes model method and adds additional meta data if needed
Constants
- PAGINATION_KEYS
Attributes
attribute_config[R]
graphql_context[R]
method_keyword_arguments[R]
model[R]
Public Class Methods
new(model:, method_keyword_arguments:, graphql_context:, attribute_config:)
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 13 def initialize(model:, method_keyword_arguments:, graphql_context:, attribute_config:) @model = model @method_keyword_arguments = method_keyword_arguments @graphql_context = graphql_context @attribute_config = attribute_config end
Public Instance Methods
call()
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 20 def call with_graphql_context do run_method end end
Private Instance Methods
custom_keyword_arguments()
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 59 def custom_keyword_arguments return method_keyword_arguments unless paginated? method_keyword_arguments.except(*PAGINATION_KEYS) end
formatted_method_input(keyword_arguments)
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 39 def formatted_method_input(keyword_arguments) keyword_arguments.transform_values do |input_argument| formatted_method_input_argument(input_argument) end end
formatted_method_input_argument(argument)
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 45 def formatted_method_input_argument(argument) return argument.to_h if argument.is_a?(GraphQL::Schema::InputObject) argument end
method_name()
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 51 def method_name attribute_config.property end
paginated?()
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 55 def paginated? attribute_config.paginated? end
run_method()
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 30 def run_method if custom_keyword_arguments.empty? model.send(method_name) else formatted_arguments = formatted_method_input(custom_keyword_arguments) model.send(method_name, **formatted_arguments) end end
with_graphql_context() { || ... }
click to toggle source
# File lib/graphql_rails/model/call_graphql_model_method.rb, line 65 def with_graphql_context return yield unless model.respond_to?(:with_graphql_context) model.with_graphql_context(graphql_context) { yield } end