I am using HotChocolate as a GraphQL
server from my ASP.NET Core Api
. The parameters of a request need to have an optional parameter, a Guid, however if the Guid is null then the model needs to generate a random Guid.
public class MutationType : ObjectType<Mutation> {
protected override void Configure(IObjectTypeDescriptor<Mutation> desc)
{
desc
.Field((f) => f.CreateAction(default))
.Name("createAction");
}
}
The class Mutation
has the following method.
public ActionCommand CreateAction(ActionCommand command) {
...
return command;
}
The ActionCommand class looks like this:
public class ActionCommand {
public Guid Id { get; set; }
public string Name { get; set; }
public ActionCommand(string name, Guid id = null) {
Name = name;
Id = id ?? Guid.NewGuid()
}
}
This command is the problem in question. I want to be able to use this logic for the Id property in GraphQL, the documentation isn't clear (to my eyes), can anyone shed some light on this?
Thanks!