Module: GraphqlRails::Attributes::TypeParseable
Overview
Contains shared parsing logic. Expects that including class has:
* method "unparsed_type" which might be Instance of String, Symbol, GraphQL type or so
Defined Under Namespace
Classes: UnknownTypeError
Constant Summary
collapse
- TYPE_MAPPING =
{
'id' => GraphQL::Types::ID,
'int' => GraphQL::Types::Int,
'integer' => GraphQL::Types::Int,
'big_int' => GraphQL::Types::BigInt,
'bigint' => GraphQL::Types::BigInt,
'float' => GraphQL::Types::Float,
'double' => GraphQL::Types::Float,
'decimal' => GraphQL::Types::Float,
'bool' => GraphQL::Types::Boolean,
'boolean' => GraphQL::Types::Boolean,
'string' => GraphQL::Types::String,
'str' => GraphQL::Types::String,
'text' => GraphQL::Types::String,
'date' => GraphQL::Types::ISO8601Date,
'time' => GraphQL::Types::ISO8601DateTime,
'datetime' => GraphQL::Types::ISO8601DateTime,
'date_time' => GraphQL::Types::ISO8601DateTime,
'json' => GraphQL::Types::JSON
}.freeze
- WRAPPER_TYPES =
[
GraphQL::Schema::List,
GraphQL::Schema::NonNull,
GraphQL::Language::Nodes::NonNullType,
GraphQL::Language::Nodes::ListType
].freeze
- GRAPHQL_BASE_TYPES =
[
GraphQL::Schema::Object,
GraphQL::Schema::InputObject
].freeze
- RAW_GRAPHQL_TYPES =
(WRAPPER_TYPES + GRAPHQL_BASE_TYPES).freeze
Instance Method Summary
collapse
Instance Method Details
#core_scalar_type? ⇒ Boolean
68
69
70
|
# File 'lib/graphql_rails/attributes/type_parseable.rb', line 68
def core_scalar_type?
unwrapped_scalar_type.present?
end
|
#graphql_model ⇒ Object
72
73
74
|
# File 'lib/graphql_rails/attributes/type_parseable.rb', line 72
def graphql_model
{ |type| graphql_model?(type) }
end
|
#graphql_type_object ⇒ Object
76
77
78
79
|
# File 'lib/graphql_rails/attributes/type_parseable.rb', line 76
def graphql_type_object
type_object = { |type| graphql_type_object?(type) }
type_object || graphql_model&.graphql&.graphql_type
end
|
#raw_graphql_type? ⇒ Boolean
60
61
62
63
64
65
66
|
# File 'lib/graphql_rails/attributes/type_parseable.rb', line 60
def raw_graphql_type?
return true if RAW_GRAPHQL_TYPES.detect { |raw_type| unparsed_type.is_a?(raw_type) }
defined?(GraphQL::Schema::Member) &&
unparsed_type.is_a?(Class) &&
unparsed_type < GraphQL::Schema::Member
end
|
#unwrapped_scalar_type ⇒ Object
56
57
58
|
# File 'lib/graphql_rails/attributes/type_parseable.rb', line 56
def unwrapped_scalar_type
TYPE_MAPPING[nullable_inner_name.downcase]
end
|