Sha256: f3e60ef378350deedce153e56c3952b338b1e48e1536f6f70b72b3bf25557c1a

Contents?: true

Size: 1.96 KB

Versions: 7

Compression:

Stored size: 1.96 KB

Contents

require_relative 'base_comparison_input_type'

module GraphQL
  module Filters
    module InputTypes
      class BaseScalarComparisonInputType
        include CachedClass

        resolve_cache_miss do |value_type, klass|
          klass.new BaseComparisonInputType do
            graphql_name "#{value_type.graphql_name}ComparisonInput"

            one_of

            argument :constant,
                     Types::Boolean,
                     prepare: lambda { |value, _context|
                       lambda { |scope, _column_name|
                         if value
                           scope.all
                         else
                           scope.none
                         end
                       }
                     }
            argument :equals,
                     value_type,
                     prepare: lambda { |value, _context|
                       lambda { |scope, column_name|
                         scope.where(column_name => value)
                       }
                     }
            argument :not_equals,
                     value_type,
                     prepare: lambda { |value, _context|
                       lambda { |scope, column_name|
                         scope.where.not(column_name => value)
                       }
                     }
            argument :in,
                     [value_type],
                     prepare: lambda { |value, _context|
                       lambda { |scope, column_name|
                         scope.where(column_name => value)
                       }
                     }
            argument :not_in,
                     [value_type],
                     prepare: lambda { |value, _context|
                       lambda { |scope, column_name|
                         scope.where.not(column_name => value)
                       }
                     }

            def prepare
              values.sole
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
graphql-filters-1.0.8 lib/graphql/filters/input_types/base_scalar_comparison_input_type.rb
graphql-filters-1.0.7 lib/graphql/filters/input_types/base_scalar_comparison_input_type.rb
graphql-filters-1.0.6 lib/graphql/filters/input_types/base_scalar_comparison_input_type.rb
graphql-filters-1.0.5 lib/graphql/filters/input_types/base_scalar_comparison_input_type.rb
graphql-filters-1.0.4 lib/graphql/filters/input_types/base_scalar_comparison_input_type.rb
graphql-filters-1.0.3 lib/graphql/filters/input_types/base_scalar_comparison_input_type.rb
graphql-filters-1.0.2 lib/graphql/filters/input_types/base_scalar_comparison_input_type.rb