I have nested entities say like as below,
public class TestA
{
public TestB TestB {get; set;}
public string ProjectNumber { get; set; }
}
public class TestB
{
public TestC TestC{ get; set; }
}
public class TestC
{
public double AValue{get; set;}
public double BValue{get; set;}
}
Now I am querying TestA using EFcore with graphql like as below
[Authorize]
[UseDbContext(typeof(APIDbContext))]
[UseSorting]
public IQueryable<TestA> TestA([ScopedService] APIDbContext dbContext, [GraphQLNonNullType] string projectNumber)
{
var testAValues = dbContext?.TestA
.Where(s => s.ProjectNumber == projectNumber) ?? throw new ArgumentNullException(nameof(dbContext));
return testAValues;
}
Now I am trying to round the AValue
and BValue
to the nearest 5. So in the process, I have written like this below
public class TestAExtentions : ObjectType<TestA>
{
private static double FormatValues(double value) => Math.Round(value / 5, MidpointRounding.AwayFromZero) * 5;
protected override void Configure(IObjectTypeDescriptor<TestA> descriptor)
{
_ = descriptor ?? throw new ArgumentNullException(nameof(descriptor));
descriptor.Field(a => a.TestB.TestC.AValue).Type<DecimalType>()
.Resolve(context => context.ArgumentValue<>); // How to resolve and round the AValue and BValue using resolver
}
}
But I am stuck in the above on what to write inside the resolver function. Could anyone please let me know how to do the rounding of the values before it is available to the client?
I am using .Net core, EF core, and Hot Chocolate graphQL.
Many thanks in advance!!!