to get a personalized navigation.
to get a personalized navigation.
Hi,
By using the @export directive I was hoping to be able to create an order with lines in the same request.
Example:
mutation CreateOrder($cid: Int, $orderId: Int = 0) {
useCompany(no: $cid) {
order_create(
values: [
{
orderDate: 20221025,
customerNo: 10000,
orderType: 1,
transactionType: 1
}
]
)
{
affectedRows
items {
orderNo @export(as: "orderId")
}
}
orderLine_create(
values: [
{
orderNo: $orderId,
productNo: "101",
quantity: 1
},
{
orderNo: $orderId,
productNo: "103",
quantity: 2
}
]
)
{
affectedRows
items {
lineNo
}
}
}
}
This returns the following errors:
"errors": [
{
"message": " Description: A record with the same primary key already exists.. Status: 3."
},
{
"message": " Description: A record with the same primary key already exists.. Status: 3."
}
]
It creates the order correctly and returns the orderNo, but fail to insert the lines. Any reason why this shouldn't work?
A fix for the @export directive is now in production.
Please try this mutation again and let us know if it is working well for you.
Interesting, we just discussed the same topic internally.
But: How would the Graph-query above work when we send in a list of orders? I can't see how we should connect the lines to the correct order-header even if the bug would be fixed?
And that leads to the next question: In the GraphQL we can send a list of orders but the error-return does not contain a reference to the right order as far as I know, right? So its maybe better or more correct to send the orders one by one?
Than the next question is how to handle the lines? Lets for example post 15 lines. The error return would could give a error-list with three errors. How can we relate the errors to the right lines? Or should we also post the lines one by one to get the right error for the right line?
Currently, the @export directive only supports exporting a single value, not a list or dictionary. Therefore, creating multiple orders at a time and the lines for those orders is not possible in one shot. You need to create one order and its lines in one request.
The other question that you're raising is, how would you know what operation produced an error message. For instance, if you add 10 lines but one of them fails, how would you know which order line failed. Currently, you can only figure that out by trying to match what you inserted and what is actually in the database. I understand that is not great. The question is how would you like to be informed about the error?
Let's take the following example:
orderLine_create(
values: [
{
orderNo: $orderId,
productNo: "101",
quantity: 1
},
{
orderNo: $orderId,
productNo: "103",
quantity: 2
}
]
)
Let's say the first line was correctly added, but the second failed for some reason. How should we tell what line failed? Should it be the index of object in the values array?
"errors": [
{
"message": " A record with the same primary key already exists. Status: 3. Values index: 1"
},
]
Would this "Value index: 1" help you?
I see your point. Indexing could be possible, but to handle this as a part of the return-text is maybe not such a good idea? Maybe the errormessage should be a bit more structured?
"error":"{"message":"A record with the same primary key already exists","Status":3,"Index":1}
I don't know what Status:3 means. But I see that it could be important to know if this is a warning or an error. Or if the row is created with error or not created.
It would probably be of more help to provide the actual path, such as ["orderLine_create", "values", 1, "lineNo"] to indicate that the lineNo field of the first order line in the list was at fault.
Also, it could be a good idea to move the Status to the extensions part of the error message. This makes little sense for you but it helps us understand what error was produced internally.
I can confirm there is a bug here and the @export directive does not work as expected. We are investigating a fix for this problem.
This indeed should work. I will investigate the problem.
Copyright Ā© 2022 Visma.com. All rights reserved.