graphql-rails-activereflection 0.1.0 → 0.1.2
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/README.md +7 -3
- data/lib/graphql/rails.rb +8 -0
- data/lib/graphql/rails/active_reflection.rb +12 -38
- data/lib/graphql/rails/active_reflection/attribute_reflection.rb +22 -25
- data/lib/graphql/rails/active_reflection/model.rb +30 -0
- data/lib/graphql/rails/active_reflection/model_reflection.rb +23 -26
- data/lib/graphql/rails/active_reflection/types/attribute_reflection_type.rb +19 -28
- data/lib/graphql/rails/active_reflection/types/model_reflection_type.rb +3 -11
- data/lib/graphql/rails/active_reflection/types/validation_result_type.rb +4 -12
- data/lib/graphql/rails/active_reflection/types/validator_type.rb +12 -76
- data/lib/graphql/rails/active_reflection/validation_result.rb +11 -15
- data/lib/graphql/rails/active_reflection/validator_reflection.rb +74 -50
- data/lib/graphql/rails/active_reflection/version.rb +7 -0
- metadata +19 -3
- data/lib/graphql/rails/active_reflection/types.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a81c1a5d660000185c3ed8b045308b24c0281982
|
4
|
+
data.tar.gz: fc4b2c58c1c69f13e64ec79ec0707ff0f35a2d77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a52d0ba5587ce4af06e4cd7d1e3c656d64319e3eb2613009919e750403fb482fdaa08f394edb6b8a9eb5cce4063ee76738ab1f9cd35bb86c1b69af9b0a064d0
|
7
|
+
data.tar.gz: fcdd14e32bc65f505330aa30e5332d22fb46edf5ba9db87bb2c81efdb730a014947c767a510c258e4555df54ec94d0cd50720641a522e6f5d2c41d8ec20e8fa7
|
data/README.md
CHANGED
@@ -30,11 +30,12 @@ And that's it! This will add a `_model` field to the object type and enables the
|
|
30
30
|
fragment on YourObjectType {
|
31
31
|
_model {
|
32
32
|
attributes {
|
33
|
-
name
|
33
|
+
name: String
|
34
|
+
field_name: String
|
34
35
|
|
35
36
|
validators {
|
36
|
-
|
37
|
-
|
37
|
+
absence: Boolean
|
38
|
+
presence: Boolean
|
38
39
|
uniqueness: Boolean
|
39
40
|
with_format: String
|
40
41
|
without_format: String
|
@@ -53,6 +54,9 @@ fragment on YourObjectType {
|
|
53
54
|
}
|
54
55
|
```
|
55
56
|
|
57
|
+
The `_model` field will resolve to whatever type `Schema.resolve_type` returns for that object.
|
58
|
+
Only the fields on that type will be exposed as `attributes` - where `name` is the attribute name and `field_name` is the field name that exposed the attribute.
|
59
|
+
|
56
60
|
Each of the validators corresponds to the standard Rails validators. Almost all validators for an attribute will be returned, **except those that have the `if` or `unless` conditionals.** This is by design and therefore make note that any conditional validations will have to be performed manually.
|
57
61
|
|
58
62
|
There is also the `validate(...)` field with arguments for standard scalar types. Any one of the arguments can be provided, but only one. The result will contain a `valid` boolean and a list of `errors` strings returned from the validators.
|
@@ -1,42 +1,16 @@
|
|
1
|
-
|
1
|
+
module GraphQL::Rails
|
2
|
+
module ActiveReflection
|
3
|
+
module Types; end
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'graphql/rails/active_reflection/version'
|
8
|
+
require 'graphql/rails/active_reflection/model'
|
2
9
|
require 'graphql/rails/active_reflection/model_reflection'
|
3
10
|
require 'graphql/rails/active_reflection/attribute_reflection'
|
4
11
|
require 'graphql/rails/active_reflection/validation_result'
|
5
12
|
require 'graphql/rails/active_reflection/validator_reflection'
|
6
|
-
require 'graphql/rails/active_reflection/types'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
module ActiveReflection
|
11
|
-
VERSION = '0.1.0'
|
12
|
-
|
13
|
-
class UnsupportedObject < StandardError; end
|
14
|
-
|
15
|
-
class Model
|
16
|
-
def self.interface
|
17
|
-
@interface ||= GraphQL::InterfaceType.define do
|
18
|
-
name "ActiveReflectionInterface"
|
19
|
-
field('_model', ModelReflectionType, 'Model of attributes for field.')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.field(**kwargs, &block)
|
24
|
-
# We have to define it fresh each time because
|
25
|
-
# its name will be modified and its description
|
26
|
-
# _may_ be modified.
|
27
|
-
field = GraphQL::Field.define do
|
28
|
-
type(GraphQL::Rails::ActiveReflection::Model.interface)
|
29
|
-
description('Fetch the content model for the given object.')
|
30
|
-
resolve(ModelReflection)
|
31
|
-
end
|
32
|
-
|
33
|
-
if kwargs.any? || block
|
34
|
-
field = field.redefine(kwargs, &block)
|
35
|
-
end
|
36
|
-
|
37
|
-
field
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
13
|
+
require 'graphql/rails/active_reflection/types/model_reflection_type'
|
14
|
+
require 'graphql/rails/active_reflection/types/attribute_reflection_type'
|
15
|
+
require 'graphql/rails/active_reflection/types/validation_result_type'
|
16
|
+
require 'graphql/rails/active_reflection/types/validator_type'
|
@@ -1,31 +1,28 @@
|
|
1
|
-
module GraphQL
|
2
|
-
|
3
|
-
|
4
|
-
class AttributeReflection
|
5
|
-
@schema_name = "ActiveReflectionAttribute"
|
1
|
+
module GraphQL::Rails::ActiveReflection
|
2
|
+
class AttributeReflection
|
3
|
+
@schema_name = "ActiveReflectionAttribute"
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
attr_reader :klass
|
6
|
+
attr_reader :name
|
7
|
+
attr_reader :field_name
|
8
|
+
attr_reader :description
|
9
|
+
attr_reader :validators
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
11
|
+
def initialize(field, klass, schema)
|
12
|
+
@klass = klass
|
13
|
+
@field_name = field.name
|
14
|
+
@name = field.property || field.name
|
15
|
+
@validators = klass.validators.map { |validator|
|
16
|
+
# Skip if the validator does not apply to this field
|
17
|
+
# Skip if there are :if or :unless options (conditionals purposely unsupported)
|
18
|
+
next if validator.attributes.exclude?(@name.to_sym) || validator.options[:if].present? || validator.options[:unless].present?
|
19
|
+
GraphQL::Rails::ActiveReflection::ValidatorReflection.new(validator)
|
20
|
+
}.compact
|
21
|
+
@errors = []
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
24
|
+
class << self
|
25
|
+
attr_accessor :schema_name
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module GraphQL::Rails::ActiveReflection
|
2
|
+
class Model
|
3
|
+
def self.interface
|
4
|
+
@interface ||= GraphQL::InterfaceType.define do
|
5
|
+
name "ActiveReflectionInterface"
|
6
|
+
field('_model', GraphQL::Rails::ActiveReflection::Types::ModelReflectionType, 'Model of attributes for field.') do
|
7
|
+
description('Fetch the content model for the given object.')
|
8
|
+
resolve(GraphQL::Rails::ActiveReflection::ModelReflection)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.field(**kwargs, &block)
|
14
|
+
# We have to define it fresh each time because
|
15
|
+
# its name will be modified and its description
|
16
|
+
# _may_ be modified.
|
17
|
+
field = GraphQL::Field.define do
|
18
|
+
type(GraphQL::Rails::ActiveReflection::Model.interface)
|
19
|
+
description('Fetch the content model for the given object.')
|
20
|
+
resolve(GraphQL::Rails::ActiveReflection::ModelReflection)
|
21
|
+
end
|
22
|
+
|
23
|
+
if kwargs.any? || block
|
24
|
+
field = field.redefine(kwargs, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
field
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,34 +1,31 @@
|
|
1
|
-
module GraphQL
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
@schema_name = "ActiveReflectionModel"
|
1
|
+
module GraphQL::Rails::ActiveReflection
|
2
|
+
class ModelReflection
|
3
|
+
@schema_name = "ActiveReflectionModel"
|
4
|
+
@reflections = {}
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
attr_reader :attributes
|
6
|
+
def self.call(obj, args, ctx)
|
7
|
+
raise TypeError, "ActiveReflection object type must be derived from ActiveRecord::Base" unless obj.is_a?(ActiveRecord::Base)
|
8
|
+
@reflections[obj] ||= new(obj, ctx)
|
9
|
+
end
|
13
10
|
|
14
|
-
|
15
|
-
@klass = klass
|
16
|
-
@type = schema.resolve_type(@klass)
|
17
|
-
@schema = schema
|
18
|
-
@attributes = @type.fields.map { |field|
|
19
|
-
# No reflection if it's not a model attribute
|
20
|
-
property = field.property || field.name
|
21
|
-
return nil unless klass.attribute_names.include? property
|
11
|
+
attr_reader :attributes
|
22
12
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
def initialize(obj, ctx)
|
14
|
+
@klass = obj.class
|
15
|
+
@type = ctx.schema.resolve_type(obj, ctx)
|
16
|
+
@schema = ctx.schema
|
17
|
+
@attributes = @type.fields.map { |name, field|
|
18
|
+
# No reflection if it's not a model attribute
|
19
|
+
property = field.property || name
|
20
|
+
if @klass.attribute_names.include? property
|
21
|
+
GraphQL::Rails::ActiveReflection::AttributeReflection.new(field, @klass, @schema)
|
29
22
|
end
|
23
|
+
}.compact
|
24
|
+
end
|
30
25
|
|
31
|
-
|
26
|
+
class << self
|
27
|
+
attr_accessor :schema_name
|
32
28
|
end
|
29
|
+
|
33
30
|
end
|
34
31
|
end
|
@@ -1,36 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module ActiveReflection
|
4
|
-
module Types
|
1
|
+
GraphQL::Rails::ActiveReflection::Types::AttributeReflectionType = GraphQL::ObjectType.define do
|
2
|
+
name GraphQL::Rails::ActiveReflection::AttributeReflection.schema_name
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
field :name, !types.String
|
5
|
+
field :field_name, !types.String
|
6
|
+
field :validators, GraphQL::Rails::ActiveReflection::Types::ValidatorType.to_list_type
|
7
|
+
field :validate, GraphQL::Rails::ActiveReflection::Types::ValidationResultType do
|
8
|
+
argument :int, types.Int
|
9
|
+
argument :str, types.String
|
10
|
+
argument :float, types.Float
|
11
|
+
argument :bool, types.Boolean
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
argument :str, types.String
|
14
|
-
argument :float, types.Float
|
15
|
-
argument :bool, types.Boolean
|
13
|
+
resolve ->(obj, args, _ctx) do
|
14
|
+
values = [args['int'], args['str'], args['float'], args['bool']]
|
15
|
+
raise ArgumentError, "Must specify at least one argument" if values.compact.empty?
|
16
|
+
raise ArgumentError, "Too many arguments, one expected" if values.compact.size > 1
|
16
17
|
|
17
|
-
|
18
|
-
values = [args['int'], args['str'], args['float'], args['bool']]
|
19
|
-
raise ArgumentError, "Must specify at least one argument" if values.compact.empty?
|
20
|
-
raise ArgumentError, "Too many arguments, one expected" if values.compact.size > 1
|
18
|
+
value = values.compact.first
|
21
19
|
|
22
|
-
|
20
|
+
model = obj.klass.new
|
21
|
+
model[obj.name] = value
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
model.validate!
|
28
|
-
ValidationResult.new(model.valid?, model.errors[obj.name])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
23
|
+
model.validate!
|
24
|
+
GraphQL::Rails::ActiveReflection::ValidationResult.new(model.valid?, model.errors[obj.name])
|
34
25
|
end
|
35
26
|
end
|
36
27
|
end
|
@@ -1,12 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
module Types
|
5
|
-
ModelReflectionType = ::GraphQL::ObjectType.define do
|
6
|
-
name ModelReflection.schema_name
|
7
|
-
field :attributes, AttributeReflectionType.to_list_type
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
GraphQL::Rails::ActiveReflection::Types::ModelReflectionType = GraphQL::ObjectType.define do
|
2
|
+
name GraphQL::Rails::ActiveReflection::ModelReflection.schema_name
|
3
|
+
field :attributes, GraphQL::Rails::ActiveReflection::Types::AttributeReflectionType.to_list_type
|
12
4
|
end
|
@@ -1,14 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module ActiveReflection
|
4
|
-
module Types
|
5
|
-
ValidationResultType = ::GraphQL::ObjectType.define do
|
6
|
-
name ValidationResult.schema_name
|
1
|
+
GraphQL::Rails::ActiveReflection::Types::ValidationResultType = GraphQL::ObjectType.define do
|
2
|
+
name GraphQL::Rails::ActiveReflection::ValidationResult.schema_name
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
4
|
+
field :valid, types.Boolean
|
5
|
+
field :errors, types.String.to_list_type
|
14
6
|
end
|
@@ -1,77 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
field :prescence, types.Boolean do
|
16
|
-
resolve ->(obj, _args, _ctx) do
|
17
|
-
obj < ActiveModel::Validations::PrescenceValidator
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
field :uniqueness, types.Boolean do
|
22
|
-
resolve ->(obj, _args, _ctx) do
|
23
|
-
obj < ActiveModel::Validations::UniquenessValidator
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
field :with_format, types.String do
|
28
|
-
resolve ->(obj, _args, _ctx) do
|
29
|
-
return nil unless obj < ActiveModel::Validations::FormatValidator
|
30
|
-
obj.options[:with]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
field :without_format, types.String do
|
35
|
-
resolve ->(obj, _args, _ctx) do
|
36
|
-
return nil unless obj < ActiveModel::Validations::FormatValidator
|
37
|
-
obj.options[:without]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
field :min_length, types.Int do
|
42
|
-
resolve ->(obj, _args, _ctx) do
|
43
|
-
return nil unless obj < ActiveModel::Validations::LengthValidator
|
44
|
-
obj.options[:minimum]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
field :max_length, types.Int do
|
49
|
-
resolve ->(obj, _args, _ctx) do
|
50
|
-
return nil unless obj < ActiveModel::Validations::LengthValidator
|
51
|
-
obj.options[:maximum]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
field :inclusion, types.String.to_list_type do
|
56
|
-
resolve ->(obj, _args, _ctx) do
|
57
|
-
return nil unless obj < ActiveModel::Validations::InclusionValidator
|
58
|
-
return nil if obj.options[:in].respond_to? :call
|
59
|
-
obj.options[:in]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
field :exclusion, types.String.to_list_type do
|
64
|
-
resolve ->(obj, _args, _ctx) do
|
65
|
-
return nil unless obj < ActiveModel::Validations::ExclusionValidator
|
66
|
-
return nil if obj.options[:in].respond_to? :call
|
67
|
-
obj.options[:in]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# TODO AcceptanceValidator (is this relevant anymore?)
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
1
|
+
GraphQL::Rails::ActiveReflection::Types::ValidatorType = GraphQL::ObjectType.define do
|
2
|
+
name GraphQL::Rails::ActiveReflection::ValidatorReflection.schema_name
|
3
|
+
|
4
|
+
field :absence, types.Boolean
|
5
|
+
field :presence, types.Boolean
|
6
|
+
field :uniqueness, types.Boolean
|
7
|
+
field :with_format, types.String
|
8
|
+
field :without_format, types.String
|
9
|
+
field :min_length, types.Int
|
10
|
+
field :max_length, types.Int
|
11
|
+
field :inclusion, types.String.to_list_type
|
12
|
+
field :exclusion, types.String.to_list_type
|
77
13
|
end
|
@@ -1,21 +1,17 @@
|
|
1
|
-
module GraphQL
|
2
|
-
|
3
|
-
|
4
|
-
class ValidationResult
|
5
|
-
@schema_name = "ActiveReflectionValidation"
|
1
|
+
module GraphQL::Rails::ActiveReflection
|
2
|
+
class ValidationResult
|
3
|
+
@schema_name = "ActiveReflectionValidation"
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
attr_reader :valid
|
6
|
+
attr_reader :errors
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def initialize(valid, errors)
|
9
|
+
@valid = valid
|
10
|
+
@errors = errors
|
11
|
+
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
13
|
+
class << self
|
14
|
+
attr_accessor :schema_name
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
@@ -1,65 +1,89 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'active_model'
|
2
|
+
require 'active_model/validations'
|
3
|
+
require 'active_model/validations/absence'
|
4
|
+
require 'active_model/validations/exclusion'
|
5
|
+
require 'active_model/validations/format'
|
6
|
+
require 'active_model/validations/inclusion'
|
7
|
+
require 'active_model/validations/length'
|
8
|
+
require 'active_model/validations/presence'
|
9
|
+
require 'active_record/validations'
|
10
|
+
require 'active_model/validations/absence'
|
11
|
+
require 'active_model/validations/length'
|
12
|
+
require 'active_model/validations/presence'
|
13
|
+
require 'active_record/validations/uniqueness'
|
6
14
|
|
7
|
-
attr_reader :validator
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
module GraphQL::Rails::ActiveReflection
|
17
|
+
class ValidatorReflection
|
18
|
+
@schema_name = "ActiveReflectionValidator"
|
12
19
|
|
13
|
-
|
14
|
-
@validator < ActiveModel::Validations::AbsenceValidator
|
15
|
-
end
|
20
|
+
attr_reader :validator
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
+
def initialize(validator)
|
23
|
+
@validator = validator
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
def absence
|
27
|
+
true if [
|
28
|
+
ActiveModel::Validations::AbsenceValidator,
|
29
|
+
ActiveRecord::Validations::AbsenceValidator
|
30
|
+
].any? { |klass| @validator.is_a? klass }
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
def presence
|
34
|
+
true if [
|
35
|
+
ActiveModel::Validations::PresenceValidator,
|
36
|
+
ActiveRecord::Validations::PresenceValidator
|
37
|
+
].any? { |klass| @validator.is_a? klass }
|
38
|
+
end
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
40
|
+
def uniqueness
|
41
|
+
true if @validator.is_a? ActiveRecord::Validations::UniquenessValidator
|
42
|
+
end
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
def with_format
|
45
|
+
return nil unless @validator.is_a? ActiveModel::Validations::FormatValidator
|
46
|
+
@validator.options[:with]
|
47
|
+
end
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
def without_format
|
50
|
+
return nil unless @validator.is_a? ActiveModel::Validations::FormatValidator
|
51
|
+
@validator.options[:without]
|
52
|
+
end
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
def min_length
|
55
|
+
return nil unless [
|
56
|
+
ActiveModel::Validations::LengthValidator,
|
57
|
+
ActiveRecord::Validations::LengthValidator
|
58
|
+
].any? { |klass| @validator.is_a? klass }
|
59
|
+
@validator.options[:minimum]
|
60
|
+
end
|
61
|
+
|
62
|
+
def max_length
|
63
|
+
return nil unless [
|
64
|
+
ActiveModel::Validations::LengthValidator,
|
65
|
+
ActiveRecord::Validations::LengthValidator
|
66
|
+
].any? { |klass| @validator.is_a? klass }
|
67
|
+
@validator.options[:maximum]
|
68
|
+
end
|
69
|
+
|
70
|
+
def inclusion
|
71
|
+
return nil unless @validator.is_a? ActiveModel::Validations::InclusionValidator
|
72
|
+
return nil if @validator.options[:in].respond_to? :call
|
73
|
+
@validator.options[:in]
|
74
|
+
end
|
75
|
+
|
76
|
+
def exclusion
|
77
|
+
return nil unless @validator.is_a? ActiveModel::Validations::ExclusionValidator
|
78
|
+
return nil if @validator.options[:in].respond_to? :call
|
79
|
+
@validator.options[:in]
|
80
|
+
end
|
52
81
|
|
53
|
-
|
54
|
-
|
55
|
-
return nil if @validator.options[:in].respond_to? :call
|
56
|
-
@validator.options[:in]
|
57
|
-
end
|
82
|
+
# TODO NumericalityValidator
|
83
|
+
# TODO AcceptanceValidator (is this relevant anymore?)
|
58
84
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
85
|
+
class << self
|
86
|
+
attr_accessor :schema_name
|
63
87
|
end
|
64
88
|
end
|
65
89
|
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.1.
|
4
|
+
version: 0.1.2
|
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-04-
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activemodel
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
47
61
|
description: Reflection over GraphQL for ActiveRecord models and validators
|
48
62
|
email: turner.cole@gmail.com
|
49
63
|
executables: []
|
@@ -53,16 +67,18 @@ files:
|
|
53
67
|
- CHANGELOG.md
|
54
68
|
- LICENSE
|
55
69
|
- README.md
|
70
|
+
- lib/graphql/rails.rb
|
56
71
|
- lib/graphql/rails/active_reflection.rb
|
57
72
|
- lib/graphql/rails/active_reflection/attribute_reflection.rb
|
73
|
+
- lib/graphql/rails/active_reflection/model.rb
|
58
74
|
- lib/graphql/rails/active_reflection/model_reflection.rb
|
59
|
-
- lib/graphql/rails/active_reflection/types.rb
|
60
75
|
- lib/graphql/rails/active_reflection/types/attribute_reflection_type.rb
|
61
76
|
- lib/graphql/rails/active_reflection/types/model_reflection_type.rb
|
62
77
|
- lib/graphql/rails/active_reflection/types/validation_result_type.rb
|
63
78
|
- lib/graphql/rails/active_reflection/types/validator_type.rb
|
64
79
|
- lib/graphql/rails/active_reflection/validation_result.rb
|
65
80
|
- lib/graphql/rails/active_reflection/validator_reflection.rb
|
81
|
+
- lib/graphql/rails/active_reflection/version.rb
|
66
82
|
homepage: http://rubygems.org/gems/graphql-rails-activereflection
|
67
83
|
licenses:
|
68
84
|
- MIT
|
@@ -1,4 +0,0 @@
|
|
1
|
-
require 'graphql/rails/active_reflection/types/model_reflection_type'
|
2
|
-
require 'graphql/rails/active_reflection/types/attribute_reflection_type'
|
3
|
-
require 'graphql/rails/active_reflection/types/validation_result_type'
|
4
|
-
require 'graphql/rails/active_reflection/types/validator_type'
|