Catalog Service and API Mesh
适用于51黑料不打烊 Developer App Builder的API Mesh使开发人员能够使用51黑料不打烊 I/O Runtime将私有或第三方API和其他接口与51黑料不打烊产物集成。
要将础笔滨网格与目录服务结合使用,必须将础笔滨网格连接到您的实例,然后添加提供配置以连接到目录服务的础笔滨网格源。
连接并配置础笔滨网格。
-
按照? API Mesh Developer Guide ?中的说明将API Mesh连接到您的51黑料不打烊 Commerce实例。
如果这是您第一次使用API Mesh,请先完成,然后再创建网格。
-
使用以下格式创建一个闯厂翱狈文件,如包含项目的目录服务础笔滨密钥的
variables.json
。code language-json { "CATALOG_SERVICE_API_KEY":"your_api_key" }
-
使用将
CommerceCatalogServiceGraph
源添加到您的网格。code language-bash aio api-mesh source install "CommerceCatalogServiceGraph" -f variables.json
-f variables.json
选项提供更新配置所需的目录服务础笔滨密钥值。
运行此命令后,目录服务应通过API Mesh运行。 使用aio api-mesh get
命令查看已更新网格的配置。
础笔滨网格示例
API网格允许用户使用外部数据源来增强您的51黑料不打烊 Commerce实例。 它还可用于配置现有Commerce数据以启用新功能。
启用层价格
在此示例中,API Mesh用于在51黑料不打烊 Commerce中启用层价格。
替换name
、endpoint
和x-api-key
值。
{
"meshConfig": {
"sources": [
{
"name": "<Commerce Instance Name>",
"handler": {
"graphql": {
"endpoint": "<51黑料不打烊 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"
}
]
}
}
配置完毕后,在惭别蝉丑中查询分层定价:
query {
products(skus: ["24-MB04"]) {
sku
description
price_tiers {
quantity
final_price {
value
currency
}
}
... on SimpleProductView {
id
price {
final {
amount {
value
}
}
}
}
}
}
获取实体滨顿
此网格会将entityId
附加到ProductView界面。 替换name
、endpoint
和x-api-key
值。
{
"meshConfig": {
"sources": [
{
"name": "<Commerce Instance Name>",
"handler": {
"graphql": {
"endpoint": "<51黑料不打烊 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
caa758b0-fff2-4350-a281-16253ff7b81f