graphql-rails-activereflection 0.1.2 → 0.2.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65192372c0519732bbd4feadef4c4680779af4a3
|
4
|
+
data.tar.gz: 201df139d12a889ed72173a80ee6b30eb80925a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27a4d364ff9f6f62f71ce79431b3ba07635272a5f1a700417ab75b025addedfd5fdb7b8e34c487d7286b2d34439cee24bf673c178643cf6214e9477c7b217a20
|
7
|
+
data.tar.gz: 506863916e7cd22ff57f33e6c7d8ff8d0742d509e096f9072a1c1719a6ef9bc6e561511087e521ba4e649decf647cca5e30e2ebb47e9fcfa343ab0cfc162e6c8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,12 +28,12 @@ And that's it! This will add a `_model` field to the object type and enables the
|
|
28
28
|
|
29
29
|
```graphql
|
30
30
|
fragment on YourObjectType {
|
31
|
-
_model {
|
32
|
-
attributes {
|
31
|
+
_model: ActiveReflectionModel {
|
32
|
+
attributes: [ActiveReflectionAttribute] {
|
33
33
|
name: String
|
34
34
|
field_name: String
|
35
35
|
|
36
|
-
validators {
|
36
|
+
validators: [ActiveReflectionValidator] {
|
37
37
|
absence: Boolean
|
38
38
|
presence: Boolean
|
39
39
|
uniqueness: Boolean
|
@@ -45,7 +45,7 @@ fragment on YourObjectType {
|
|
45
45
|
exclusion: [String]
|
46
46
|
}
|
47
47
|
|
48
|
-
validate(int: Integer, str: String, float: Float, bool: Boolean) {
|
48
|
+
validate(int: Integer, str: String, float: Float, bool: Boolean): ActiveReflectionValidation {
|
49
49
|
valid: Boolean
|
50
50
|
errors: [String]
|
51
51
|
}
|
@@ -12,17 +12,27 @@ module GraphQL::Rails::ActiveReflection
|
|
12
12
|
@klass = klass
|
13
13
|
@field_name = field.name
|
14
14
|
@name = field.property || field.name
|
15
|
-
@
|
15
|
+
@errors = []
|
16
|
+
get_validators
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_accessor :schema_name
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def get_validators
|
26
|
+
@validators ||= klass.validators.map { |validator|
|
16
27
|
# Skip if the validator does not apply to this field
|
17
28
|
# Skip if there are :if or :unless options (conditionals purposely unsupported)
|
18
|
-
next
|
29
|
+
next unless include_validator? validator
|
19
30
|
GraphQL::Rails::ActiveReflection::ValidatorReflection.new(validator)
|
20
31
|
}.compact
|
21
|
-
@errors = []
|
22
32
|
end
|
23
33
|
|
24
|
-
|
25
|
-
|
34
|
+
def include_validator? validator
|
35
|
+
validator.attributes.include?(@name.to_sym) && validator.options[:if].nil? && validator.options[:unless].nil?
|
26
36
|
end
|
27
37
|
end
|
28
38
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module GraphQL::Rails::ActiveReflection
|
2
2
|
class ModelReflection
|
3
3
|
@schema_name = "ActiveReflectionModel"
|
4
|
-
|
4
|
+
@@reflections = {}
|
5
5
|
|
6
6
|
def self.call(obj, args, ctx)
|
7
7
|
raise TypeError, "ActiveReflection object type must be derived from ActiveRecord::Base" unless obj.is_a?(ActiveRecord::Base)
|
8
|
-
|
8
|
+
@@reflections[obj] ||= new(obj, ctx)
|
9
9
|
end
|
10
10
|
|
11
11
|
attr_reader :attributes
|
@@ -14,17 +14,26 @@ module GraphQL::Rails::ActiveReflection
|
|
14
14
|
@klass = obj.class
|
15
15
|
@type = ctx.schema.resolve_type(obj, ctx)
|
16
16
|
@schema = ctx.schema
|
17
|
-
|
17
|
+
get_attributes
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_accessor :schema_name
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
def get_attributes
|
26
|
+
@attributes ||= @type.fields.map { |name, field|
|
18
27
|
# No reflection if it's not a model attribute
|
19
28
|
property = field.property || name
|
20
|
-
if
|
29
|
+
if include_property? property
|
21
30
|
GraphQL::Rails::ActiveReflection::AttributeReflection.new(field, @klass, @schema)
|
22
31
|
end
|
23
32
|
}.compact
|
24
33
|
end
|
25
34
|
|
26
|
-
|
27
|
-
|
35
|
+
def include_property? name
|
36
|
+
@klass.attribute_names.include? name
|
28
37
|
end
|
29
38
|
|
30
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-rails-activereflection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cole Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
|
-
type: :
|
40
|
+
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
-
type: :
|
54
|
+
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|