yireo / magento2-graph-ql-schema-manipulation
Magento module to manipulate the GraphQl schema
Yireo GraphQlSchemaManipulation
Magento 2 module to manipulate the GraphQL schema before it is being used. This can be useful when trying to remove endpoints that are added by monolithic extensions and perhaps other use-cases.
Installation
composer require yireo/magento2-graph-ql-schema-manipulation
bin/magento module:enable Yireo_GraphQlSchemaManipulation
Usage
To manipulate the schema, create a class that implements SchemaConfigManipulatorInterface. It receives the full schema config (as read from all schema.graphqls files), keyed by type name. Use the SchemaConfigEditor to remove fields, arguments and enum values of a specific type:
use Yireo\GraphQlSchemaManipulation\Schema\SchemaConfigEditor;
use Yireo\GraphQlSchemaManipulation\Schema\SchemaConfigManipulatorInterface;
class ExampleSchemaManipulator implements SchemaConfigManipulatorInterface
{
public function __construct(
private readonly SchemaConfigEditor $schemaConfigEditor
) {
}
public function manipulate(array $schemaConfig): array
{
$schemaConfig = $this->schemaConfigEditor->removeField($schemaConfig, 'Query', 'isEmailAvailable');
$schemaConfig = $this->schemaConfigEditor->removeArgument($schemaConfig, 'Query', 'products', 'search');
return $this->schemaConfigEditor->removeEnumValue($schemaConfig, 'CurrencyEnum', 'EUR');
}
}
When a field or argument is removed from an interface (like ProductInterface), it is also removed from all types implementing that interface (like SimpleProduct), so the schema stays consistent. A field with the same name in another type or input is left alone.
Next, add this class to this module with a global etc/di.xml file (not etc/graphql/di.xml, because the schema config is cached once for all areas):
<?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\ManipulateSchemaConfig">
<arguments>
<argument name="schemaConfigManipulators" xsi:type="array">
<item name="example" xsi:type="object">ExampleSchemaManipulator</item>
</argument>
</arguments>
</type>
</config>
The manipulated schema config is stored in the config cache. After changing a manipulator, run bin/magento cache:clean config. If a manipulator returns an invalid schema config, a LogicException naming the manipulator is thrown.
Limitations
Removing a field from the GraphQL schema only hides it from GraphQL: queries for it fail validation and introspection no longer shows it. It does not disable the underlying feature. Resolver classes, REST endpoints (like V1/customers/isEmailAvailable) and controllers offering the same functionality are still available. Do not rely on this module as your only access control.
Deprecated: ManipulationInterface
The older ManipulationInterface (added to Plugin\AddSchemaManipulators via its schemaManipulators argument) still works, but is deprecated. Its manipulateFieldsConfig() method receives the Magento\Framework\GraphQl\Config\Element\Field objects of every single type, input and interface, without the type name. Removing a field by name therefore removes it from every type and input that has a field with that name.
Current status
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog,
and this project adheres to Semantic Versioning.
[Unreleased]
[0.0.3] - 25 November 2026
Added
- Schema config manipulators (
SchemaConfigManipulatorInterface) that receive the GraphQL schema config keyed by type name, so fields, arguments and enum values can be removed from one specific type; removing from an interface also removes it from the implementing types - Field manipulators now also apply to interface fields, which were skipped before
- Support for PHP 8.4 and 8.5
- README documentation of schema config manipulators and their limits
Changed
- The field-level
ManipulationInterfaceis deprecated in favour of schema config manipulators - Manipulator output is now validated, giving a clear error when a manipulator returns invalid data
Removed
- Support for PHP 8.1
Requires 2
| Package | Constraint |
|---|---|
| magento/framework | ^103.0 |
| php | >=8.2 <8.6 |
Requires-dev 2
| Package | Constraint |
|---|---|
| phpunit/phpunit | ^10.5 |
| yireo/magento2-integration-test-helper | ~0.0 |
Compatibility
Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.
Code Quality
Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.
Static analysis
Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.
Tests
Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.
Unit tests
Security
Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.
More from yireo
View vendorReplace bundled third party packages from Magento
N/A
Turn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.