Module: GraphQL::Models

Defined in:
lib/graphql/activerecord.rb,
lib/graphql/models/definer.rb,
lib/graphql/models/helpers.rb,
lib/graphql/models/mutator.rb,
lib/graphql/models/version.rb,
lib/graphql/models/object_type.rb,
lib/graphql/models/proxy_block.rb,
lib/graphql/models/scalar_types.rb,
lib/graphql/models/backed_by_model.rb,
lib/graphql/models/relation_loader.rb,
lib/graphql/models/attribute_loader.rb,
lib/graphql/models/definition_helpers.rb,
lib/graphql/models/mutation_field_map.rb,
lib/graphql/models/relation_load_request.rb,
lib/graphql/models/active_record_extension.rb,
lib/graphql/models/association_load_request.rb,
lib/graphql/models/mutation_helpers/validation.rb,
lib/graphql/models/promise_relation_connection.rb,
lib/graphql/models/definition_helpers/attributes.rb,
lib/graphql/models/mutation_helpers/apply_changes.rb,
lib/graphql/models/mutation_helpers/authorization.rb,
lib/graphql/models/definition_helpers/associations.rb,
lib/graphql/models/mutation_helpers/validation_error.rb,
lib/graphql/models/mutation_helpers/print_input_fields.rb

Defined Under Namespace

Modules: ActiveRecordExtension, DefinitionHelpers, HashCombiner, Helpers, MutationHelpers, ObjectType, ScalarTypes Classes: AssociationLoadRequest, AttributeLoader, BackedByModel, Definer, Middleware, MutationFieldMap, Mutator, MutatorDefinition, PromiseRelationConnection, ProxyBlock, RelationLoadRequest, RelationLoader

Constant Summary collapse

VERSION =
"0.8.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.authorizeObject

Returns the value of attribute authorize.



43
44
45
# File 'lib/graphql/activerecord.rb', line 43

def authorize
  @authorize
end

.id_for_modelObject

Returns the value of attribute id_for_model.



43
44
45
# File 'lib/graphql/activerecord.rb', line 43

def id_for_model
  @id_for_model
end

.model_from_idObject

Returns the value of attribute model_from_id.



43
44
45
# File 'lib/graphql/activerecord.rb', line 43

def model_from_id
  @model_from_id
end

.node_interface_procObject

Returns the value of attribute node_interface_proc.



43
44
45
# File 'lib/graphql/activerecord.rb', line 43

def node_interface_proc
  @node_interface_proc
end

Class Method Details

.authorize!(context, model, action) ⇒ Object



73
74
75
# File 'lib/graphql/activerecord.rb', line 73

def self.authorize!(context, model, action)
  authorize.call(context, model, action)
end

.define_mutator(definer, model_type, null_behavior:, &block) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/graphql/activerecord.rb', line 77

def self.define_mutator(definer, model_type, null_behavior:, &block)
  # HACK: To get the name of the mutation, to avoid possible collisions with other type names
  prefix = definer.instance_variable_get(:@target).name

  mutator_definition = MutatorDefinition.new(model_type, null_behavior: null_behavior)
  mutator_definition.field_map.instance_exec(&block)
  MutationHelpers.print_input_fields(mutator_definition.field_map, definer, "#{prefix}Input")
  mutator_definition
end

.field_info(graph_type, field_name) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/graphql/activerecord.rb', line 64

def self.field_info(graph_type, field_name)
  field_name = field_name.to_s

  meta = graph_type.instance_variable_get(:@field_metadata)
  return nil unless meta

  meta[field_name]
end

.load_association(starting_model, path, context) ⇒ Object

Returns a promise that will traverse the associations and resolve to the model at the end of the path. You can use this to access associated models inside custom field resolvers, without losing optimization benefits.



49
50
51
52
# File 'lib/graphql/activerecord.rb', line 49

def self.load_association(starting_model, path, context)
  path = Array.wrap(path)
  GraphQL::Models::DefinitionHelpers.load_and_traverse(starting_model, path, context)
end

.load_relation(relation, fast_query: false) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/graphql/activerecord.rb', line 54

def self.load_relation(relation, fast_query: false)
  if fast_query
    request = AttributeLoader::Request.new(relation.where_values_hash, Helpers.orders_to_sql(relation.orders))
    AttributeLoader.for(relation.klass).load(request)
  else
    request = RelationLoadRequest.new(relation)
    request.load
  end
end