Hi, so I have the following query set up (with data):
query test {
character(charID="a", enemy:"c") {
charID
enemy {
name
weapons {
type
power
}
}
}
}
Suppose my data takes this shape (when the query is run):
{
"data": {
"charEnemy": [
{
"charID": "a",
"enemy": [
{
"name": "q",
"weapons": [
{ "type": "metal", "power": "5" }
]
},
{
"name": "X",
"weapons": [
{ "type": "metal", "power": "6" }
]
},
{
"name": "c",
"weapons": [
{ "type": "metal", "power": "7" }
]
},
]
}
]
}
How should I go about querying a specific CharID with a specific enemy name? If I query charID=âaâ and enemy name âXâ for example, I only want to be able to access enemy[1]
, or rather, everything within the object with that specific name.
I currently have this but it returns the entire charEnemy object which has both conditions met. It doesnât ONLY return the charID, with that specific enemy object, but rather returns that charID with ALL the enemy objects associated with it: return charEnemy.find({charID: args.charID, enemy : {$elemMatch: {name : "X"}}});
How do I make it such that I get that entire charEnemy object with that charID and enemy name, but not the other enemy objects within the enemy array?