graphiti 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77a0b8b5d8df9c67801e64943896e8ab1641626c7819548839f07ec498242fb7
4
- data.tar.gz: 33c1ee5fe14d815a9d1bb4bf2763d468d613a22ac7f8417a827ddb19623d2de8
3
+ metadata.gz: 501d03b06258694566979a6f54104d8da41a44ab6dadec078e7b84ef047de364
4
+ data.tar.gz: cb85e65ffb73f9294cd0173eee9a0f2e8239697dac1a83adbe58a2faf9c6cbe9
5
5
  SHA512:
6
- metadata.gz: a75fed69be79eba1cc5b892c55a6b452683164666fb96597e119b36100b7de98dd2671615ea6bba208e75e084697b03ec1b35850a8cefe431c5dd2edfe6a9c93
7
- data.tar.gz: 169cb3b32f2ce23767e4a158da84d5b0b307ed3ee6c834b059237b59ca6b711b727c4449a6ed7fa8055a33e561bca0a258a007753a2c65359fa47b11cc20abee
6
+ metadata.gz: 917d60f26882a2efbcebcf80279aa624b795628d6ad6fdc201dd8c4511e3a7caf6979fbf24c870aa176827dfe7daeffef0a1b5e5e73cec8d83bec98761ad1a9f
7
+ data.tar.gz: 1028dc0fe60eb8b4b54f119ccb12308390ff849c48047f6597e4149dbf6123aae296299d231fde9fa3469c023d7caa86b9e5ce334dc079547932ba886512e38e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.0.3
2
+
3
+ Fixes:
4
+
5
+ - [#130](https://github.com/graphiti-api/graphiti/pull/130) Run query
6
+ blocks in resource context.
7
+
1
8
  ## 1.0.2
2
9
 
3
10
  Fixes:
@@ -13,6 +20,11 @@ Fixes:
13
20
 
14
21
  ### master (unreleased)
15
22
 
23
+ Misc:
24
+
25
+ - [#123](https://github.com/graphiti-api/graphiti/pull/123) Throw
26
+ better error when polymorphic type not found.
27
+
16
28
  <!-- ### [version (YYYY-MM-DD)](diff_link) -->
17
29
  <!-- Breaking changes:-->
18
30
  <!-- Features:-->
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.0.0.beta2"
6
6
  gem "rspec-rails"
7
- gem "sqlite3", "~> 1.3.6"
7
+ gem "sqlite3", "~> 1.4"
8
8
  gem "database_cleaner"
9
9
  gem "kaminari", "~> 0.17"
10
10
 
@@ -561,6 +561,28 @@ module Graphiti
561
561
  end
562
562
  end
563
563
 
564
+ class PolymorphicSideloadTypeNotFound < Base
565
+ def initialize(sideload, name)
566
+ @sideload = sideload
567
+ @name = name
568
+ end
569
+
570
+ def message
571
+ <<~MSG
572
+ #{@sideload.parent_resource}: Tried to find a Resource with type '#{@name.inspect}', but did not find one!
573
+
574
+ This is because either a Resource with that type doesn't exist, or it's not registered on the sideload. The below example shows how to register a Resource with this sideload. Make sure one of the registered Resources has type '#{@name.inspect}'
575
+
576
+ polymorphic_belongs_to #{@sideload.name.inspect} do
577
+ group_by(#{@sideload.grouper.field_name.inspect}) do
578
+ on(:foo)
579
+ on(:foo).belongs_to :foo, resource: FooResource # (long-hand example)
580
+ end
581
+ end
582
+ MSG
583
+ end
584
+ end
585
+
564
586
  class PolymorphicSideloadChildNotFound < Base
565
587
  def initialize(sideload, name)
566
588
  @sideload = sideload
@@ -38,7 +38,7 @@ module Graphiti
38
38
  def apply
39
39
  resource.default_filters.each_pair do |name, opts|
40
40
  next if overridden?(name)
41
- @scope = opts[:filter].call(@scope, resource.context)
41
+ @scope = resource.instance_exec(@scope, resource.context, &opts[:filter])
42
42
  end
43
43
 
44
44
  @scope
@@ -23,7 +23,7 @@ module Graphiti
23
23
 
24
24
  def filter_scope(filter, operator, value)
25
25
  if (custom_scope = filter.values[0][:operators][operator])
26
- custom_scope.call(@scope, value, resource.context)
26
+ @resource.instance_exec(@scope, value, resource.context, &custom_scope)
27
27
  else
28
28
  filter_via_adapter(filter, operator, value)
29
29
  end
@@ -38,7 +38,7 @@ module Graphiti
38
38
 
39
39
  # Apply the custom pagination proc
40
40
  def apply_custom_scope
41
- custom_scope.call(@scope, number, size, resource.context)
41
+ resource.instance_exec(@scope, number, size, resource.context, &custom_scope)
42
42
  end
43
43
 
44
44
  private
@@ -29,7 +29,7 @@ module Graphiti
29
29
  attribute, sort[:only], direction
30
30
  else
31
31
  @scope = if sort[:proc]
32
- sort[:proc].call(@scope, direction)
32
+ resource.instance_exec(@scope, direction, &sort[:proc])
33
33
  else
34
34
  resource.adapter.order(@scope, attribute, direction)
35
35
  end
@@ -99,6 +99,15 @@ class Graphiti::Sideload::PolymorphicBelongsTo < Graphiti::Sideload::BelongsTo
99
99
  end
100
100
  end
101
101
 
102
+ def child_for_type!(type)
103
+ if (child = child_for_type(type))
104
+ child
105
+ else
106
+ err = ::Graphiti::Errors::PolymorphicSideloadTypeNotFound
107
+ raise err.new(self, type)
108
+ end
109
+ end
110
+
102
111
  def resolve(parents, query, graph_parent)
103
112
  parents.group_by(&grouper.field_name).each_pair do |group_name, group|
104
113
  next if group_name.nil? || grouper.ignore?(group_name)
@@ -47,7 +47,7 @@ module Graphiti
47
47
 
48
48
  # For polymorphic *sideloads*, grab the correct child sideload
49
49
  if sideload.resource.type != type && sideload.type == :polymorphic_belongs_to
50
- sideload = sideload.child_for_type(type)
50
+ sideload = sideload.child_for_type!(type)
51
51
  end
52
52
 
53
53
  # For polymorphic *resources*, grab the correct child resource
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-19 00:00:00.000000000 Z
11
+ date: 2019-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable