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.".
Hi all,
We recently announced that we have decided to deprecate the Atlas GraphQL API, and current users should’ve received an email explaining the details of the deprecation and end-of-life plan. Consequently, we will not be adding new features going forward and are updating the status for all related feedback accordingly.
Please read our announcement in the MongoDB Developer Center for more details and guidance on the migration process and timeline. Should you have any questions or need further assistance, please reach out to our support team via the MongoDB Support Portal.
We truly prioritize your satisfaction and success, and we thank you for your patience and the feedback you have provided us over the years.