// wrap in async function
return (async () => {
// request graphql
const data = await input.__requestCkg({
svcRef: "/service/donald-hello-world",
query: "query { allFoos { id } }"
})
// post-process results
const output = data.allFoos
// return
return output
})()
return Object.keys(input).map(key => ({
id: key,
fieldName: key,
op: "==",
value: {
id: input[key],
ID: input[key],
}
}))
const parseKindName = svcRef => {
const regex = /\/kind\/(.*)/gm
const matches = regex.exec(svcRef)
if (!matches) return
console.log(matches)
return matches[1]
}
const svcRef = `/service/donald-maana-kind-q/kind/Aspect`;
const kindName = parseKindName(svcRef)
console.log(kindName)
const isObject = x => typeof x === "object" && !Array.isArray(x);
const flatten = obj => {
const out = Object.entries(obj).reduce((acc, [key, value]) => {
acc[key] = isObject(value) ? value["id"] : value;
return acc;
}, {});
return out;
};
const input = {
id: "id",
obj: {
id: "objId"
},
arr: ["arr"]
};
flatten(input);
const { v4:uuid } = require('uuid');
const id = input.id || uuid()
const safeInput = { ...input, id }
or
const hash = require('object-hash')
const obj = { ... }
const id = hash(obj)