class GraphqlRails::Model::FindOrBuildGraphqlType
stores information about model specific config, like attributes and types
Attributes
attributes[R]
description[R]
force_define_attributes[R]
name[R]
type_name[R]
Public Class Methods
new(name:, description:, attributes:, type_name:, force_define_attributes: false)
click to toggle source
# File lib/graphql_rails/model/find_or_build_graphql_type.rb, line 13 def initialize(name:, description:, attributes:, type_name:, force_define_attributes: false) @name = name @description = description @attributes = attributes @type_name = type_name @force_define_attributes = force_define_attributes end
Public Instance Methods
call()
click to toggle source
# File lib/graphql_rails/model/find_or_build_graphql_type.rb, line 21 def call klass.tap { add_fields_to_graphql_type if new_class? || force_define_attributes } end
Private Instance Methods
add_fields_to_graphql_type()
click to toggle source
# File lib/graphql_rails/model/find_or_build_graphql_type.rb, line 39 def add_fields_to_graphql_type AddFieldsToGraphqlType.call(klass: klass, attributes: attributes.values.select(&:scalar_type?)) attributes.values.reject(&:scalar_type?).tap do |dynamic_attributes| find_or_build_dynamic_graphql_types(dynamic_attributes) do |name, description, attributes, type_name| self.class.call( name: name, description: description, attributes: attributes, type_name: type_name ) end AddFieldsToGraphqlType.call(klass: klass, attributes: dynamic_attributes) end end
find_or_build_dynamic_graphql_types(dynamic_attributes) { |graphql_model.name, graphql_model.description, graphql_model.attributes, graphql_model.type_name| ... }
click to toggle source
# File lib/graphql_rails/model/find_or_build_graphql_type.rb, line 53 def find_or_build_dynamic_graphql_types(dynamic_attributes) dynamic_attributes.each do |attribute| yield( attribute.graphql_model.graphql.name, attribute.graphql_model.graphql.description, attribute.graphql_model.graphql.attributes, attribute.graphql_model.graphql.type_name ) end end
type_class_finder()
click to toggle source
# File lib/graphql_rails/model/find_or_build_graphql_type.rb, line 31 def type_class_finder @type_class_finder ||= FindOrBuildGraphqlTypeClass.new( name: name, type_name: type_name, description: description ) end