Sha256: ff3943798fa6169e20fbc410db0cabdb69df70e13a6848919415cbda949f6838

Contents?: true

Size: 957 Bytes

Versions: 47

Compression:

Stored size: 957 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,Time,DateTime,String]
      # @return [String]
      def self.coerce_result(value, _ctx)
        Date.parse(value.to_s).iso8601
      end

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

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
graphql_cody-1.13.0 lib/graphql/types/iso_8601_date.rb
graphql-1.12.24 lib/graphql/types/iso_8601_date.rb
graphql-1.13.5 lib/graphql/types/iso_8601_date.rb
graphql-1.13.4 lib/graphql/types/iso_8601_date.rb
graphql-1.13.3 lib/graphql/types/iso_8601_date.rb
graphql-1.12.23 lib/graphql/types/iso_8601_date.rb
graphql-1.13.2 lib/graphql/types/iso_8601_date.rb
graphql-1.13.1 lib/graphql/types/iso_8601_date.rb
graphql-1.12.22 lib/graphql/types/iso_8601_date.rb
graphql-1.13.0 lib/graphql/types/iso_8601_date.rb
graphql-1.12.21 lib/graphql/types/iso_8601_date.rb
graphql-1.12.20 lib/graphql/types/iso_8601_date.rb
graphql-1.12.19 lib/graphql/types/iso_8601_date.rb
graphql-1.11.10 lib/graphql/types/iso_8601_date.rb
graphql-1.12.18 lib/graphql/types/iso_8601_date.rb
graphql-1.11.9 lib/graphql/types/iso_8601_date.rb
graphql-1.12.17 lib/graphql/types/iso_8601_date.rb
graphql-1.12.16 lib/graphql/types/iso_8601_date.rb
graphql-1.12.15 lib/graphql/types/iso_8601_date.rb
graphql-1.12.14 lib/graphql/types/iso_8601_date.rb