Skip to content

Commit

Permalink
refactor: rename and alias some methods for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeen committed Mar 27, 2024
1 parent 4eb2fc8 commit 0d0e218
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/graphiti/resource/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/graphiti/resource_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 : {}
Expand Down Expand Up @@ -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)
Expand All @@ -154,7 +155,7 @@ def destroy
end

def update
data
resolve_data
save(action: :update)
end

Expand Down

0 comments on commit 0d0e218

Please sign in to comment.