graphiti_gql 0.2.25 → 0.2.26

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: ae5d9ce0fe34ef8d53204f8c292b5d09cb58c821ec413804a169e3a562061ad2
4
- data.tar.gz: 02fc540e3203efe6311fba2d30c3b8b75308103cffe4b5df1f01b29dac804e74
3
+ metadata.gz: 00d26d5be2b1e9f1f277e0d0922faec91599f72a28fabe77ff16fb1f2ae6870f
4
+ data.tar.gz: a868703b6bf2a2fbf88464396f0fe17ba836ffc183cee22e2aad06b5bd6a1223
5
5
  SHA512:
6
- metadata.gz: e01483c436cbc15cb0c80598725a16440ba0254242554c9a2401c4dd72ca5cd4b847941fe3d02da7a4d023640b7ca20824e2537a04654dc2d46c192e53885863
7
- data.tar.gz: 13478f1634bcb76c13cf9aef90c036fb5636a55c72643db21e854cca9679c4c735e848c6245e73d2194374fa54ee34eecda4cc17240f5cbe491acf14a0ef9db9
6
+ metadata.gz: 02f91817b443a31d0eaa280316ddd1ab18691936e401c431a38354370f8a6a1b435076fa022df6d37041f35e08d06fb99fc8104aa957cca4e3b9507bba828117
7
+ data.tar.gz: 94ca96b977800303c54ecf61fabfeeca65c4b839fc1ae501e6192fdbb30af86181a1aada59d64a47339c28ff3ca4e5469d071a27db9280a59e8c0b339b0f70f6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphiti_gql (0.2.25)
4
+ graphiti_gql (0.2.26)
5
5
  activemodel (> 6.0, < 8.0)
6
6
  graphiti (~> 1.3.9)
7
7
  graphql (~> 2.0)
@@ -131,7 +131,7 @@ module GraphitiGql
131
131
 
132
132
  def value_object(name, opts = {})
133
133
  opts[:array] ||= false
134
- opts[:null] ||= true
134
+ opts[:null] = true if opts[:null] != false
135
135
  config[:value_objects][name] = Graphiti::ValueObjectAssociation.new(
136
136
  name,
137
137
  parent_resource_class: self,
@@ -438,6 +438,7 @@ module GraphitiGql
438
438
 
439
439
  def resolve(*args)
440
440
  results = super
441
+ raise Graphiti::Errors::InvalidResolve unless results.is_a?(Array)
441
442
  results.reverse! if @query.hash[:reverse]
442
443
  results
443
444
  end
@@ -458,6 +459,24 @@ module GraphitiGql
458
459
  end
459
460
  end
460
461
 
462
+ class Graphiti::Errors::InvalidResolve < Graphiti::Errors::Base
463
+ def message
464
+ "Resource#resolve must always return an array"
465
+ end
466
+ end
467
+
468
+ class Graphiti::Errors::InvalidValueObject < Graphiti::Errors::Base
469
+ def initialize(resource, name, value)
470
+ @resource = resource
471
+ @name = name
472
+ @value = value
473
+ end
474
+
475
+ def message
476
+ "#{@resource} - value object '#{@name}' configured with array: true but returned non-array: #{@value.inspect}"
477
+ end
478
+ end
479
+
461
480
  class Graphiti::ValueObjectAssociation
462
481
  attr_reader :name,
463
482
  :parent_resource_class,
@@ -44,12 +44,14 @@ module GraphitiGql
44
44
  end
45
45
 
46
46
  result = vo_resource_class.all({ parent: object }).to_a
47
- if result.is_a?(Array) && !_array
48
- result = result.first
49
- end
50
- if result == object || result == [object]
47
+ default_behavior = result == [object]
48
+ result = result.first if !_array
49
+ if default_behavior
51
50
  method_name = vo_association.alias.presence || name
52
51
  result = object.send(method_name)
52
+ if _array && !result.is_a?(Array)
53
+ raise Graphiti::Errors::InvalidValueObject.new(resource, name, result)
54
+ end
53
55
  end
54
56
  result
55
57
  end
@@ -1,3 +1,3 @@
1
1
  module GraphitiGql
2
- VERSION = "0.2.25"
2
+ VERSION = "0.2.26"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti_gql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.25
4
+ version: 0.2.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-12 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql