Class: ForestAdminDatasourceGraphqlHasura::Introspection::Introspector
- Inherits:
-
Object
- Object
- ForestAdminDatasourceGraphqlHasura::Introspection::Introspector
- Defined in:
- lib/forest_admin_datasource_graphql_hasura/introspection/introspector.rb
Overview
Builds the datasource structure from the GraphQL introspection query (tables, columns, relationship fields) and the Hasura metadata API (relationship column mappings), when the latter is reachable.
Constant Summary collapse
- INTROSPECTION_QUERY =
<<~GRAPHQL.freeze query IntrospectSchema { __schema { types { name kind fields { name type { ...TypeRef } } enumValues { name } } queryType { name fields { name type { ...TypeRef } args { name type { name kind ofType { name kind } } } } } } } fragment TypeRef on __Type { name kind ofType { name kind ofType { name kind ofType { name kind } } } } GRAPHQL
- SCALAR_TYPES =
%w[ Int Float String Boolean ID uuid timestamptz timestamp date time timetz jsonb json numeric bigint smallint integer real double_precision text varchar char bpchar bytea inet cidr macaddr money interval bit xml citext _text _int4 _uuid _jsonb ].to_set.freeze
- TEXT_TYPES =
A Postgres enum, or any scalar Hasura exposes under a custom name (
macaddr, a domain type…), displays as a string but has no_like/_ilikein its comparison expression. %w[String ID text varchar char bpchar citext bytea].to_set.freeze
- EXCLUDED_PREFIXES =
%w[__ hdb_ pg_ information_schema].freeze
Instance Method Summary collapse
-
#initialize(client, configuration) ⇒ Introspector
constructor
A new instance of Introspector.
- #introspect ⇒ Array<Table>
Constructor Details
#initialize(client, configuration) ⇒ Introspector
Returns a new instance of Introspector.
64 65 66 67 |
# File 'lib/forest_admin_datasource_graphql_hasura/introspection/introspector.rb', line 64 def initialize(client, configuration) @client = client @configuration = configuration end |
Instance Method Details
#introspect ⇒ Array<Table>
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/forest_admin_datasource_graphql_hasura/introspection/introspector.rb', line 70 def introspect types, query_fields = introspection_payload = @client. @type_map = build_type_map(types) @custom_root_fields = {} @relationship_mappings = ? safe_relationship_mappings() : {} @primary_keys = parse_primary_keys(query_fields) parse_tables(query_fields) end |