Catalog Service and API Mesh
适用于Adobe Developer App Builder🔗的API Mesh使开发人员能够使用Adobe I/O Runtime将私有或第三方API和其他接口与Adobe产品集成。
将API网格与目录服务结合使用的第一步是将API网格连接到实例。 请参阅创建网格中的详细说明。
要完成安装,请安装Adobe Developer CLI包。
在Adobe I/O Runtime上配置Mesh后,请运行以下命令以将CommerceCatalogServiceGraph
源添加到您的网格。
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网格示例
API网格允许用户使用外部数据源来增强您的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