Class: ForestAdminDatasourceGraphqlHasura::Introspection::PolymorphismDetector
- Inherits:
-
Object
- Object
- ForestAdminDatasourceGraphqlHasura::Introspection::PolymorphismDetector
- Defined in:
- lib/forest_admin_datasource_graphql_hasura/introspection/polymorphism_detector.rb
Overview
Recognises Rails polymorphic belongs_to associations among introspected
tables, from a <base>_type/<base>_id column pair backed by one Hasura
relationship per target, or from the polymorphic_relations configuration
when the metadata API is unreachable.
Instance Method Summary collapse
-
#detect(tables) ⇒ Object
Fills
polymorphicson each table and removes the per-target object relationships it absorbs. -
#initialize(configuration) ⇒ PolymorphismDetector
constructor
A new instance of PolymorphismDetector.
Constructor Details
#initialize(configuration) ⇒ PolymorphismDetector
Returns a new instance of PolymorphismDetector.
10 11 12 |
# File 'lib/forest_admin_datasource_graphql_hasura/introspection/polymorphism_detector.rb', line 10 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#detect(tables) ⇒ Object
Fills polymorphics on each table and removes the per-target object
relationships it absorbs.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/forest_admin_datasource_graphql_hasura/introspection/polymorphism_detector.rb', line 16 def detect(tables) # Relationships reference the GraphQL type name; the merge order makes # the type interpretation win when it collides with another table's # root field name (crossed custom_root_fields renames). tables_by_name = tables.to_h { |table| [table.name, table] } .merge(tables.to_h { |table| [table.type_name, table] }) tables.each do |table| bases_of(table).each { |base| absorb(table, base, tables_by_name) } end end |