class Graphql::Generators::TypeGeneratorBase
Attributes
Public Class Methods
# File lib/generators/graphql/type_generator.rb, line 51 def self.normalize_type_expression(type_expression, mode:, null: true) if type_expression.start_with?("!") normalize_type_expression(type_expression[1..-1], mode: mode, null: false) elsif type_expression.end_with?("!") normalize_type_expression(type_expression[0..-2], mode: mode, null: false) elsif type_expression.start_with?("[") && type_expression.end_with?("]") name, is_null = normalize_type_expression(type_expression[1..-2], mode: mode, null: null) ["[#{name}]", is_null] elsif type_expression.end_with?("Type") normalize_type_expression(type_expression[0..-5], mode: mode, null: null) elsif type_expression.start_with?("Types::") normalize_type_expression(type_expression[7..-1], mode: mode, null: null) elsif type_expression.start_with?("types.") normalize_type_expression(type_expression[6..-1], mode: mode, null: null) else case mode when :ruby case type_expression when "Int" ["Integer", null] when "Integer", "Float", "Boolean", "String", "ID" [type_expression, null] else ["Types::#{type_expression.camelize}Type", null] end when :graphql [type_expression.camelize, null] else raise "Unexpected normalize mode: #{mode}" end end end
Take a type expression in any combination of GraphQL or Ruby styles and return it in a specified output style TODO: nullability / list with mode: :graphql doesnβt work
Parameters
-
type_expresson(String) -
mode(Symbol) -
null(Boolean)
Returns
-
(String, Boolean)β The type expression, followed bynull:value
Public Instance Methods
Source
# File lib/generators/graphql/type_generator.rb, line 31 def create_type_file template "#{graphql_type}.erb", "#{options[:directory]}/types#{subdirectory}/#{type_file_name}.rb" end