yireo/magento2-graph-ql-schema-manipulation

用于操作 GraphQL 模式的 Magento 模块

安装: 0

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

类型:magento2-module

0.0.1 2024-08-06 18:40 UTC

This package is auto-updated.

Last update: 2024-09-06 18:47:50 UTC


README

Magento 2 模块,用于在 GraphQL 模式被使用之前对其进行操作。这在尝试删除由单体扩展添加的端点或其他用例时可能很有用。

安装

composer require yireo/magento2-graph-ql-schema-manipulation
bin/magento module:enable Yireo_GraphQlSchemaManipulation

使用

要自己操作模式,您需要创建一个类似于以下示例的类

class ExampleSchemaManipulator implements \Yireo\GraphQlSchemaManipulation\Schema\ManipulationInterface
{
    public function manipulateResolvedTypes(array $resolvedTypes): array
    {
        foreach ($resolvedTypes as $resolvedTypeIndex => $type) {
            if (stristr($type->name(), 'Foobar')) {
                unset($resolvedTypes[$resolvedTypeIndex]);
            }
        }
        
        return $resolvedTypes;
    }
}

接下来,创建一个 di.xml 文件,将此类添加到此模块

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Yireo\GraphQlSchemaManipulation\Plugin\AddSchemaManipulators">
        <arguments>
            <argument name="schemaManipulators" xsi:type="array">
                <item name="example" xsi:type="object">ExampleSchemaManipulator</item>
            </argument>
        </arguments>
    </type>
</config>