graycore/magento2-graphql-introspection-cache

v0.1.2 2022-08-25 20:19 UTC

This package is auto-updated.

Last update: 2024-09-19 16:35:40 UTC


README

Packagist Downloads Packagist Version Packagist License Unit Test Integration Test

此模块允许您使用与缓存常规 GraphQL 解析器相同的机制来缓存 introspection 查询。

这有助于最小化 Magento 的启动次数。

以下 introspection 类型默认支持

  • ProductAttributeFilterInput

此模块是 实验性的,它包含针对旧版 Magento 版本(<2.4.2)的 BC 修复。当支持这些版本结束时,类内部结构可能会发生变化。

入门指南

此模块旨在使用 composer 安装。从您的 Magento 2 项目根目录开始

  1. 下载包
composer require graycore/magento2-graphql-introspection-cache
  1. 启用包
./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 请求以及是否为其注册了缓存身份。如果有,它将尝试生成缓存标签并将其添加到请求中。

查看单元/集成测试以获得更好的了解。