Skip to content

Exposing custom GQL Mutations

Sometimes we will want to build the MT event that we are publishing in a more complex fashion than just setting the CorrelationId.

In those cases, we can create a class to represent the mutation:

C#
public class TestMutation : IMutation
{
    private readonly IPublishEndpoint endpoint;

    public TestMutation(IPublishEndpoint endpoint)
    {
        this.endpoint = endpoint;
    }

    public async Task<Guid> DoSomething(SomeDto input)
    {
        var id = NewId.NextGuid();

        // [..] generate and publish the message using the endpoint

        return id;
    }
}

The method may require inputs, like a DTO that we'll use to build the message. It is also quite common to return the correlation id that we generated for the operation.