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
-
.authorize ⇒ Object
Returns the value of attribute authorize.
-
.id_for_model ⇒ Object
Returns the value of attribute id_for_model.
-
.model_from_id ⇒ Object
Returns the value of attribute model_from_id.
-
.node_interface_proc ⇒ Object
Returns the value of attribute node_interface_proc.
Class Method Summary collapse
- .authorize!(context, model, action) ⇒ Object
- .define_mutator(definer, model_type, null_behavior:, &block) ⇒ Object
- .field_info(graph_type, field_name) ⇒ Object
-
.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.
- .load_relation(relation, fast_query: false) ⇒ Object
Class Attribute Details
.authorize ⇒ Object
Returns the value of attribute authorize.
43 44 45 |
# File 'lib/graphql/activerecord.rb', line 43 def end |
.id_for_model ⇒ Object
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_id ⇒ Object
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_proc ⇒ Object
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.(context, model, action) .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 = graph_type.instance_variable_get(:@field_metadata) return nil unless [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 |