graycore / magento2-graphql-introspection-cache
v0.1.2
2022-08-25 20:19 UTC
Requires
- php: >=7.4
- magento/framework: ^102.0 || ^103.0
- magento/module-catalog: ^103.0 || ^104.0
- magento/module-eav: ^102.0
- magento/module-graph-ql: ^100.0.0
- magento/module-graph-ql-cache: ^100.0.0
Requires (Dev)
- magento/magento-coding-standard: >=6.0
- phpunit/phpunit: ^8.0 || ^9.0
- squizlabs/php_codesniffer: ^3.0
README
此模块允许您使用与缓存常规 GraphQL 解析器相同的机制来缓存 introspection 查询。
这有助于最小化 Magento 的启动次数。
以下 introspection 类型默认支持
- ProductAttributeFilterInput
此模块是 实验性的,它包含针对旧版 Magento 版本(<2.4.2)的 BC 修复。当支持这些版本结束时,类内部结构可能会发生变化。
入门指南
此模块旨在使用 composer 安装。从您的 Magento 2 项目根目录开始
- 下载包
composer require graycore/magento2-graphql-introspection-cache
- 启用包
./bin/magento module:enable Graycore_GraphQlIntrospectionCache
用法
您可以通过添加一些 di.xml 来添加自己的 introspection 缓存身份。
<type name="Graycore\GraphQlIntrospectionCache\Plugin\CachePlugin"> <arguments> <argument xsi:type="array" name="introspectionHandlers"> <item xsi:type="object" name="NameOfInspectedType">Namespace\Module\Model\Cache\Identity\Introspection\NameOfInspectedType</item> </argument> </arguments> </type>
您的类必须实现 Magento\Framework\GraphQl\Query\Resolver\IdentityInterface
。
有关 GraphQL 缓存身份的更多信息,请访问 官方文档。
内部实现
- 在
QueryProcessor::process
上创建了一个前置插件来设置自定义的ReferenceExecutor
。此ReferenceExecutor
使用对象管理器实例化,以便我们可以在后续阶段使用插件。 - 在
ReferenceExecutor::doExecute
上创建了一个后置插件。此插件确定我们是否正在处理 introspection 请求以及是否为其注册了缓存身份。如果有,它将尝试生成缓存标签并将其添加到请求中。
查看单元/集成测试以获得更好的了解。