Module: GraphQL::Client::Schema::ClassMethods
- Defined in:
- lib/graphql/client/schema.rb
Instance Method Summary collapse
- #define_class(definition, irep_node, type) ⇒ Object
- #get_class(type_name) ⇒ Object
- #set_class(type_name, klass) ⇒ Object
Instance Method Details
#define_class(definition, irep_node, type) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/graphql/client/schema.rb', line 18 def define_class(definition, irep_node, type) type_klass = case type when GraphQL::NonNullType define_class(definition, irep_node, type.of_type).to_non_null_type when GraphQL::ListType define_class(definition, irep_node, type.of_type).to_list_type else get_class(type.name).define_class(definition, irep_node) end irep_node.ast_node.directives.inject(type_klass) do |klass, directive| if directive = self.directives[directive.name.to_sym] directive.new(klass) else klass end end end |
#get_class(type_name) ⇒ Object
37 38 39 |
# File 'lib/graphql/client/schema.rb', line 37 def get_class(type_name) const_get(normalize_type_name(type_name)) end |
#set_class(type_name, klass) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/graphql/client/schema.rb', line 41 def set_class(type_name, klass) class_name = normalize_type_name(type_name) if constants.include?(class_name.to_sym) raise ArgumentError, "Can't define #{class_name} to represent type #{type_name} " \ "because it's already defined" end const_set(class_name, klass) end |