Support relationships for fields inside arrays of embedded objects in GraphQL
Currently, as explained in the App Services documentation, the "GraphQL API does not currently support relationships for fields inside arrays of embedded objects. You can use a custom resolver to manually look up and resolve embedded object array relationships."
There is a contradiction with this other documentation that explains it's possible: https://www.mongodb.com/docs/atlas/app-services/schemas/relationships/#embedded-object-within-a-list
But it's not possible.
For example, with this schema:
{
"title": "Person",
"properties": {
"_id": { "bsonType": "objectId" },
"pets": {
"bsonType":"array",
"items": {
"title":"PersonPet",
"bsonType": "object",
"properties": {
"favoriteToyBrand": { "bsonType": "objectId" }
}
}
}
// ...additional model properties
}
}
and this relationship:
{
"pets.[].favoriteToyBrand": {
"ref": "#/relationship/mongodb-atlas/example/ToyBrand",
"foreign_key": "_id",
"is_list": false
}
}
... the generated GraphQL schema will be:
type PersonPet {
favoriteToyBrand: String
// ...additional model properties
}
Please note that the type of the favoriteToyBrand
is String
instead of ToyBrand
.
Therefore, you cannot do something like favoriteToyBrand.name in your code.
I've contacted the Altas Pro support team. Here is their message: "We do have an internal ticket that is tracking this improvement, however we do not have an estimated timeframe when it will be implemented.".
