0

My architecture is based on Symfony 4.4 / ApiPLatform / Mercure / Angular 9. I've made working a simple push from Mercure by adding mercure:true in my resources.yaml ApiPlatform conf file. Now I need to make updates being private. So with ApiPlatform I have to add the parameter private:true. But the API response is now :

Targets do not exist anymore since Mercure 0.10. Mark the update as private instead or downgrade the Mercure Component to version 0.3

And this is my yaml configuration :

resources:
    App\Entity\Order:
        attributes:
            mercure:
                - private: true
                - topics: ['object.getMercureTopics()']

What should be the right configuration ?

Samy AZ
  • 31
  • 5

1 Answers1

2

In fact, ExpressionLanguage is not evaluated in each option like I thought, it is only evaluated if the configured option is a string. So, the solution is the following if needed ExpressionLanguage for topics (or evrything else) :

public function getMercureOptions()
{
    $topic = sprintf(
        '%s/%s',
        self::MERCURE_TOPIC_PREFIX,
        $this->getSomethingFromTheObject()
    );

    return [
        "private" => true,
        "topics" => [$topic]
    ];
}

And then, the yaml configuration file should be :

resources:
    App\Entity\Order:
        attributes:
            mercure: "object.getMercureOptions()"
Samy AZ
  • 31
  • 5