Class: ElasticGraph::SchemaDefinition::SchemaElements::Relationship
- Inherits:
-
Field
- Object
- Struct
- Field
- ElasticGraph::SchemaDefinition::SchemaElements::Relationship
- Defined in:
- elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/relationship.rb
Overview
Wraps a Field to provide additional relationship-specific functionality when defining a field via TypeWithSubfields#relates_to_one or TypeWithSubfields#relates_to_many.
Constant Summary
Constants included from Mixins::HasTypeInfo
Mixins::HasTypeInfo::CUSTOMIZABLE_DATASTORE_PARAMS
Instance Attribute Summary collapse
-
#related_type ⇒ ObjectType, ...
readonly
The type this relationship relates to.
Attributes inherited from Field
#graphql_only, #name, #name_in_index, #resolver, #schema_def_state
Attributes included from Mixins::HasDocumentation
Instance Method Summary collapse
-
#additional_filter(filter) ⇒ void
Adds additional filter conditions to a relationship beyond the foreign key.
-
#equivalent_field(path, locally_named: path) ⇒ void
Indicates that
path(a field on the related type) is the equivalent oflocally_namedon this type. -
#parent_relationship(parent_type_name, parent_relationship_name, parent_field_name: nil) ⇒ void
Indicates that this relationship chains through a parent relationship to reach the root indexed type.
Methods inherited from Field
#aggregatable?, #argument, #customize_aggregated_values_field, #customize_filter_field, #customize_grouped_by_field, #customize_highlights_field, #customize_sort_order_enum_values, #customize_sub_aggregations_field, #filterable?, #groupable?, #highlightable?, #json_schema, #mapping, #mapping_type, #on_each_generated_schema_element, #renamed_from, #resolve_with, #returnable?, #sortable?, #sourced_from, #sub_aggregatable?, #type
Methods included from Mixins::HasTypeInfo
#json_schema, #json_schema_options, #mapping, #mapping_options
Methods included from Mixins::HasDirectives
#directive, #directives, #directives_sdl
Methods included from Mixins::HasDocumentation
#append_to_documentation, #derived_documentation, #documentation, #formatted_documentation
Methods included from Mixins::VerifiesGraphQLName
Instance Attribute Details
#related_type ⇒ ObjectType, ... (readonly)
Returns the type this relationship relates to.
46 47 48 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/relationship.rb', line 46 def @related_type end |
Instance Method Details
#additional_filter(filter) ⇒ void
This method returns an undefined value.
Adds additional filter conditions to a relationship beyond the foreign key.
101 102 103 104 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/relationship.rb', line 101 def additional_filter(filter) stringified_filter = Support::HashUtil.stringify_keys(filter) @additional_filter = Support::HashUtil.deep_merge(@additional_filter, stringified_filter) end |
#equivalent_field(path, locally_named: path) ⇒ void
This method returns an undefined value.
Indicates that path (a field on the related type) is the equivalent of locally_named on this type.
Use this API to specify a local field's equivalent path on the related type. This must be used on relationships used by Field#sourced_from when the local type uses Indexing::Index#route_with or Indexing::Index#rollover so that ElasticGraph can determine what field from the related type to use to route the update requests to the correct index and shard.
146 147 148 149 150 151 152 153 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/relationship.rb', line 146 def equivalent_field(path, locally_named: path) if @equivalent_field_paths_by_local_path.key?(locally_named) raise Errors::SchemaError, "`equivalent_field` has been called multiple times on `#{parent_type.name}.#{name}` with the same " \ "`locally_named` value (#{locally_named.inspect}), but each local field can have only one `equivalent_field`." else @equivalent_field_paths_by_local_path[locally_named] = path end end |
#parent_relationship(parent_type_name, parent_relationship_name, parent_field_name: nil) ⇒ void
This method returns an undefined value.
Indicates that this relationship chains through a parent relationship to reach the root indexed type.
Use this API when defining relationships on embedded (non-indexed) types that need to use sourced_from
on their fields. By chaining relationships through parent types, ElasticGraph can resolve the path from
the nested type up to the root indexed type and properly update nested fields when source events arrive.
201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_elements/relationship.rb', line 201 def parent_relationship(parent_type_name, parent_relationship_name, parent_field_name: nil) if @parent_ref raise Errors::SchemaError, "`parent_relationship` has been called multiple times on `#{parent_type.name}.#{name}`, " \ "but each relationship can have only one `parent_relationship`." end @parent_ref = ParentRef.new( type_ref: schema_def_state.type_ref(parent_type_name), relationship_name: parent_relationship_name, field_name: parent_field_name ) end |