From 0d0e218f9db9b2365ca04fa5abbee6c802f8b820 Mon Sep 17 00:00:00 2001 From: Jeff Keen Date: Wed, 27 Mar 2024 17:19:42 -0500 Subject: [PATCH] refactor: rename and alias some methods for clarity --- lib/graphiti/resource/interface.rb | 8 ++++---- lib/graphiti/resource_proxy.rb | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/graphiti/resource/interface.rb b/lib/graphiti/resource/interface.rb index b424b064..b79a31a2 100644 --- a/lib/graphiti/resource/interface.rb +++ b/lib/graphiti/resource/interface.rb @@ -5,7 +5,7 @@ module Interface class_methods do def all(params = {}, base_scope = nil) - validate!(params) + validate_request!(params) _all(params, {}, base_scope) end @@ -17,7 +17,7 @@ def _all(params, opts, base_scope) end def find(params = {}, base_scope = nil) - validate!(params) + validate_request!(params) _find(params, base_scope) end @@ -38,14 +38,14 @@ def _find(params = {}, base_scope = nil) end def build(params, base_scope = nil) - validate!(params) + validate_request!(params) runner = Runner.new(self, params) runner.proxy(base_scope, single: true, raise_on_missing: true) end private - def validate!(params) + def validate_request!(params) return if Graphiti.context[:graphql] || !validate_endpoints? if context&.respond_to?(:request) diff --git a/lib/graphiti/resource_proxy.rb b/lib/graphiti/resource_proxy.rb index d03105be..4372ce9c 100644 --- a/lib/graphiti/resource_proxy.rb +++ b/lib/graphiti/resource_proxy.rb @@ -74,6 +74,7 @@ def data end end alias_method :to_a, :data + alias_method :resolve_data, :data def meta @meta ||= data.respond_to?(:meta) ? data.meta : {} @@ -136,7 +137,7 @@ def save(action: :create) end def destroy - data + resolve_data transaction_response = @resource.transaction do metadata = {method: :destroy} model = @resource.destroy(@query.filters[:id], metadata) @@ -154,7 +155,7 @@ def destroy end def update - data + resolve_data save(action: :update) end