Class: GraphQL::Models::BackedByModel
- Inherits:
-
Object
- Object
- GraphQL::Models::BackedByModel
- Defined in:
- lib/graphql/models/backed_by_model.rb
Constant Summary collapse
- DEFAULT_OBJECT_TO_MODEL =
-> (obj) { obj }
Instance Attribute Summary collapse
-
#graph_type ⇒ Object
Returns the value of attribute graph_type.
-
#model_type ⇒ Object
Returns the value of attribute model_type.
-
#object_to_model(value = nil) ⇒ Object
Returns the value of attribute object_to_model.
Instance Method Summary collapse
- #attr(name, **options) ⇒ Object
- #field(*args, &block) ⇒ Object
- #has_many_array(association, **options) ⇒ Object
- #has_many_connection(association, **options) ⇒ Object
- #has_one(association, **options) ⇒ Object
-
#initialize(graph_type, model_type) ⇒ BackedByModel
constructor
A new instance of BackedByModel.
- #proxy_to(association, &block) ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(graph_type, model_type) ⇒ BackedByModel
Returns a new instance of BackedByModel.
8 9 10 11 12 |
# File 'lib/graphql/models/backed_by_model.rb', line 8 def initialize(graph_type, model_type) @graph_type = graph_type @model_type = model_type @object_to_model = DEFAULT_OBJECT_TO_MODEL end |
Instance Attribute Details
#graph_type ⇒ Object
Returns the value of attribute graph_type.
4 5 6 |
# File 'lib/graphql/models/backed_by_model.rb', line 4 def graph_type @graph_type end |
#model_type ⇒ Object
Returns the value of attribute model_type.
4 5 6 |
# File 'lib/graphql/models/backed_by_model.rb', line 4 def model_type @model_type end |
#object_to_model(value = nil) ⇒ Object
Returns the value of attribute object_to_model.
4 5 6 |
# File 'lib/graphql/models/backed_by_model.rb', line 4 def object_to_model @object_to_model end |
Instance Method Details
#attr(name, **options) ⇒ Object
23 24 25 |
# File 'lib/graphql/models/backed_by_model.rb', line 23 def attr(name, **) DefinitionHelpers.define_attribute(graph_type, model_type, model_type, [], name, object_to_model, ) end |
#field(*args, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/graphql/models/backed_by_model.rb', line 43 def field(*args, &block) defined_field = GraphQL::Define::AssignObjectField.call(graph_type, *args, &block) DefinitionHelpers.(graph_type, defined_field.name, { macro: :field, macro_type: :custom, path: [], base_model_type: @model_type.to_s.classify.constantize, model_type: @model_type.to_s.classify.constantize, object_to_base_model: object_to_model }) defined_field end |
#has_many_array(association, **options) ⇒ Object
39 40 41 |
# File 'lib/graphql/models/backed_by_model.rb', line 39 def has_many_array(association, **) DefinitionHelpers.define_has_many_array(graph_type, model_type, model_type, [], association, object_to_model, ) end |
#has_many_connection(association, **options) ⇒ Object
35 36 37 |
# File 'lib/graphql/models/backed_by_model.rb', line 35 def has_many_connection(association, **) DefinitionHelpers.define_has_many_connection(graph_type, model_type, model_type, [], association, object_to_model, ) end |
#has_one(association, **options) ⇒ Object
31 32 33 |
# File 'lib/graphql/models/backed_by_model.rb', line 31 def has_one(association, **) DefinitionHelpers.define_has_one(graph_type, model_type, model_type, [], association, object_to_model, ) end |
#proxy_to(association, &block) ⇒ Object
27 28 29 |
# File 'lib/graphql/models/backed_by_model.rb', line 27 def proxy_to(association, &block) DefinitionHelpers.define_proxy(graph_type, model_type, model_type, [], association, object_to_model, &block) end |
#types ⇒ Object
14 15 16 |
# File 'lib/graphql/models/backed_by_model.rb', line 14 def types GraphQL::Define::TypeDefiner.instance end |