Open vruffer opened 1 year ago
This would indeed be very helpful!
After some trial and error I went for this hack now. Probably does not cover all cases but seems to work fine for all our use cases:
function isArray(input) {
return typeof input === "object" && input !== null && typeof input.length === "number";
}
I have the same issue. In V1 of graphql we were able to work around this.
But in V2 the resolver lacks any way of detecting a json array.
Currently, there is no way to check whether a variable is an array in JS resolver functions.
Here are a couple of approaches as to how you would go about it in a browser or Nodejs environment:
Array.isArray
, which doesn't exist inAPPSYNC_JS
.arr.constructor === Array
. That doesn't work, becausearr.constructor
is undefined inAPPSYNC_JS
.This also doesn't work because
typeof
any function is'undefined'
inAPPSYNC_JS
. This is also (IMO) the worst solution.The functionality is present in
vtl
resolvers with$util.isList
, so it would be nice if it was available in the JS runtime as well.