Sha256: 05b9daa4cf1fd2848f67772205fe9927c401f203956591ba8c38d5ff20f22971

Contents?: true

Size: 792 Bytes

Versions: 6

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

module Rails # :nodoc:
  module GraphQL # :nodoc:
    class Type # :nodoc:
      # Date uses a ISO 8601 string to exchange the value.
      class Scalar::DateScalar < Scalar
        desc 'The Date scalar type represents a ISO 8601 string value.'

        class << self
          def valid_input?(value)
            super && !!Date.iso8601(value)
          rescue Date::Error
            false
          end

          def valid_output?(value)
            value.respond_to?(:to_date) && !!value.to_date
          rescue Date::Error
            false
          end

          def as_json(value)
            value.to_date.iso8601
          end

          def deserialize(value)
            Date.iso8601(value)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails-graphql-0.2.1 lib/rails/graphql/type/scalar/date_scalar.rb
rails-graphql-0.2.0 lib/rails/graphql/type/scalar/date_scalar.rb
rails-graphql-0.1.3 lib/rails/graphql/type/scalar/date_scalar.rb
rails-graphql-0.1.2 lib/rails/graphql/type/scalar/date_scalar.rb
rails-graphql-0.1.1 lib/rails/graphql/type/scalar/date_scalar.rb
rails-graphql-0.1.0 lib/rails/graphql/type/scalar/date_scalar.rb