From d3217af55a412f65c86d600865c5cbcac06ee397 Mon Sep 17 00:00:00 2001 From: Lee Richmond Date: Thu, 25 Apr 2019 16:30:19 -0400 Subject: [PATCH 1/2] Evaluate query blocks in context of resource --- CHANGELOG.md | 7 +++++++ lib/graphiti/scoping/default_filter.rb | 2 +- lib/graphiti/scoping/filter.rb | 2 +- lib/graphiti/scoping/paginate.rb | 2 +- lib/graphiti/scoping/sort.rb | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce0a27fa..96630aee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/lib/graphiti/scoping/default_filter.rb b/lib/graphiti/scoping/default_filter.rb index 4f60a379..7208f3d9 100644 --- a/lib/graphiti/scoping/default_filter.rb +++ b/lib/graphiti/scoping/default_filter.rb @@ -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 diff --git a/lib/graphiti/scoping/filter.rb b/lib/graphiti/scoping/filter.rb index 7292042e..eefb40c3 100644 --- a/lib/graphiti/scoping/filter.rb +++ b/lib/graphiti/scoping/filter.rb @@ -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 diff --git a/lib/graphiti/scoping/paginate.rb b/lib/graphiti/scoping/paginate.rb index 3e45d7e6..8a0a355f 100644 --- a/lib/graphiti/scoping/paginate.rb +++ b/lib/graphiti/scoping/paginate.rb @@ -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 diff --git a/lib/graphiti/scoping/sort.rb b/lib/graphiti/scoping/sort.rb index a931b89c..c6c3206e 100644 --- a/lib/graphiti/scoping/sort.rb +++ b/lib/graphiti/scoping/sort.rb @@ -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 From 2ecf1365b0b1e4d0fe35f3c97028507ee147545e Mon Sep 17 00:00:00 2001 From: Lee Richmond Date: Thu, 25 Apr 2019 16:56:27 -0400 Subject: [PATCH 2/2] Attempt to fix travis --- gemfiles/rails_6.gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/rails_6.gemfile b/gemfiles/rails_6.gemfile index dd55fbb8..58b932cd 100644 --- a/gemfiles/rails_6.gemfile +++ b/gemfiles/rails_6.gemfile @@ -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"