Asset Types
An Asset Type is a root node in the Asset graph space. It is a custom actor type that defines the kind of business data a type holds, what sub-types may be present, and any relations with other resources. For instance, a Vendor Asset type models vendor business data.
Asset Types are unavoidable because every Asset instance must be tied to a custom type.
Start by defining a new Asset type key in a YAML file with the uri path as /registry/actors/custom/asset/types/<ASSET TYPE KEY>. The Graph will automatically index the new type.
Keep in mind that Asset type definitions have a schema.
Example: Create a New Vendor Asset Type
Create a New Vendor Asset Type
This example models a Vendor data model and includes two types of vendors, local and global vendors. 1. Create a YAML file containing the necessary fields. ```filtrera // newAssetType.yaml uri: /registry/actors/custom/asset/types/vendor spec: value: graphSetName: vendor itemEdgeName: head defaultNumberPrefix: "VE" items: localVendor: graphSetName: localVendors edgeName: localVendors relations: supplies: node: 'order' cardinality: many globalVendor: graphSetName: globalVendors edgeName: globalVendors relations: payments: node: 'order' cardinality: many relations: order: node: 'order' cardinality: many ``` 2. Send the YAML file to the Registry via the CLI using `h_ manage apply` ``` h_ manage apply .\newAssetType.yaml -s demo-ecom ``` **Response** ``` Updated registry keys: - actors/asset/types/vendor - Old: undefined - New: {"graphSetName":"vendor","itemEdgeName":"head","defaultNumberPrefix":"VE","items":{"localVendor":{"graphSetName":"localVendors","edgeName":"localVendors","relations":{"supplies":{"node":"order","cardinality":"many"}}},"globalVendor":{"graphSetName":"globalVendors","edgeName":"globalVendors","relations":{"payments":{"node":"order","cardinality":"many"}}}},"relations":{"order":{"node":"order","cardinality":"many"}}} ```Choose unique names for asset type definitions, If now, existing types may be overwritten.
TIP
Always run h_ manage signals after applying a Type definition. It lists changes including any type definition errors.
Example: Query the Vendor Asset
Query the Vendor Asset from the Graph
Let's query the Graph to return all Vendors. We will also return local and global vendors for each Vendor. Send the following `POST` request to `/resources/graph`. You must a valid JSON body containing the `graphSetName` or `rootEdgeName` of the node. In this case, from the type definition, it is `vendor`. **Request**You can also customize graph queries to make them more specific.
TIP
Run GET /resources/graph before a query. It returns all existing graph nodes and edges so you can correctly query the graph.