DotNet Core's GraphQL casting parameter value to integer

0

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:

enter image description here

The watch is showing the value of id to be 0x00000013 instead of 19.

Here's the output in GraphIQL:

enter image description here

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?

c#
graphql
graphiql
graphql-dotnet
asked on Stack Overflow Jan 15, 2020 by Tom Schreck • edited Jan 16, 2020 by Tom Schreck

1 Answer

1

It's correct, the value is just being displayed as Hex. It's your inspector that's confusing you. 13 hex as binary is

10011

And that is decimal

19

https://www.rapidtables.com/convert/number/hex-to-decimal.html

answered on Stack Overflow Jan 16, 2020 by Zakk Diaz

User contributions licensed under CC BY-SA 3.0