Application Modules

Resource Aliasing for Apps

Handle resource aliasing in app modules using output artifacts, introspection, or config maps as workarounds.

Resource Aliasing for Apps

While dependency aliasing works flawlessly for engine-level files (models, compliance, output), it introduces a challenge for Application Modules (custom web applications in the app folder). Because the application files are served statically, if a module’s frontend hardcodes a GraphQL query for query { auth { ... } }, it will fail when the engine has aliased auth to dns_auth.

Possible Solutions:

  1. Output Artifacts as an API: The most robust solution is to define an [output] generator in the module. Output definitions are processed by the engine and thus respect aliasing automatically. The frontend application can then fetch the generated JSON artifact from the /api/outputs/index REST endpoint instead of querying GraphQL directly.
  2. Dynamic Introspection: The frontend can run a GraphQL introspection query or call listResourceTypes on load to dynamically discover the active label (e.g., by matching expected properties).
  3. Configuration Outputs: The module can generate a small JSON output artifact acting as a configuration map. The frontend can fetch this configuration on startup to construct dynamic GraphQL queries that use the correct aliased resource types.

Example: Configuration Outputs

First, define an output generator in your module (e.g., data/output/app_config.toml) that generates a JSON artifact mapping the expected resource names to their active aliases using the RESOURCE_ALIASES global variable:

[[output]]
resource_type = "hybriddns_config"
name = "config"
filename = "config.json"
mimetype = "application/json"
template = '''
{
  "auth": "{{ RESOURCE_ALIASES.auth | default(value='auth') }}",
  "zone": "{{ RESOURCE_ALIASES.zone | default(value='zone') }}"
}
'''

Then, in your frontend application (e.g., data/app/index.html), fetch this artifact on startup and use it to construct dynamic GraphQL queries:

let authResource = 'auth';
let zoneResource = 'zone';

async function loadConfig() {
    try {
        const res = await fetch('/api/outputs/hybriddns_config/config/config.json');
        if (res.ok) {
            const config = await res.json();
            if (config.auth) authResource = config.auth;
            if (config.zone) zoneResource = config.zone;
        }
    } catch (e) {
        console.warn('Failed to load configuration map', e);
    }
}