Module: GraphQL::Client::Schema::ClassMethods

Defined in:
lib/graphql/client/schema.rb

Instance Method Summary collapse

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
    const_get(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