123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Defined in: lib/graphql/client/schema.rb

Constant Summary

Instance Method Summary

Instance Method Details

#define_class(definition, ast_nodes, type)

[ GitHub ]

  
# File 'lib/graphql/client/schema.rb', line 18

def define_class(definition, ast_nodes, type)
  type_class = case type.kind.name
  when "NON_NULL"
    define_class(definition, ast_nodes, type.of_type).to_non_null_type
  when "LIST"
    define_class(definition, ast_nodes, type.of_type).to_list_type
  else
    get_class(type.graphql_name).define_class(definition, ast_nodes)
  end

  ast_nodes.each do |ast_node|
    ast_node.directives.each do |directive|
      if directive = self.directives[directive.name.to_sym]
        type_class = directive.new(type_class)
      end
    end
  end

  type_class
end

#directives

[ GitHub ]

  
# File 'lib/graphql/client/schema.rb', line 58

def directives
  DIRECTIVES
end

#get_class(type_name)

[ GitHub ]

  
# File 'lib/graphql/client/schema.rb', line 39

def get_class(type_name)
  const_get(normalize_type_name(type_name))
end

#normalize_type_name(type_name) (private)

[ GitHub ]

  
# File 'lib/graphql/client/schema.rb', line 64

def normalize_type_name(type_name)
  /\A[A-Z]/.match?(type_name) ? type_name : type_name.camelize
end

#set_class(type_name, klass)

[ GitHub ]

  
# File 'lib/graphql/client/schema.rb', line 43

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