Skip to main content
Version: 4.1

Overwrite Default Queries

CoreShop Headless provides a simple way to overwrite the default queries. There are two ways to overwrite the default queries.

Extend Inputs of a Query

CoreShop Headless uses a similar approach as Symfony Form to extend the inputs of a query. You can extend an existing Input Type by creating a new Input Type Extension. For example:

<?php

declare(strict_types=1);

namespace CoreShop\Bundle\HeadlessBundle\InputType;

use Symfony\Component\OptionsResolver\OptionsResolver;

class AddToOrderInputItemTypeExtension implements DataHubInputTypeExtensionInterface
{
public function __construct(
private InputTypeFactoryInterface $inputTypeFactory,
) {
}

public function extendType(array $type, array $options): ?array
{
$type['fields']['orderItem']['type'] = $this->inputTypeFactory->buildType(OrderItemInputType::class, ['allow_units' => true]);

return $type;
}

public function getExtendedTypes(): ?array
{
return [
AddToOrderInputType::class,
];
}

public function configureOptions(OptionsResolver $optionsResolver): void
{
}
}

You also must register the Input Type Extension as a service and tag it with coreshop_headless.input_type_extension:

services:
CoreShop\Bundle\HeadlessBundle\InputType\AddToOrderInputItemTypeExtension:
arguments:
- '@CoreShop\Bundle\HeadlessBundle\InputType\InputTypeFactoryInterface'
tags:
- { name: coreshop.datahub.input_type_extension }

Since it only makes sense to then also extend the Command Handler, you can also do that by decorating the existing one:

services:
App\CoreShop\Headless\CommandHandler\AddToOrderHandler:
decorates: 'CoreShop\Bundle\HeadlessBundle\CommandHandler\AddToOrderHandler'

Your Input Arguments are then passed in the last argument of the Command called $args