docs: improve schema extensibility documentation and samples

- Added TSDoc for 'createHierarchicalValueFieldResolver'.

- Updated README with 'Extending the Schema' guide and Zabbix preconditions.

- Migrated all MQTT items to Agent 2 'mqtt.get' format across documentation and test data.

- Added 'docs/sample_import_distance_tracker_template.graphql' as a schema extension example.

- Verified all 38 tests pass.

(cherry picked from commit bff9ee6d2e)
This commit is contained in:
Andreas Hilbig 2026-01-26 17:49:31 +01:00
parent 023198d3fe
commit d4cb9fecab
5 changed files with 245 additions and 38 deletions

View file

@ -16,6 +16,21 @@ function defaultKeyMappingFunction(key: string): string {
return words.join("")
}
/**
* Creates a resolver for an object type where each field is resolved by mapping Zabbix items or tags
* to a hierarchical structure based on field names or Zabbix keys.
*
* This function iterates over all fields of the specified GraphQL type and assigns a resolver
* that uses the provided `sourceFieldMapper` to retrieve the value. It automatically detects
* whether a field is a scalar or an object type to guide the mapping process.
*
* @param schema - The executable GraphQL schema.
* @param typename - The name of the GraphQL type for which to create the resolver.
* @param sourceFieldMapper - A function that maps a field name to its value from the parent object.
* It receives the field name, the parent object, and a boolean indicating
* if the requested field is an object type.
* @returns A resolver object containing field-to-function mappings for the specified type.
*/
export function createHierarchicalValueFieldResolver(
schema: any, typename: string,
sourceFieldMapper: (fieldname: string, parent: any, objectTypeRequested: boolean) => { [p: string]: any } | null): {