Sha256: f838e0d641682cec2ab2f0d5a056dda67cba4524dd442784bb395cc3c536cc88

Contents?: true

Size: 962 Bytes

Versions: 122

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

module GraphQL
  class Schema
    class Validator
      # Use this to specifically reject values from an argument.
      #
      # @example disallow certain values
      #
      #   argument :favorite_non_prime, Integer, required: true,
      #     validates: { exclusion: { in: [2, 3, 5, 7, ... ]} }
      #
      class ExclusionValidator < Validator
        # @param message [String]
        # @param in [Array] The values to reject
        def initialize(message: "%{validated} is reserved", in:, **default_options)
          # `in` is a reserved word, so work around that
          @in_list = binding.local_variable_get(:in)
          @message = message
          super(**default_options)
        end

        def validate(_object, _context, value)
          if permitted_empty_value?(value)
            # pass
          elsif @in_list.include?(value)
            @message
          end
        end
      end
    end
  end
end

Version data entries

122 entries across 122 versions & 2 rubygems

Version Path
graphql-2.4.9 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.8 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.7 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.6 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.5 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.4 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.3 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.2 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.1 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.4.0 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.20 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.19 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.18 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.17 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.16 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.15 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.14 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.13 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.12 lib/graphql/schema/validator/exclusion_validator.rb
graphql-2.3.11 lib/graphql/schema/validator/exclusion_validator.rb