What's the difference between args and keys/argsFromKeys when merging types?
Is there any reason args would not work?
My understanding from the GraphQL Tools docs is it's simply single result queries vs arrays... getUserByID(id: String) vs getUsersByIDs(ids: [String]) but this alone doesn't explain my experience. After many hours I've found one works for me but not the other.
Works:
merge: {
Product: {
fieldName: 'Product',
selectionSet: '{id}',
key: (record) => {
return record.id;
},
argsFromKeys: (keys) => {
var arg = { filter: { id_in: keys }};
console.log(arg); // { where: { id_in: ["475e006f-b9cg-4f40-8712-271ceb46d14b"]}
//expected query: Product(where:{id_in: ["475e006f-b9cg-4f40-8712-271ceb46d14b"]})
return arg;
}
}
}
Does not work (resolves to undefined):
merge: {
Product: {
fieldName: 'Product',
selectionSet: '{id}',
args: (originalObject) => {
var arg = { id: originalObject.id };
console.log(arg); // { id: "475e006f-b9cg-4f40-8712-271ceb46d14b" }
// expected query: Product(id: "475e006f-b9cg-4f40-8712-271ceb46d14b")
return arg;
}
}
}
Does not work either - even using the same query as argsFromKeys:
merge: {
Product: {
fieldName: 'Product',
selectionSet: '{id}',
args: (originalObject) => {
var arg = { where: { id_in: [originalObject.id] };
console.log(arg); // { where: { id_in: ["475e006f-b9cg-4f40-8712-271ceb46d14b"]}
//expected query: Product(where:{id_in: ["475e006f-b9cg-4f40-8712-271ceb46d14b"]})
return arg;
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…