class GraphqlRails::Attributes::TypeParser

converts string value in to GraphQL type

Attributes

unparsed_type[R]

Public Class Methods

new(unparsed_type, paginated: false) click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 20
def initialize(unparsed_type, paginated: false)
  @unparsed_type = unparsed_type
  @paginated = paginated
end

Public Instance Methods

graphql_type() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 29
def graphql_type
  return unparsed_type if raw_graphql_type?

  if list?
    parsed_list_type
  else
    parsed_inner_type
  end
end
paginated?() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 25
def paginated?
  @paginated
end
type_arg() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 39
def type_arg
  if paginated?
    paginated_type_arg
  elsif list?
    list_type_arg
  else
    raw_unwrapped_type
  end
end

Protected Instance Methods

list_type_arg() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 57
def list_type_arg
  if required_inner_type?
    [raw_unwrapped_type]
  else
    [raw_unwrapped_type, null: true]
  end
end
paginated_type_arg() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 51
def paginated_type_arg
  return graphql_model.graphql.connection_type if graphql_model

  raise NotSupportedFeature, 'pagination is only supported for models which include GraphqlRails::Model'
end
parsed_type() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 65
def parsed_type
  return unparsed_type if raw_graphql_type?

  type_by_name
end
raw_unwrapped_type() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 71
def raw_unwrapped_type
  @raw_unwrapped_type ||= unwrap_type(parsed_type)
end

Private Instance Methods

parsed_inner_type() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 89
def parsed_inner_type
  if required_inner_type?
    type_by_name.to_non_null_type
  else
    type_by_name
  end
end
parsed_list_type() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 79
def parsed_list_type
  list_type = parsed_inner_type.to_list_type

  if required_list?
    list_type.to_non_null_type
  else
    list_type
  end
end
type_by_name() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 109
def type_by_name
  unwrapped_scalar_type || unwrapped_model_type || raise_not_supported_type_error
end
type_name_info() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 97
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
unwrapped_model_type() click to toggle source
# File lib/graphql_rails/attributes/type_parser.rb, line 113
def unwrapped_model_type
  type_class = graphql_model
  return unless type_class

  type_class.graphql.graphql_type
end