Sha256: 636a9b3e999fbdc480f556dcaa28bbd854a6ea4365b87fbed297f3eb97aecd1f

Contents?: true

Size: 908 Bytes

Versions: 20

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module Types
    # This scalar takes `Date`s and transmits them as strings,
    # using ISO 8601 format.
    #
    # Use it for fields or arguments as follows:
    #
    #     field :published_at, GraphQL::Types::ISO8601Date, null: false
    #
    #     argument :deliver_at, GraphQL::Types::ISO8601Date, null: false
    #
    # Alternatively, use this built-in scalar as inspiration for your
    # own Date type.
    class ISO8601Date < GraphQL::Schema::Scalar
      description "An ISO 8601-encoded date"

      # @param value [Date]
      # @return [String]
      def self.coerce_result(value, _ctx)
        value.iso8601
      end

      # @param str_value [String]
      # @return [Date]
      def self.coerce_input(str_value, _ctx)
        Date.iso8601(str_value)
      rescue ArgumentError
        # Invalid input
        nil
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
graphql-1.9.21 lib/graphql/types/iso_8601_date.rb
graphql-1.9.20 lib/graphql/types/iso_8601_date.rb
graphql-1.10.6 lib/graphql/types/iso_8601_date.rb
graphql-1.10.5 lib/graphql/types/iso_8601_date.rb
graphql-1.10.4 lib/graphql/types/iso_8601_date.rb
graphql-1.10.3 lib/graphql/types/iso_8601_date.rb
graphql-1.10.2 lib/graphql/types/iso_8601_date.rb
graphql-1.9.19 lib/graphql/types/iso_8601_date.rb
graphql-1.10.1 lib/graphql/types/iso_8601_date.rb
graphql-1.10.0 lib/graphql/types/iso_8601_date.rb
graphql-1.10.0.pre4 lib/graphql/types/iso_8601_date.rb
graphql-1.9.18 lib/graphql/types/iso_8601_date.rb
graphql-1.10.0.pre3 lib/graphql/types/iso_8601_date.rb
graphql-1.9.17 lib/graphql/types/iso_8601_date.rb
graphql-1.10.0.pre2 lib/graphql/types/iso_8601_date.rb
graphql-1.9.16 lib/graphql/types/iso_8601_date.rb
graphql-1.9.15 lib/graphql/types/iso_8601_date.rb
graphql-1.9.14 lib/graphql/types/iso_8601_date.rb
graphql-1.10.0.pre1 lib/graphql/types/iso_8601_date.rb
graphql-1.9.13 lib/graphql/types/iso_8601_date.rb