Sha256: 11d5e605bbbc756690fd1322630c05f3867cefd81c322b8024281fcd8b5c441a

Contents?: true

Size: 1.94 KB

Versions: 53

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true
module GraphQL
  class Schema
    class Scalar < GraphQL::Schema::Member
      extend GraphQL::Schema::Member::ValidatesInput

      class << self
        def coerce_input(val, ctx)
          val
        end

        def coerce_result(val, ctx)
          val
        end

        def kind
          GraphQL::TypeKinds::SCALAR
        end

        def specified_by_url(new_url = nil)
          if new_url
            directive(GraphQL::Schema::Directive::SpecifiedBy, url: new_url)
          elsif (directive = directives.find { |dir| dir.graphql_name == "specifiedBy" })
            directive.arguments[:url] # rubocop:disable Development/ContextIsPassedCop
          elsif superclass.respond_to?(:specified_by_url)
            superclass.specified_by_url
          else
            nil
          end
        end

        def default_scalar(is_default = nil)
          if !is_default.nil?
            @default_scalar = is_default
          end
          @default_scalar
        end

        def default_scalar?
          @default_scalar ||= false
        end

        def validate_non_null_input(value, ctx, max_errors: nil)
          coerced_result = begin
            coerce_input(value, ctx)
          rescue GraphQL::CoercionError => err
            err
          rescue StandardError => err
            ctx.query.handle_or_reraise(err)
          end

          if coerced_result.nil?
            str_value = if value == Float::INFINITY
              ""
            else
              " #{GraphQL::Language.serialize(value)}"
            end
            Query::InputValidationResult.from_problem("Could not coerce value#{str_value} to #{graphql_name}")
          elsif coerced_result.is_a?(GraphQL::CoercionError)
            Query::InputValidationResult.from_problem(coerced_result.message, message: coerced_result.message, extensions: coerced_result.extensions)
          else
            nil
          end
        end
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

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