Version: Edit on GitHub

Add a Custom Query Operator

For adding a new query operator two steps are necessary:

  • add a type definition
  • add the operator implementation

Type definition

Add a section similar to this one to your services.yml file.

        class: Pimcore\Bundle\DataHubBundle\GraphQL\QueryOperatorConfigGenerator\MyCustomOperator
            - { name: pimcore.datahub.graphql.dataobjectquerytypegenerator, id: typegenerator_queryoperator_mycustomoperator }                        

For reference, have a look at a look at the Trimmer operator.

Operator Implementation

You have to provide both JavaScript code dealing with the UI configuration aspects specific to your operator and the server-side PHP implementation doing the actual calculations.

A JS sample can be found here. Note that the namespace would be pimcore.plugin.datahub.operator.mycustomoperator.

Make sure, that your extension gets loaded. See Pimcore Bundles docs page for further details.

Next thing is to provide the server-side implementation. A sample can be found here.

Finally, we have to define how the operator instances get created. In most cases we use the DefaultOperatorFactory for that:

        class: Pimcore\Bundle\DataHubBundle\GraphQL\Query\Operator\Factory\DefaultOperatorFactory
            $className: Pimcore\Bundle\DataHubBundle\GraphQL\Query\Operator\MyCustomOperator
            - { name: pimcore.datahub.graphql.dataobjectqueryoperator_factory, id: mycustomoperator }