Module: EPlat::Concerns::GraphQLable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/e_plat/resource/concerns/graph_q_lable.rb
Constant Summary collapse
- FILTER_ARGS =
[:id, :after, :before, :last, :first, :sort_key, :reverse].freeze
- QUERY_ARG_ARGS =
[:available_for_sale, :created_at, :product_type, :product_id, :tag, :tag_not, :title, :updated_at, :vendor].freeze
Instance Method Summary collapse
- #graphql_mutation_string(graphql_proc_constant, action) ⇒ Object
- #mutate_graphql(action, graphql_proc_constant, *args) ⇒ Object
- #remove_mutation_root_from(data, graphql_proc_constant) ⇒ Object
Instance Method Details
#graphql_mutation_string(graphql_proc_constant, action) ⇒ Object
245 246 247 248 249 250 251 252 |
# File 'lib/e_plat/resource/concerns/graph_q_lable.rb', line 245 def graphql_mutation_string(graphql_proc_constant, action) mutation_proc = eval graphql_proc_constant input = graphql_input.mutation_input(self, action) additional_graphql = self.class.before_graphql_callbacks[action.to_sym]&.call(self) mutation_proc.call(input, additional_graphql:) end |
#mutate_graphql(action, graphql_proc_constant, *args) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/e_plat/resource/concerns/graph_q_lable.rb', line 217 def mutate_graphql(action, graphql_proc_constant, *args) callback_name = (action == :delete) ? :destroy : action run_callbacks callback_name.to_sym do response = self.class.execute_graphql_request graphql_mutation_string(graphql_proc_constant, action) if !response.is_a?(Hash) raise EPlat::GraphqlError.new(response.first["message"]) elsif response["errors"] raise EPlat::GraphqlError.new(response["errors"].first["message"]) else response = remove_mutation_root_from(response, graphql_proc_constant) parsed_response = self.class.resources_parsed_from(response) if parsed_response.is_a?(Array) load parsed_response.first, true, true else load parsed_response, true, true end @persisted = true changed_attributes.clear end end rescue StandardError => e raise EPlat::GraphqlError.new(e.) end |
#remove_mutation_root_from(data, graphql_proc_constant) ⇒ Object
254 255 256 257 |
# File 'lib/e_plat/resource/concerns/graph_q_lable.rb', line 254 def remove_mutation_root_from(data, graphql_proc_constant) mutation_root = graphql_proc_constant.split(".").last.camelcase(:lower) (mutation_root && data[mutation_root]) ? data[mutation_root] : data end |