Sha256: 7b88daff46a4e153dfc9f65cf82d6dcc99acd3f417adfa981cebc32e009018b9

Contents?: true

Size: 1.53 KB

Versions: 64

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true
module GraphQL
  class Schema
    class Member
      module HasValidators
        include GraphQL::EmptyObjects

        # Build {GraphQL::Schema::Validator}s based on the given configuration
        # and use them for this schema member
        # @param validation_config [Hash{Symbol => Hash}]
        # @return [void]
        def validates(validation_config)
          new_validators = GraphQL::Schema::Validator.from_config(self, validation_config)
          @own_validators ||= []
          @own_validators.concat(new_validators)
          nil
        end

        # @return [Array<GraphQL::Schema::Validator>]
        def validators
          @own_validators || EMPTY_ARRAY
        end

        module ClassConfigured
          def inherited(child_cls)
            super
            child_cls.extend(ClassValidators)
          end

          module ClassValidators
            include GraphQL::EmptyObjects

            def validators
              inherited_validators = superclass.validators
              if inherited_validators.any?
                if @own_validators.nil?
                  inherited_validators
                else
                  inherited_validators + @own_validators
                end
              elsif @own_validators.nil?
                EMPTY_ARRAY
              else
                @own_validators
              end
            end
          end
        end

        def self.extended(child_cls)
          super
          child_cls.extend(ClassConfigured)
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
graphql-2.4.4 lib/graphql/schema/member/has_validators.rb
graphql-2.4.3 lib/graphql/schema/member/has_validators.rb
graphql-2.4.2 lib/graphql/schema/member/has_validators.rb
graphql-2.4.1 lib/graphql/schema/member/has_validators.rb
graphql-2.4.0 lib/graphql/schema/member/has_validators.rb
graphql-2.3.20 lib/graphql/schema/member/has_validators.rb
graphql-2.3.19 lib/graphql/schema/member/has_validators.rb
graphql-2.3.18 lib/graphql/schema/member/has_validators.rb
graphql-2.3.17 lib/graphql/schema/member/has_validators.rb
graphql-2.3.16 lib/graphql/schema/member/has_validators.rb
graphql-2.3.15 lib/graphql/schema/member/has_validators.rb
graphql-2.3.14 lib/graphql/schema/member/has_validators.rb
graphql-2.3.13 lib/graphql/schema/member/has_validators.rb
graphql-2.3.12 lib/graphql/schema/member/has_validators.rb
graphql-2.3.11 lib/graphql/schema/member/has_validators.rb
graphql-2.3.10 lib/graphql/schema/member/has_validators.rb
graphql-2.2.16 lib/graphql/schema/member/has_validators.rb
graphql-2.1.13 lib/graphql/schema/member/has_validators.rb
graphql-2.3.9 lib/graphql/schema/member/has_validators.rb
graphql-2.3.8 lib/graphql/schema/member/has_validators.rb