Class: GraphQL::Types::ISO8601Date

Inherits:
Schema::Scalar show all
Defined in:
lib/graphql/types/iso_8601_date.rb

Overview

This scalar takes Dates 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.

Constant Summary

Constants included from Schema::Member::HasDirectives

Schema::Member::HasDirectives::NO_DIRECTIVES

Constants included from Schema::Member::GraphQLTypeNames

Schema::Member::GraphQLTypeNames::Boolean, Schema::Member::GraphQLTypeNames::ID, Schema::Member::GraphQLTypeNames::Int

Class Method Summary collapse

Methods inherited from Schema::Scalar

default_scalar, default_scalar?, kind, to_graphql, validate_non_null_input

Methods included from Schema::Member::ValidatesInput

#coerce_isolated_input, #coerce_isolated_result, #valid_input?, #valid_isolated_input?, #validate_input

Methods included from Schema::Member::CachedGraphQLDefinition

#graphql_definition, #initialize_copy, #type_class

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Methods included from Schema::Member::BaseDSLMethods

#accessible?, #authorized?, #default_graphql_name, #description, #graphql_name, #introspection, #introspection?, #mutation, #name, #overridden_graphql_name, #to_graphql, #visible?

Methods included from Schema::Member::BaseDSLMethods::ConfigurationExtension

#inherited

Methods included from Schema::Member::TypeSystemHelpers

#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature

Methods included from Schema::Member::Scoped

#scope_items

Methods included from Schema::Member::RelayShortcuts

#connection_type, #connection_type_class, #edge_type, #edge_type_class

Methods included from Schema::Member::HasPath

#path

Methods included from Schema::Member::HasAstNode

#ast_node

Methods included from Schema::Member::HasDirectives

#directive, #directives, #remove_directive

Class Method Details

.coerce_input(str_value, _ctx) ⇒ Date

Parameters:

Returns:

  • (Date)


26
27
28
29
30
31
# File 'lib/graphql/types/iso_8601_date.rb', line 26

def self.coerce_input(str_value, _ctx)
  Date.iso8601(str_value)
rescue ArgumentError, TypeError
  # Invalid input
  nil
end

.coerce_result(value, _ctx) ⇒ String

Parameters:

  • value (Date, Time, DateTime, String)

Returns:



20
21
22
# File 'lib/graphql/types/iso_8601_date.rb', line 20

def self.coerce_result(value, _ctx)
  Date.parse(value.to_s).iso8601
end