Class: GraphitiGraphQL::Federation::FederatedResource

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti_graphql/federation/federated_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_name) ⇒ FederatedResource

Returns a new instance of FederatedResource.



6
7
8
9
# File 'lib/graphiti_graphql/federation/federated_resource.rb', line 6

def initialize(type_name)
  @type_name = type_name
  @relationships = {}
end

Instance Attribute Details

#relationshipsObject (readonly)

Returns the value of attribute relationships.



4
5
6
# File 'lib/graphiti_graphql/federation/federated_resource.rb', line 4

def relationships
  @relationships
end

#type_nameObject (readonly)

Returns the value of attribute type_name.



4
5
6
# File 'lib/graphiti_graphql/federation/federated_resource.rb', line 4

def type_name
  @type_name
end

Instance Method Details

#add_relationship(kind, name, local_resource_class, foreign_key, &blk) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graphiti_graphql/federation/federated_resource.rb', line 11

def add_relationship(
  kind,
  name,
  local_resource_class,
  foreign_key,
  &blk
)
  @relationships[name] = FederatedRelationship
    .new(kind, name, local_resource_class, foreign_key)
  if blk
    @relationships[name].instance_eval(&blk)
  end
end

#klass_nameObject



29
30
31
32
33
34
35
# File 'lib/graphiti_graphql/federation/federated_resource.rb', line 29

def klass_name
  if polymorphic?
    "I#{@relationships.keys[0].to_s.camelize}"
  else
    @type_name
  end
end

#polymorphic?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/graphiti_graphql/federation/federated_resource.rb', line 25

def polymorphic?
  @type_name.is_a?(Hash)
end