I am using Hasura Enterprise Edition to write GraphQL query Mongo DB collection. Mongo DB collection has nested array as shown below. Query shall match PatientRef with given value and return the collection.
MongoDB collection named StaffAvailability has documents like below,
[
{
"_id": {
"$oid": "65f9f891f3f507d711e18f81"
},
"staffName": "John",
"email": "[email protected]",
"AvailabilityDate": "2023-01-18T00:00:00.000Z",
"Slots": [
{
"StartTime": "08:30:00",
"EndTime": "12:00:00",
"Appointments": [
{
"VisitStartDateTime": "08:30:00",
"VisitStartEndTime": "08:35:00",
"PatientRef": 1570204
},
{
"VisitStartDateTime": "10:30:00",
"VisitStartEndTime": "10:35:00",
"PatientRef": 1570254
}
]
},
{
"StartTime": "14:30:00",
"EndTime": "17:00:00",
"Appointments": [
{
"VisitStartDateTime": "14:30:00",
"VisitStartEndTime": "15:35:00",
"PatientRef": 4540204
},
{
"VisitStartDateTime": "16:30:00",
"VisitStartEndTime": "16:55:00",
"PatientRef": 4560254
}
]
}
]
},
{
"_id": {
"$oid": "65f9f891f3f507d711e18f83"
},
"staffName": "Emma",
"email": "[email protected]",
"AvailabilityDate": "2021-02-13T00:00:00.000Z",
"Slots": [
{
"StartTime": "08:30:00",
"EndTime": "12:00:00",
"Appointments": [
{
"VisitStartDateTime": "08:30:00",
"VisitStartEndTime": "08:35:00",
"PatientRef": 1670404
},
{
"VisitStartDateTime": "10:30:00",
"VisitStartEndTime": "10:35:00",
"PatientRef": 1670454
}
]
}
]
}
]
I want to write GraphQL query to get documents in this StaffAvailability collection where Slots->Appointments->PatientRef is lets say 1670454.
I tried following,
query MyQuery {
StaffAvailability{
Slots {
Appointments(where: {PatientRef: {_eq: 1570204}}) {
PatientRef
}
}
AvailabilityDate
staffName
}
}
I am expecting it to return following where 1570204 is matching with Slots->Appointments->PatientRef
{
"data": {
"StaffAvailability": [
{
"Slots": [
{
"Appointments": [
{
"PatientRef": 1570204
}
]
}
],
"AvailabilityDate": "2023-01-18T00:00:00.000Z",
"staffName": "John"
}
]
}
}
but it shows error as below,
{
"errors": [
{
"message": "'Appointments' has no argument named 'where'",
"extensions": {
"path": "$.selectionSet.StaffAvailability.selectionSet.Slots.selectionSet.Appointments",
"code": "validation-failed"
}
}
]
}