Class: ForestAdminDatasourceGraphqlHasura::Configuration
- Inherits:
-
Object
- Object
- ForestAdminDatasourceGraphqlHasura::Configuration
- Defined in:
- lib/forest_admin_datasource_graphql_hasura/configuration.rb
Constant Summary collapse
- DEFAULTS =
polymorphic_relations declares associations explicitly when the metadata API is unreachable: { 'comments' => { 'commentable' => %w[transfers cards] } }. type_values overrides the Rails class name a table maps to, for those that
classifygets wrong: { 'bank_accounts' => 'Banking::Account' }. { headers: {}, metadata_uri: nil, included_tables: nil, excluded_tables: [], polymorphic_relations: {}, type_values: {}, timeout: 30 }.freeze
Instance Attribute Summary collapse
-
#excluded_tables ⇒ Object
readonly
Returns the value of attribute excluded_tables.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#included_tables ⇒ Object
readonly
Returns the value of attribute included_tables.
-
#metadata_uri ⇒ Object
readonly
Returns the value of attribute metadata_uri.
-
#polymorphic_relations ⇒ Object
readonly
Returns the value of attribute polymorphic_relations.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#type_values ⇒ Object
readonly
Returns the value of attribute type_values.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri:, **options) ⇒ Configuration
constructor
A new instance of Configuration.
-
#table_allowed?(*table_names) ⇒ Boolean
Accepts every spelling a table goes by (root field and type name): an exclusion must hold under renaming, or it would silently re-expose data.
Constructor Details
#initialize(uri:, **options) ⇒ Configuration
Returns a new instance of Configuration.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 20 def initialize(uri:, **) raise ConfigurationError, 'uri is required' if uri.nil? || uri.empty? unknown = .keys - DEFAULTS.keys raise ConfigurationError, "Unknown option(s): #{unknown.join(", ")}" if unknown.any? @uri = uri # An explicit nil means "the default" (`headers: nil` must not crash every # request), and `default.dup` keeps the DEFAULTS hashes and arrays from # being shared — and mutated — across Configuration instances. DEFAULTS.each do |option, default| instance_variable_set("@#{option}", [option].nil? ? default.dup : [option]) end validate_polymorphic_relations validate_table_lists # Only derivable from the conventional endpoint path: substituting on any # other uri would silently post metadata commands to the GraphQL endpoint. @metadata_uri ||= uri.include?('/v1/graphql') ? uri.sub('/v1/graphql', '/v1/metadata') : nil end |
Instance Attribute Details
#excluded_tables ⇒ Object (readonly)
Returns the value of attribute excluded_tables.
17 18 19 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 17 def excluded_tables @excluded_tables end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
17 18 19 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 17 def headers @headers end |
#included_tables ⇒ Object (readonly)
Returns the value of attribute included_tables.
17 18 19 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 17 def included_tables @included_tables end |
#metadata_uri ⇒ Object (readonly)
Returns the value of attribute metadata_uri.
17 18 19 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 17 def @metadata_uri end |
#polymorphic_relations ⇒ Object (readonly)
Returns the value of attribute polymorphic_relations.
17 18 19 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 17 def polymorphic_relations @polymorphic_relations end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
17 18 19 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 17 def timeout @timeout end |
#type_values ⇒ Object (readonly)
Returns the value of attribute type_values.
17 18 19 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 17 def type_values @type_values end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
17 18 19 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 17 def uri @uri end |
Instance Method Details
#table_allowed?(*table_names) ⇒ Boolean
Accepts every spelling a table goes by (root field and type name): an exclusion must hold under renaming, or it would silently re-expose data.
42 43 44 45 46 47 |
# File 'lib/forest_admin_datasource_graphql_hasura/configuration.rb', line 42 def table_allowed?(*table_names) return false if table_names.any? { |name| excluded_tables.include?(name) } return (table_names & included_tables).any? unless included_tables.nil? true end |