Class: ElasticGraph::SchemaDefinition::Indexing::RelationshipResolver
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaDefinition::Indexing::RelationshipResolver
- Defined in:
- lib/elastic_graph/schema_definition/indexing/relationship_resolver.rb
Instance Method Summary collapse
-
#initialize(schema_def_state:, object_type:, relationship_name:, sourced_fields:, field_path_resolver:) ⇒ RelationshipResolver
constructor
A new instance of RelationshipResolver.
- #resolve ⇒ Object
Constructor Details
#initialize(schema_def_state:, object_type:, relationship_name:, sourced_fields:, field_path_resolver:) ⇒ RelationshipResolver
Returns a new instance of RelationshipResolver.
14 15 16 17 18 19 20 |
# File 'lib/elastic_graph/schema_definition/indexing/relationship_resolver.rb', line 14 def initialize(schema_def_state:, object_type:, relationship_name:, sourced_fields:, field_path_resolver:) @schema_def_state = schema_def_state @object_type = object_type @relationship_name = relationship_name @sourced_fields = sourced_fields @field_path_resolver = field_path_resolver end |
Instance Method Details
#resolve ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elastic_graph/schema_definition/indexing/relationship_resolver.rb', line 22 def resolve relation_field = object_type.graphql_fields_by_name[relationship_name] if relation_field.nil? [nil, "#{relationship_error_prefix} is not defined. Is it misspelled?"] elsif (relationship = relation_field.relationship).nil? [nil, "#{relationship_error_prefix} is not a relationship. It must be defined using `relates_to_one` or `relates_to_many`."] elsif ( = schema_def_state.object_types_by_name[relationship..unwrap_non_null.name]).nil? issue = if schema_def_state.types_by_name.key?(relationship..fully_unwrapped.name) "references a type which is not an object type: `#{relationship..name}`. Only object types can be used in relations." else "references an unknown type: `#{relationship..name}`. Is it misspelled?" end [nil, "#{relationship_error_prefix} #{issue}"] elsif !.indexed? [nil, "#{relationship_error_prefix} references a type which is not indexed: `#{.name}`. Only indexed types can be used in relations."] else = relation_field..relation # : SchemaArtifacts::RuntimeMetadata::Relation foreign_key_parent_type = (.direction == :in) ? : object_type if (foreign_key_error = validate_foreign_key(foreign_key_parent_type, )) [nil, foreign_key_error] else [ResolvedRelationship.new(relationship_name, relation_field, relationship, , ), nil] end end end |