to get a personalized navigation.
to get a personalized navigation.
Hey,
There's a logical issue when using _in. When the array is empty i expect it to be false, but instead it returns all rows.
So just for the sake of a demo I'm setting the sellerOrBuyer to 999 here, so that we know that it won't return any, but this might be due to some other filter in the real world.
When order in this example returns 0 rows I would expect sellerDetails to do the same, but instead it returns all rows.
query IssuesWith_InSample($cid: Int!, $sellers: [Int!] = []) {
useCompany(no: $cid) {
order(filter: {sellerOrBuyer: {_gt: 999}}, first: 3) {
items {
sellerOrBuyer @export(as: "sellers")
}
}
sellerDetails: associate(filter: {employeeNo: {_in: $sellers}}) {
items {
employeeNo
name
}
}
}
}
I understand that this will be a breaking change to fix, but I'd like to argue that we're not past the point of breaking changes with bnxt yet.
This problem is now fixed. https://docs.business.visma.net/docs/releasenotes
So I just realized that theres a very simple workaround for this. Setting the initial array with a value of [-1].
query IssuesWith_InSample($cid: Int!, $sellers: [Int!] = [-1]) {
useCompany(no: $cid) {
order(filter: {sellerOrBuyer: {_gt: 0}}, first: 3) {
items {
sellerOrBuyer @export(as: "sellers")
}
}
sellerDetails: associate(filter: {employeeNo: {_in: $sellers}}) {
items {
employeeNo
name
}
}
}
}
OK. We can make it without returning an error.
I get your point: in the context of @export, it's not an error, because the array was evaluated. But if you pass an empty array directly, would you consider it an error? Would you expect a message that your argument was incorrect? Or would you expect an empty result, and nothing about the cause?
Yes, we can do it so that an error is not returned, but I see pros and cons for it.
I see no reason to return an error if I send an empty array. An empty array is not an invalid argument to an input of array.
If I pass an empty error to for(const x of y) it just does 0 iterations, it doesn't throw an error.
We can't just return no data, we should also indicate the problem. So you get an error message back. It would look like this:
{
"errors": [
{
"message": "The array argument for the _in operator is empty.",
"path": [
"useCompany",
"associate"
],
"extensions": {
"details": "GraphQL.ExecutionError: The array argument for the _in operator is empty."
}
}
],
"data": {
"useCompany": {
"order": {
"totalCount": 0,
"items": null
},
"sellerDetails": null
}
}
}
Seems good?
But this would raise and log an error, when it's not strictly an error. I don't see any reason to return an error in this situation.
Can't you just return an empty array?
But still, this would solve my specific issue as I'm ignoring errors in this context.
You are correct. There should be nothing to return. Will look into it.
Copyright © 2022 Visma.com. All rights reserved.