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 +4 -4
- data/lib/graphql/models/reflection.rb +9 -1
- data/lib/graphql/models/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1de65b95cb8f19cdca7643404e8dd55c072e2a3b
|
4
|
+
data.tar.gz: a21768845b286ae9f539725e2d7ab52002b6d3c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|