I'm using graphql-dotnet (dotnet GraphQl) for implementing GraphQL in DotNet Core 2.1. I have the following classes:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
}
public class CustomerInputType : InputObjectGraphType
{
public CustomerInputType()
{
Name = "CustomerInput";
Field<NonNullGraphType<IntGraphType>>(nameof(Customer.Id));
Field<NonNullGraphType<StringGraphType>>(nameof(Customer.Name));
}
}
public class CustomerOutputType : ObjectGraphType<Customer>
{
public CustomerOutputType()
{
Name = "Customer";
Field<NonNullGraphType<IntGraphType>>(nameof(Customer.Id));
Field<NonNullGraphType<StringGraphType>>(nameof(Customer.Name));
}
}
public class CustomerMutation : ICustomerMutation
{
public void Resolve(GraphQLMutation graphQLMutation)
{
graphQLMutation.FieldAsync<CustomerOutputType, Customer>
(
"createCustomer",
arguments: new QueryArguments
(
new QueryArgument<NonNullGraphType<CustomerInputType>> { Name = "customer"}
),
resolve: context =>
{
var customer = context.GetArgument<Customer>("customer");
return Task.FromResult(customer);
}
);
}
}
Here's the input I'm sending to this mutation via GraphIQL:
mutation createCustomer
{
createCustomer(customer:{id: 19, name: "Me"})
{id name}
}
Here's the input inside C# Code:
The watch is showing the value of id to be 0x00000013
instead of 19
.
Here's the output in GraphIQL:
I need to use the value of 19
for further processing in a repository which is injected into this mutation. However, when I pass the Customer object to the repository, the value of id in Customer object is 0x00000013
which causes further downstream processing to fail because it's expecting 19
instead of 0x00000013
.
Why is the value of the object 0x00000013
inside C# code yet gets translated to the actual value in GraphIQL? How do I cast the value of Cusutomer.id to its correct integer value for further processing before the mutation returns results?