lib/graphql_rails/attribute.rb in graphql_rails-0.2.2 vs lib/graphql_rails/attribute.rb in graphql_rails-0.2.3

- old
+ new

@@ -4,24 +4,21 @@ require 'graphql_rails/attribute/attribute_type_parser' module GraphqlRails # contains info about single graphql attribute class Attribute - attr_reader :name, :graphql_field_type, :property, :type_name + attr_reader :name, :graphql_field_type, :property, :type_name, :description - def initialize(name, type = nil, hidden: false, property: name) - @name = name.to_s + def initialize(name, type = nil, description: nil, property: name) + @original_name = name.to_s + @name = @original_name.tr('!', '') @type_name = type.to_s @graphql_field_type = parse_type(type || type_by_attribute_name) - @hidden = hidden + @description = description @property = property.to_s end - def hidden? - @hidden - end - def field_name field = if name.end_with?('?') "is_#{name.remove(/\?\Z/)}" else @@ -29,20 +26,29 @@ end field.camelize(:lower) end + def field_args + [field_name, graphql_field_type, { property: property.to_sym, description: description }] + end + private + attr_reader :original_name + def type_by_attribute_name - case name - when 'id', /_id\Z/ - GraphQL::ID_TYPE - when /\?\Z/ - GraphQL::BOOLEAN_TYPE - else - GraphQL::STRING_TYPE - end + type = \ + case name + when 'id', /_id\Z/ + GraphQL::ID_TYPE + when /\?\Z/ + GraphQL::BOOLEAN_TYPE + else + GraphQL::STRING_TYPE + end + + original_name['!'] ? type.to_non_null_type : type end def parse_type(type) AttributeTypeParser.new(type).call end