graphql-activerecord 0.10.0.pre.alpha1 → 0.10.0.pre.alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 492bdd93511565f485130b3faa32d9af36eed176
4
- data.tar.gz: bafa803ca1452a1f7ceefe66362cf4c063e06a49
3
+ metadata.gz: 1de65b95cb8f19cdca7643404e8dd55c072e2a3b
4
+ data.tar.gz: a21768845b286ae9f539725e2d7ab52002b6d3c0
5
5
  SHA512:
6
- metadata.gz: 3e5652bd12e1b46d9bb1834aa8eebe149f5e484d79d29fa7d25297121e626f0962729199dc135e532d348344f4105ca35b3f2b6be5d5c3c02aaca938f0b37edf
7
- data.tar.gz: ada3b96ec9bcdbfbdf0dee07ed79ccce4b603a7ac353a99f0b2acc65cec877f081d496e4e39a688f6d1e2a27bec5696424fd1ae6eb25efca36fefc1157c895a5
6
+ metadata.gz: 97aa43f8f65466f9b069786fbba22f7552f775c42693b3d148fdc931cd7d41606e729c4af73e75f4708a23ea4af7397b11ddf202bac57e9a501d96d787371cce
7
+ data.tar.gz: 9b541a012f17e0b7cb6dbba60110d64fcc5df04fd34eec2624d2ee7f6c91990bac411e42860b4211b62416581d5fbdf6aae5cb008b536fd7dd6712cc41870bd3
@@ -16,12 +16,20 @@ module GraphQL::Models
16
16
  # Determines if the attribute (or association) is required by examining presence validators
17
17
  # and the nullability of the column in the database
18
18
  def is_required(model_class, attr_or_assoc)
19
+ # Check for non-nullability on the column itself
19
20
  return true if model_class.columns_hash[attr_or_assoc.to_s]&.null == false
20
21
 
21
- model_class.validators_on(attr_or_assoc)
22
+ # Check for a presence validator on the association
23
+ return true if model_class.validators_on(attr_or_assoc)
22
24
  .select { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
23
25
  .reject { |v| v.options.include?(:if) || v.options.include?(:unless) }
24
26
  .any?
27
+
28
+ # If it's a belongs_to association, check for nullability on the foreign key
29
+ reflection = model_class.reflect_on_association(attr_or_assoc)
30
+ return true if reflection && reflection.macro == :belongs_to && is_required(model_class, reflection.foreign_key)
31
+
32
+ false
25
33
  end
26
34
 
27
35
  # Returns a struct that tells you the input and output GraphQL types for an attribute
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Models
3
- VERSION = "0.10.0-alpha1"
3
+ VERSION = "0.10.0-alpha2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0.pre.alpha1
4
+ version: 0.10.0.pre.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Foster