Skip to content

Exposing custom GQL Mutations

Mutations exposed through the module API use a default, generic resolver that usually fits most use cases. We still can declare mutations with custom resolution logic for any corner cases.

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.