初识Magento2.3的GraphQl API
7天成为Magento系统架构师,现在开始学习Magento全栈开发!
《Magento2.X企业级开发实战》
阅读导航
Magento2.3开始,Magento全面引入GraphQl构建API
什么是 GraphQl
本文假设已经了解了GraphQl.
网上描述最多的是一种用于 API 的查询语言
简单提取了如下特点:
– 语法易于理解
– 准确获取数据
– 数据没有冗余
– 能应对业务变化
– 减少API请求次数
Magento2.3增加的GraphQl相关模块
BundleGraphQl
CatalogGraphQl
CatalogInventoryGraphQl
CatalogUrlRewriteGraphQl
CmsGraphQl
CmsUrlRewriteGraphQl
ConfigurableProductGraphQl
CustomerGraphQl
DirectoryGraphQl
DownloadableGraphQl
EavGraphQl
GraphQl
GroupedProductGraphQl
QuoteGraphQl
SalesGraphQl
SendFriendGraphQl
StoreGraphQl
SwatchesGraphQl
TaxGraphQl
ThemeGraphQl
UrlRewriteGraphQl
WeeeGraphQl
WishlistGraphQl
Magento GraphQl API调用
推荐用chrome的调试插件ChromeiQL测试, 截图如下:
注意:
1. magento后台需要开启游客访问API的权限
1. 红圈部分 需要切换到magento的开发模式developer
1. 这里忽略了授权部分,大部分API接口需要特定权限才能访问
你也可以用常用的API测试工具测试
POST https://www.magento2.top/graphql
Headers Content-Type:application/json
body参数
{
"query": "{cmsPage (id:2){title content}}"
}
上面参数意思是查询cmsPage id=2 的数据,只需要返回title和content字段的值
返回结果
{
"data": {
"cmsPage": {
"title": "Magento2演示",
"content": "
CMS homepage content goes here.
rn"
}
}
}
调试插件 ChromeiQL
安装地址https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij
文章来源于互联网:初识Magento2.3的GraphQl API
如无特殊说明或标注,任何个人或组织,复制、转载、采集本站内容请注明:
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。