My Products
Help
omelhus
PARTNER

Suggest values without suggest: ?

by omelhus

Hey @Marius Bancila,

 

If i run a create-mutation with null-values for some properties, will it suggest values for those properties, even though I haven't set suggest for them? If so, this is a major issue.

 

Both (System.Text.Json and NewtonSoft) will serialize all unset properties of a class to null, so then the suggest-value-logic will run for all properties where a value is not set.

 

It's fundamental that you don't run suggest on a field unless suggest is provided as a parameter to the create-mutation.

8 REPLIES 8
AndreasDevDotNet
CONTRIBUTOR ***

by AndreasDevDotNet (Updated ‎27-11-2023 13:10 by AndreasDevDotNet )

 

 

I agree that the way suggest is implemented is not the best way, in my Business NXT Client I have implemented it like this:

 

 

var orderInputList = new List<Order_Input> { new Order_Input { OrderType = 1, CustomerNo = 123456, OrderDateAsDate = new DateOnly(2023, 12, 19) } };

var insertMutation = vbNxtClient.UseCompanyMutationFor<Order>(4816282)
                            .Insert(orderInputList)
                            .Select(x => new { x.OrderNo, x.OrderStatus1Flags })
                            .Suggest(x => new {x.OrderNo})
                            .CreateMutation();

 

 

 

This results in the following GraphQL:

 

 

mutation 
{
    useCompany(no: 4816282)
    {
        mutationResult : order_create
        (
            values:[{orderNo:null,orderType:1,orderDateAsDate:"2023-12-19",customerNo:123456}]
        )
        {
            affectedRows
            items
            {
                orderNo
                orderStatus1Flags
            }
        }
    }
}

 

 

I would rather like it to be like this:

 

 

mutation 
{
    useCompany(no: 4816282)
    {
        mutationResult : order_create
        (
            values:[{orderType:1,orderDateAsDate:"2023-12-19",customerNo:123456}]
            suggest:[{orderNo}]
        )
        {
            affectedRows
            items
            {
                orderNo
                orderStatus1Flags
            }
        }
    }
}

 

 

omelhus
PARTNER

by omelhus

Yeah, but this still skips the reason for the null-debacle. It's because you need to set fields in a set order, like defining currency before you set an exchange rate. You code should then be something like:

var orderInputList = new List<Order_Input> { new Order_Input { OrderNo = null, OrderType = 1, CustomerNo = 123456, OrderDateAsDate = new DateOnly(2023, 12, 19) } };

var insertMutation = vbNxtClient.UseCompanyMutationFor<Order>(4816282)
                            .Insert(orderInputList)
                            .Select(x => new { x.OrderNo, x.OrderStatus1Flags })
                            .Suggest(x => new {x.OrderNo})
                            .CreateMutation();

 

But still I think that Visma should support generic clients like StrawberryShake, and not be tied to a custom client.

 

I like your fluent approach though. Managed to get it up on github yet?

by Marius Bancila

Yes, I understand that not everything is plain forward and need to read the documentation for different things. But I don't think there are many APIs that you can use without going through the docs.

 

That doesn't mean we don't want to improve. We've been opened to ideas. So if you can explain with examples what you suggest I'll look into it. But honestly, the title and phrases like "using the suggest:-functionality" are confusing to me and I don't understand what you really want.

omelhus
PARTNER

by omelhus (Updated ‎24-11-2023 16:43 by omelhus PARTNER )

I'd like us to do suggest: { voucherNo: true } like before, and rather let a voucherNo: null in the entity define the order of the properties.

 

If I set the json-serializer to omit null values, I'm no longer able to suggest values at all.

by Marius Bancila

Both System.Text.Json and NewtonSoft allow you to ignore properties that are null. Here is an example of how to do that: https://stackoverflow.com/questions/6507889/how-to-ignore-a-property-in-class-if-null-using-json-net.

 

Actually suggest works exactly on null, because that's the only value that can be assigned to any field, regardless the type.

omelhus
PARTNER

by omelhus

Using this method I'm either unable to suggest values at all, or I have to suggest values for all fields.

 

Please only suggest values if the field is included in suggest:. This is making it really troublesome to use input variables with .NET applications. Javascript has the notion of null or undefined, where undefined will be omitted, and null values included, but .NET doesn't. It's all or nothing.

omelhus
PARTNER

by omelhus

Haven't heard anything about this issue for a little while. Any plans to address these issues?

omelhus
PARTNER

by omelhus

I'm still really unhappy with this doing suggest without setting it in suggest:. It's not clear (unless you read the docs, of course) that this will happen, but by using the suggest:-functionality it's really clear what the intent is.