Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Evaluate query blocks in context of resource #130

Merged
merged 2 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.0.3

Fixes:

- [#130](https://github.com/graphiti-api/graphiti/pull/130) Run query
blocks in resource context.

## 1.0.2

Fixes:
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"

gem "rails", "~> 6.0.0.beta2"
gem "rspec-rails"
gem "sqlite3", "~> 1.3.6"
gem "sqlite3", "~> 1.4"
gem "database_cleaner"
gem "kaminari", "~> 0.17"

Expand Down
2 changes: 1 addition & 1 deletion lib/graphiti/scoping/default_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Scoping::DefaultFilter < Scoping::Base
def apply
resource.default_filters.each_pair do |name, opts|
next if overridden?(name)
@scope = opts[:filter].call(@scope, resource.context)
@scope = resource.instance_exec(@scope, resource.context, &opts[:filter])
end

@scope
Expand Down
2 changes: 1 addition & 1 deletion lib/graphiti/scoping/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def apply

def filter_scope(filter, operator, value)
if (custom_scope = filter.values[0][:operators][operator])
custom_scope.call(@scope, value, resource.context)
@resource.instance_exec(@scope, value, resource.context, &custom_scope)
else
filter_via_adapter(filter, operator, value)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphiti/scoping/paginate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def apply_standard_scope

# Apply the custom pagination proc
def apply_custom_scope
custom_scope.call(@scope, number, size, resource.context)
resource.instance_exec(@scope, number, size, resource.context, &custom_scope)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/graphiti/scoping/sort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def apply_standard_scope
attribute, sort[:only], direction
else
@scope = if sort[:proc]
sort[:proc].call(@scope, direction)
resource.instance_exec(@scope, direction, &sort[:proc])
else
resource.adapter.order(@scope, attribute, direction)
end
Expand Down