module GraphqlRails::Attributes::TypeParseable
Contains shared parsing logic. Expects that including class has:
* method "unparsed_type" which might be Instance of String, Symbol, GraphQL type or so
Constants
- GRAPHQL_BASE_TYPES
- RAW_GRAPHQL_TYPES
- TYPE_MAPPING
- WRAPPER_TYPES
Public Instance Methods
core_scalar_type?()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 60 def core_scalar_type? unwrapped_scalar_type.in?(TYPE_MAPPING.values) end
graphql_model()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 64 def graphql_model type_class = \ if unparsed_type.is_a?(Class) && unparsed_type < GraphqlRails::Model unparsed_type else nullable_inner_name.safe_constantize end return if type_class.nil? return unless type_class < GraphqlRails::Model type_class end
raw_graphql_type?()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 52 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()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 48 def unwrapped_scalar_type TYPE_MAPPING[nullable_inner_name.downcase.downcase] end
Protected Instance Methods
list?()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 94 def list? type_name_info.list? end
nullable_inner_name()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 90 def nullable_inner_name type_name_info.nullable_inner_name end
raise_not_supported_type_error()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 122 def raise_not_supported_type_error error_message = \ "Type #{unparsed_type.inspect} is not supported. " \ "Supported scalar types are: #{TypeParseable::TYPE_MAPPING.keys}. " \ 'All the classes that includes `GraphqlRails::Model` are also supported as types.' raise UnknownTypeError, error_message end
required?()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 106 def required? type_name_info.required? end
required_inner_type?()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 98 def required_inner_type? type_name_info.required_inner_type? end
required_list?()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 102 def required_list? type_name_info.required_list? end
type_name_info()
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 110 def type_name_info @type_name_info ||= begin type_name = \ if unparsed_type.respond_to?(:to_type_signature) unparsed_type.to_type_signature else unparsed_type.to_s end TypeNameInfo.new(type_name) end end
unwrap_type(type)
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 80 def unwrap_type(type) unwrappable = type unwrappable = unwrappable.of_type while wrapped_type?(unwrappable) unwrappable end
wrapped_type?(type)
click to toggle source
# File lib/graphql_rails/attributes/type_parseable.rb, line 86 def wrapped_type?(type) WRAPPER_TYPES.any? { |wrapper| type.is_a?(wrapper) } end