Catalog Service and API Mesh
適用於Adobe Developer App Builder🔗的API Mesh可讓開發人員使用Adobe I/O Runtime將私人或協力廠商API和其他介面與Adobe產品整合。
搭配目錄服務使用API網狀架構的第一步,是將API網狀架構連線到您的執行個體。 請參閱建立Mesh中的詳細說明。
若要完成安裝,請安裝Adobe Developer CLI套件。
在Adobe I/O Runtime上設定Mesh後,請執行以下命令,將CommerceCatalogServiceGraph
來源新增至您的Mesh。
aio api-mesh:source:install "CommerceCatalogServiceGraph" -f variables.json
其中variables.json
是儲存Adobe I/O Runtime常用值的個別檔案。
例如,API金鑰可儲存在檔案中:
{
"CATALOG_SERVICE_API_KEY":"your_api_key"
}
執行此命令後,目錄服務應透過API Mesh執行。 您可以執行aio api-mesh:get
命令來檢視更新網格的組態。
API Mesh範例
API Mesh可讓使用者使用外部資料來源,以強化您的Adobe Commerce執行個體。 它也可用來設定現有的Commerce資料,以啟用新功能。
啟用層級價格
在此範例中,API Mesh是用來啟用Adobe Commerce中的層級價格。
取代name
、endpoint
和x-api-key
值。
{
"meshConfig": {
"sources": [
{
"name": "<Commerce Instance Name>",
"handler": {
"graphql": {
"endpoint": "<Adobe Commerce GraphQL endpoint>"
}
},
"transforms": [
{
"prefix": {
"includeRootOperations": true,
"value": "Core_"
}
}
]
},
{
"name": "CommerceCatalogServiceGraph",
"handler": {
"graphql": {
"endpoint": "https://commerce.adobe.io/catalog-service/graphql/",
"operationHeaders": {
"Magento-Store-View-Code": "{context.headers['magento-store-view-code']}",
"Magento-Website-Code": "{context.headers['magento-website-code']}",
"Magento-Store-Code": "{context.headers['magento-store-code']}",
"Magento-Environment-Id": "{context.headers['magento-environment-id']}",
"Magento-Customer-Group": "{context.headers['magento-customer-group']}"
},
"schemaHeaders": {
"x-api-key": "<YOUR API-KEY>"
}
}
}
}
],
"additionalTypeDefs": "extend interface ProductView {\n price_tiers: [Core_TierPrice]\n}\n extend type SimpleProductView {\n price_tiers: [Core_TierPrice]\n}\n extend type ComplexProductView {\n price_tiers: [Core_TierPrice]\n}\n",
"additionalResolvers": [
{
"targetTypeName": "ProductView",
"targetFieldName": "price_tiers",
"sourceName": "MagentoStageCore",
"sourceTypeName": "Query",
"sourceFieldName": "Core_products",
"requiredSelectionSet": "{\n items {\n sku\n price_tiers {\n quantity,\n final_price {\n value\n currency\n }\n }\n }\n }",
"sourceArgs": {
"filter.sku.eq": "{root.sku}"
},
"result": "items[0].price_tiers"
},
{
"targetTypeName": "SimpleProductView",
"targetFieldName": "price_tiers",
"sourceName": "MagentoStageCore",
"sourceTypeName": "Query",
"sourceFieldName": "Core_products",
"requiredSelectionSet": "{\n items {\n sku\n price_tiers {\n quantity,\n final_price {\n value\n currency\n }\n }\n }\n }",
"sourceArgs": {
"filter.sku.eq": "{root.sku}"
},
"result": "items[0].price_tiers"
},
{
"targetTypeName": "ComplexProductView",
"targetFieldName": "price_tiers",
"sourceName": "MagentoStageCore",
"sourceTypeName": "Query",
"sourceFieldName": "Core_products",
"requiredSelectionSet": "{\n items {\n sku\n price_tiers {\n quantity,\n final_price {\n value\n currency\n }\n }\n }\n }",
"sourceArgs": {
"filter.sku.eq": "{root.sku}"
},
"result": "items[0].price_tiers"
}
]
}
}
設定之後,請查詢Mesh以取得階層式定價:
query {
products(skus: ["24-MB04"]) {
sku
description
price_tiers {
quantity
final_price {
value
currency
}
}
... on SimpleProductView {
id
price {
final {
amount {
value
}
}
}
}
}
}
取得實體ID
此網格會將entityId
附加至ProductView介面。 取代name
、endpoint
和x-api-key
值。
{
"meshConfig": {
"sources": [
{
"name": "<Commerce Instance Name>",
"handler": {
"graphql": {
"endpoint": "<Adobe Commerce GraphQL endpoint>"
}
},
"transforms": [
{
"prefix": {
"includeRootOperations": true,
"value": "Core_"
}
}
]
},
{
"name": "CommerceCatalogServiceGraph",
"handler": {
"graphql": {
"endpoint": "https://catalog-service.adobe.io/graphql",
"operationHeaders": {
"Magento-Store-View-Code": "{context.headers['magento-store-view-code']}",
"Magento-Website-Code": "{context.headers['magento-website-code']}",
"Magento-Store-Code": "{context.headers['magento-store-code']}",
"Magento-Environment-Id": "{context.headers['magento-environment-id']}",
"x-api-key": "<YOUR_CATALOG_SERVICE_API_KEY>",
"Magento-Customer-Group": "{context.headers['magento-customer-group']}"
},
"schemaHeaders": {
"x-api-key": "<YOUR_CATALOG_SERVICE_API_KEY>"
}
}
}
}
],
"additionalTypeDefs": "extend interface ProductView {\n entityId: String\n}\n extend type SimpleProductView {\n entityId: String\n}\n extend type ComplexProductView {\n entityId: String\n}\n",
"additionalResolvers": [
{
"targetTypeName": "ComplexProductView",
"targetFieldName": "entityId",
"sourceName": "MagentoCore",
"sourceTypeName": "Query",
"sourceFieldName": "Core_products",
"requiredSelectionSet": "{ sku\n }",
"sourceSelectionSet": "{\n items {\n sku\n uid\n }\n }",
"sourceArgs": {
"filter.sku.eq": "{root.sku}"
},
"result": "items[0].uid",
"resultType": "String"
},
{
"targetTypeName": "SimpleProductView",
"targetFieldName": "entityId",
"sourceName": "MagentoCore",
"sourceTypeName": "Query",
"sourceFieldName": "Core_products",
"requiredSelectionSet": "{ sku\n }",
"sourceSelectionSet": "{\n items {\n sku\n uid\n }}",
"sourceArgs": {
"filter.sku.eq": "{root.sku}"
},
"result": "items[0].uid",
"resultType": "String"
}
]
}
}
現在可以查詢entityId
:
query {
products(skus: ["MH07"]){
sku
name
id
entityId
}
}
recommendation-more-help
7c786b3e-f793-4e26-b38a-3fe76d8eca72